/* ═══════════════════════════════════════════════════════════════
   LOTS OF LEGS THAILAND — Member & Admin Portal Stylesheet
   Design language: Airbnb (light, airy, rounded, coral accent).
   Class names preserved from the original portal so every page
   reskins without markup changes.
   ═══════════════════════════════════════════════════════════════ */

:root {
  /* Airbnb palette (mapped onto the original token names so the
     existing class rules keep working). */
  --gold:        #C8102E;   /* primary accent — Thai-flag red (logo) */
  --gold-light:  #A00C24;
  --gold-dim:    #F3C9CE;
  --bg:          #FFFFFF;
  --bg-card:     #FFFFFF;
  --bg-alt:      #F7F7F7;
  --bg-raised:   #FAFAFA;
  --border:      #DDDDDD;
  --border-sub:  #EBEBEB;
  --text:        #222222;
  --text-muted:  #717171;
  --text-dim:    #B0B0B0;
  --viper-blue:  #16284F;   /* secondary action — navy (logo) */

  --status-waiting:  #B47800;
  --status-process:  #2A7DB5;
  --status-booking:  #5b8bd9;
  --status-flight:   #008489;
  --status-loaded:   #2E7D32;
  --status-complete: #717171;

  --radius: 8px;
  --radius-lg: 14px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.08);
  --shadow-md: 0 6px 16px rgba(0,0,0,0.12);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg-alt);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
ul { list-style: none; }
h1, h2, h3, h4 { font-family: var(--font); font-weight: 800; letter-spacing: -0.01em; line-height: 1.2; }

/* ── Auth screens (login/signup) ───────────────────────────────── */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background:
    radial-gradient(900px 500px at 50% -10%, #fff5f7 0%, rgba(255,245,247,0) 60%),
    var(--bg-alt);
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-card);
  border: 1px solid var(--border-sub);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-md);
}

.auth-logo { text-align: center; margin-bottom: 1.5rem; }
.auth-logo img { height: 88px; margin: 0 auto; }
.auth-logo .auth-brand {
  font-family: var(--font);
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--text);
  margin-top: 0.7rem;
}

.auth-card h1 { text-align: center; font-size: 1.5rem; color: var(--text); margin-bottom: 0.4rem; }
.auth-sub { text-align: center; color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.8rem; }

