/* ==========================================================================
   Shared base styles — minimal dashboard
   ขึ้นทับด้วย CSS เฉพาะของแต่ละแอปได้
   ========================================================================== */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--navy); text-decoration: none; }
a:hover { color: var(--gold-2); }

button, input, select, textarea {
  font: inherit;
  font-family: inherit;
}

img { max-width: 100%; display: block; }

h1, h2, h3, h4 {
  margin: 0 0 var(--space-3);
  color: var(--navy);
  letter-spacing: 0;
  line-height: 1.3;
}
h1 { font-size: var(--fs-2xl); font-weight: 800; }
h2 { font-size: var(--fs-xl); font-weight: 800; }
h3 { font-size: var(--fs-lg); font-weight: 700; }

p { margin: 0 0 var(--space-3); }

.muted    { color: var(--muted); }
.hidden   { display: none !important; }
em        { color: var(--danger); font-style: normal; }

/* ----- Container / grid ----- */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-5);
}

/* ----- Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: 0;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  min-height: 44px;
  font-weight: 700;
  cursor: pointer;
  transition: filter .15s ease, transform .05s ease, background-color .15s ease;
  background: var(--navy);
  color: var(--white);
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { cursor: wait; opacity: .58; }
.btn-primary  { background: var(--gold); color: var(--navy); }
.btn-secondary{ background: var(--navy); color: var(--white); }
.btn-ghost    { background: transparent; color: var(--navy); border: 1px solid var(--line); }
.btn-success  { background: var(--success); color: var(--white); }
.btn-danger   { background: var(--danger); color: var(--white); }
.btn-block    { width: 100%; }
.btn-sm       { padding: 8px 12px; min-height: 36px; font-size: .9rem; }

/* ----- Forms ----- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--space-4);
}
.field > span { font-weight: 700; color: var(--navy); }
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(214, 162, 30, .18);
}

/* ----- Card ----- */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}

/* ----- Topbar (สำหรับแอปด้านใน) ----- */
.app-topbar {
  background: var(--navy);
  color: var(--white);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.app-topbar a { color: var(--white); }
.app-topbar .badge {
  background: var(--gold);
  color: var(--navy);
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-weight: 800;
  font-size: var(--fs-xs);
}

/* ----- Footer ----- */
body.has-fixed-footer {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app-footer {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  text-align: center;
  padding: var(--space-5) var(--space-4);
  font-size: var(--fs-sm);
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: var(--white);
  margin-top: auto;
}

.fixed-screen-footer,
.app-footer.fixed-screen-footer,
.footer.fixed-screen-footer {
  z-index: 120;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(15, 23, 42, 0.06);
  background: transparent;
  color: rgba(107, 114, 128, 0.76);
  font-size: 0.86rem;
  font-weight: 400;
  margin-top: auto;
  flex: 0 0 auto;
}

.portal-body .fixed-screen-footer,
.reset-body .fixed-screen-footer {
  border-top-color: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.58);
}

@media (max-width: 640px) {
  body.has-fixed-footer {
    min-height: 100dvh;
  }

  .fixed-screen-footer,
  .app-footer.fixed-screen-footer,
  .footer.fixed-screen-footer {
    min-height: 60px;
    padding-right: 12px;
    padding-left: 12px;
    font-size: 0.76rem;
    line-height: 1.35;
  }
}

/* ----- Status pill ----- */
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 700;
}

/* ----- Scrollbars (subtle) ----- */
*::-webkit-scrollbar { height: 10px; width: 10px; }
*::-webkit-scrollbar-thumb { background: var(--line); border-radius: var(--radius-pill); }
*::-webkit-scrollbar-thumb:hover { background: #cfd6df; }

/* ----- Utility ----- */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

@media (max-width: 700px) {
  .container { padding: var(--space-4); }
  h1 { font-size: 1.4rem; }
  h2 { font-size: 1.15rem; }
}