.field { margin-bottom: 1rem; }
.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
  margin-bottom: 0.4rem;
}
.field input, .field textarea, .field select {
  width: 100%;
  padding: 0.75rem 0.9rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--text);
  box-shadow: 0 0 0 2px rgba(34,34,34,0.08);
  background: #fff;
}
.field textarea { resize: vertical; min-height: 70px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
@media (max-width: 480px) { .field-row { grid-template-columns: 1fr; } }

.btn-gold {
  width: 100%;
  padding: 0.85rem 1.2rem;
  background: var(--gold);
  color: #fff;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0;
  border-radius: var(--radius);
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
}
.btn-gold:hover:not(:disabled) { background: var(--gold-light); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-gold:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-blue {
  display: inline-block;
  padding: 0.7rem 1.4rem;
  background: var(--viper-blue);
  color: #fff;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius);
  transition: background 0.2s, transform 0.15s;
}
.btn-blue:hover { background: #006e72; transform: translateY(-1px); }

.btn-ghost {
  display: inline-block;
  padding: 0.6rem 1.1rem;
  border: 1px solid var(--text);
  color: var(--text);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.2s;
}
.btn-ghost:hover { background: var(--bg-alt); }

.auth-foot { margin-top: 1.4rem; text-align: center; font-size: 0.9rem; color: var(--text-muted); }
.auth-foot a { color: var(--gold); text-decoration: underline; text-underline-offset: 3px; font-weight: 600; }
.auth-foot a:hover { color: var(--gold-light); }

.auth-msg { margin-bottom: 1rem; padding: 0.75rem 0.9rem; font-size: 0.9rem; border-radius: var(--radius); display: none; }
.auth-msg.error   { display: block; background: #fbe9e4; border: 1px solid #f3c4b8; color: #9a2a10; }
.auth-msg.success { display: block; background: #e8f3e9; border: 1px solid #bfe0c4; color: #1f5a23; }
.auth-msg.info    { display: block; background: #fff0f3; border: 1px solid #ffd0da; color: #bd1e59; }

/* ── Portal shell (dashboard layout) ──────────────────────────── */
.portal-shell { display: grid; grid-template-columns: 256px 1fr; min-height: 100vh; }
@media (max-width: 860px) { .portal-shell { grid-template-columns: 1fr; } }

.portal-side {
  background: var(--bg-card);
  border-right: 1px solid var(--border-sub);
  padding: 1.5rem 1rem;
  position: sticky; top: 0; align-self: start; height: 100vh;
  overflow-y: auto; display: flex; flex-direction: column;
}

/* ── Mobile top-bar + off-canvas drawer ───────────────────────────
   Hidden on desktop; the sidebar is the persistent left column.
   On ≤860px the sidebar becomes a slide-in drawer toggled by the
   hamburger in the fixed top-bar. */
.portal-topbar { display: none; }
.portal-backdrop { display: none; }

@media (max-width: 860px) {
  .portal-topbar {
    display: flex; align-items: center; gap: 0.6rem;
    position: fixed; top: 0; left: 0; right: 0; z-index: 40;
    height: 56px; padding: 0 0.8rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-sub);
    box-shadow: var(--shadow-sm);
  }
  .portal-topbar .nav-toggle {
    width: 40px; height: 40px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: #fff; color: var(--text); font-size: 1.25rem; line-height: 1;
  }
  .portal-topbar .nav-toggle:active { background: var(--bg-alt); }
  .portal-topbar .topbar-brand {
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 0.95rem; font-weight: 800; letter-spacing: -0.01em; color: var(--text);
    min-width: 0;
  }
  .portal-topbar .topbar-brand img { height: 32px; width: 32px; border-radius: 8px; flex-shrink: 0; }
  .portal-topbar .topbar-brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* Sidebar becomes an off-canvas drawer */
  .portal-side {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: min(280px, 82vw); height: 100vh; height: 100dvh;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.28s var(--ease);
    box-shadow: var(--shadow-md);
  }
  .portal-shell.nav-open .portal-side { transform: translateX(0); }

  .portal-backdrop {
    display: block; position: fixed; inset: 0; z-index: 50;
    background: rgba(0,0,0,0.45);
    opacity: 0; pointer-events: none;
    transition: opacity 0.28s var(--ease);
  }
  .portal-shell.nav-open .portal-backdrop { opacity: 1; pointer-events: auto; }

  /* Prevent background scroll while the drawer is open
     (.portal-main top-padding for the fixed bar is set with the other
     .portal-main padding rules below, so source order keeps it.) */
  body.nav-locked { overflow: hidden; }
}

.portal-side .side-logo { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 1.6rem; padding: 0.4rem 0.5rem; }
.portal-side .side-logo img { height: 56px; width: 56px; border-radius: 12px; }
.portal-side .side-logo .side-brand {
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text);
  line-height: 1.15;
}

.side-nav { flex: 1; }
.side-nav a {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.7rem 0.9rem; border-radius: var(--radius);
  color: var(--text-muted); font-size: 0.92rem; font-weight: 500;
  margin-bottom: 0.2rem; transition: background 0.15s, color 0.15s;
}
.side-nav a:hover { background: var(--bg-alt); color: var(--text); }
.side-nav a.active {
  background: #fff0f3; color: var(--gold); font-weight: 700;
  border-left: 3px solid var(--gold);
  padding-left: calc(0.9rem - 3px);
}
.side-nav .nav-icon { width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }

.side-foot { border-top: 1px solid var(--border-sub); padding-top: 1rem; font-size: 0.82rem; color: var(--text-muted); }
.side-foot .who { padding: 0 0.5rem 0.6rem; }
.side-foot .who strong { color: var(--text); display: block; font-size: 0.9rem; }
.side-foot button.signout {
  width: 100%; padding: 0.6rem 0.9rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.85rem; font-weight: 600; color: var(--text-muted);
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.side-foot button.signout:hover { border-color: var(--text); color: var(--text); background: var(--bg-alt); }

.portal-main { padding: 2rem 2rem 4rem; max-width: 1200px; min-width: 0; }
/* On ≤860px a fixed 56px top-bar appears — pad the content clear of it.
   `min-width:0` is the load-bearing fix for "page too wide": .portal-main
   is a CSS-grid item, which defaults to min-width:auto and refuses to
   shrink below its content's intrinsic width — so a wide table (even one
   inside an overflow-x wrapper) blows the whole column past the viewport.
   Forcing min-width:0 lets the column shrink and inner wrappers scroll. */
@media (max-width: 860px) { .portal-main { padding: calc(56px + 1.5rem) 1.5rem 3rem; } }
@media (max-width: 600px) { .portal-main { padding: calc(56px + 1.25rem) 1rem 3rem; } }

.page-head { margin-bottom: 2rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border-sub); }
.page-head h1 { font-size: 1.7rem; color: var(--text); letter-spacing: -0.02em; margin-bottom: 0.4rem; }
.page-head p { color: var(--text-muted); font-size: 0.95rem; }

/* ── Tables / lists ───────────────────────────────────────────── */
.data-table {
  width: 100%; border-collapse: collapse;
  background: var(--bg-card); border: 1px solid var(--border-sub);
  border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm);
}
.data-table th, .data-table td { padding: 0.9rem 1rem; text-align: left; border-bottom: 1px solid var(--border-sub); font-size: 0.92rem; }
.data-table th {
  background: var(--bg-alt); font-family: var(--font); font-size: 0.78rem;
  font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase; color: var(--text-muted);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-alt); }

.status-pill { display: inline-block; padding: 0.28rem 0.7rem; border-radius: 99px; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em; }
.status-WAITING_FOR_DEPOSIT { background: #fbf2d8; color: var(--status-waiting);  border: 1px solid #ecd9a3; }
.status-ORDER_PROCESSING    { background: #e6f1f8; color: var(--status-process);  border: 1px solid #c2dded; }
.status-BOOKING_FLIGHT      { background: #e9eefb; color: var(--status-booking);  border: 1px solid #c7d4f3; }
.status-FLIGHT_DATE         { background: #e2f1f1; color: var(--status-flight);   border: 1px solid #b9dedd; }
.status-LOADED              { background: #e8f3e9; color: var(--status-loaded);   border: 1px solid #bfe0c4; }
.status-COMPLETED           { background: #f0f0f0; color: var(--status-complete); border: 1px solid #dcdcdc; }

.empty-state {
  background: var(--bg-card); border: 1px dashed var(--border);
  border-radius: var(--radius-lg); padding: 3rem 2rem; text-align: center; color: var(--text-muted);
}
.empty-state h3 { color: var(--text); font-size: 1.15rem; margin-bottom: 0.6rem; }
.empty-state p { font-size: 0.92rem; margin-bottom: 1.4rem; }

/* ── Modal close button ─────────────────────────────────────────── */
.modal-close,
.popup-close {
  position: absolute; top: 0.7rem; right: 0.7rem;
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--border-sub); background: #fff; color: var(--text);
  font-size: 1.2rem; line-height: 1;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: background 0.2s, transform 0.15s; box-shadow: var(--shadow-sm); z-index: 5;
}
.modal-close:hover,
.popup-close:hover { background: var(--bg-alt); transform: scale(1.06); }

/* ── iOS-safe modal scrolling ──────────────────────────────────── */
dialog { overscroll-behavior: contain; }
dialog[open] { -webkit-overflow-scrolling: touch; }

/* Generic dialog surface (in case pages use <dialog>) */
dialog {
  border: 1px solid var(--border-sub);
  border-radius: var(--radius-lg);
  background: #fff;
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  padding: 1.75rem;
}
dialog::backdrop { background: rgba(0,0,0,0.5); }

/* ── Shared responsive helpers (phones + tablets) ─────────────────
   These cascade across every logged-in page because the markup
   reuses the same class names. */

/* Wide tables stay usable: their scroll wrappers get momentum
   scrolling on touch. Tables keep their natural width and the
   wrapper scrolls horizontally rather than crushing columns.
   (Pages that re-style .data-table into cards — e.g. the member
   order sheet — override this within their own media queries.) */
div[style*="overflow-x"] { -webkit-overflow-scrolling: touch; }

@media (max-width: 860px) {
  .page-head { margin-bottom: 1.4rem; }
  .page-head h1 { font-size: 1.4rem; }

  /* Two-column label/value grids collapse to stacked rows */
  .label-pair { grid-template-columns: 1fr; gap: 0.1rem 0; }
  .label-pair > span:nth-child(odd) {
    font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em;
    margin-top: 0.7rem;
  }
  .label-pair > span:first-child { margin-top: 0; }

  /* Totals / summary grids go full-width instead of pinned right */
  .totals-grid { max-width: none; margin-left: 0; }
  .payment-progress { max-width: none; margin-left: 0; }

  /* Three-up form rows are too tight on tablets — go two-up */
  .row3 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  /* Cards lose heavy padding to claw back horizontal room */
  .order-card { padding: 1.1rem; }

  /* Button rows wrap and stretch so taps are comfortable */
  .order-card > div[style*="justify-content:flex-end"],
  div[style*="justify-content:flex-end"][style*="flex-wrap"] { gap: 0.5rem; }

  /* Inputs hit the 16px floor so iOS doesn't zoom on focus */
  .field input, .field textarea, .field select,
  .num-input, .qty-input { font-size: 16px; }

  /* Generic two-column form grids collapse to a single column */
  .pf-grid, .row2, .row3 { grid-template-columns: 1fr; }

  /* iOS zooms any focused control whose font is < 16px. Floor every
     inline-styled / unclassed control on small screens. */
  input, select, textarea { font-size: 16px; }
  /* Page <style> blocks load after this file and set `font: inherit` on
     their input classes (which resets font-size), so a plain element rule
     loses the cascade. !important guarantees the 16px zoom-floor wins
     everywhere without a per-page rule on each sheet. */
  .num-input, .inv-input, .text-input, .qty-input, .prot-select,
  .name-input, .sci-input, .sku-input, .cat-label-input { font-size: 16px !important; }
}

/* ── Mobile portrait hardening (≤480px) ───────────────────────────
   Removes the last sources of horizontal scroll and small tap targets
   surfaced in the portrait UX audit. */
@media (max-width: 480px) {
  /* Comfortable ≥40px tap targets */
  .btn-ghost { padding: 0.7rem 1.1rem; }
  .modal-close, .popup-close { width: 40px; height: 40px; }

  /* Member account: permit-row actions stack full-width instead of
     cramming two buttons into one nowrap cell. */
  .permit-download, .permit-delete {
    display: block; width: 100%; margin: 0 0 0.4rem 0 !important;
  }

  /* Order-item tables: tighter cells so they fit without side-scroll */
  .order-card .data-table th,
  .order-card .data-table td { padding: 0.6rem 0.5rem; font-size: 0.85rem; }
}
