/* ---- Login screen ---- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--soil-900);
  border: 1px solid var(--soil-700);
  border-radius: var(--radius-md);
  padding: 32px 28px;
  box-shadow: var(--shadow-card);
}
.auth-card .mark {
  display: inline-flex;
  margin-bottom: 14px;
}
.auth-mark-img { height: 40px; width: auto; display: block; }
.auth-card h2 {
  font-size: 1.4rem;
  margin-bottom: 4px;
}
.auth-card .sub {
  font-size: 0.85rem;
  margin-bottom: 22px;
}
.auth-card .field {
  margin-bottom: 14px;
}
.auth-card .row {
  display: flex;
  gap: 10px;
}
.auth-card .row > .field {
  flex: 1;
}
.auth-card button[type="submit"] {
  width: 100%;
  margin-top: 6px;
  justify-content: center;
}

@media (max-width: 400px) {
  .auth-shell { padding: 16px; }
  .auth-card { padding: 24px 20px; }
  /* Country + state selects at ~130px each on a 400px-wide card is
     workable but tight; stacking removes the squeeze on genuinely small
     phones (iPhone SE and similar) without affecting anything wider. */
  .auth-card .row { flex-direction: column; gap: 14px; }
}
.auth-toggle {
  text-align: center;
  margin-top: 18px;
  font-size: 0.85rem;
  color: var(--parchment-500);
}
.auth-toggle button {
  background: none;
  border: none;
  color: var(--brand-300);
  padding: 0;
  font-weight: 600;
  text-decoration: underline;
}

/* ---- App shell ---- */
.app-shell {
  display: grid;
  grid-template-columns: 230px 1fr;
  min-height: 100vh;
  /* Without this, grid's default align-items:stretch makes .sidebar as
     tall as .content, so .sidebar-footer's margin-top:auto lands it at a
     different height on every page (or off-screen below a long table)
     instead of anchored to the viewport. */
  align-items: start;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--soil-700);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  background: var(--soil-900);
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 20px;
  border-bottom: 1px solid var(--soil-700);
  margin-bottom: 14px;
}
.sidebar .brand .mark {
  display: inline-flex;
}
.brand-mark-img { height: 28px; width: auto; display: block; }
.sidebar .brand span.name {
  font-family: var(--font-display);
  font-size: 0.95rem;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--parchment-300);
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
}
.nav-item .icon { color: var(--parchment-500); }
.nav-item:hover {
  background: var(--soil-800);
  color: var(--parchment-050);
}
.nav-item.active {
  background: var(--soil-800);
  color: var(--brand-300);
  box-shadow: inset 2px 0 0 var(--brand-500);
}
.nav-item.active .icon { color: var(--brand-300); }
.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--soil-700);
}
.sidebar-external-link {
  display: block;
  text-align: center;
  margin-top: 10px;
  font-size: 0.78rem;
  color: var(--parchment-500);
  text-decoration: none;
}
.sidebar-external-link:hover { color: var(--brand-300); }
.who-am-i {
  padding: 8px 10px 12px;
  font-size: 0.8rem;
  color: var(--parchment-500);
}
.who-am-i strong {
  display: block;
  color: var(--parchment-100);
  font-weight: 600;
  font-size: 0.88rem;
}
.who-am-i .loc-line { display: flex; align-items: center; gap: 5px; margin-top: 6px; }

/* Content area intentionally uses almost the full remaining width. This is
   an operational dashboard, not a reading-width document, so wide tables
   and multi-column filter bars get the room they need. */
.content {
  padding: 28px clamp(16px, 2.4vw, 48px) 60px;
  max-width: 1680px;
  /* Grid items default to min-width:auto, meaning a grid item will never
     shrink below its content's intrinsic (unwrapped) width — so a wide
     table inside .content was forcing .app-shell's entire "1fr" column
     wider than the actual viewport instead of respecting it, which is
     what pushed the whole page sideways (confirmed directly: the grid
     column was computing to ~1118px on a 390px-wide screen). This is what
     actually lets .table-wrap's own overflow-x:auto do its job — contain
     the table's overflow *within itself* — instead of the grid track
     growing to avoid ever needing to. */
  min-width: 0;
}
.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}
.content-header h2 {
  font-size: 1.35rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.content-header p {
  margin: 4px 0 0;
  font-size: 0.88rem;
}

/* ---- Cards / panels ---- */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 6px;
}
.field { margin-bottom: 0; }
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

/* ---- Filter bar (admin listings/enquiries) ---- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px 16px;
  background: var(--soil-900);
  border: 1px solid var(--soil-700);
  border-radius: var(--radius-md);
}
.filter-bar .field { flex: 1 1 200px; min-width: 160px; margin-bottom: 0; }
.filter-bar label { display: flex; align-items: center; gap: 5px; }
.filter-bar .filter-clear { flex: 0 0 auto; }

/* ---- Table ---- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--soil-700);
  border-radius: var(--radius-md);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
thead th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--parchment-500);
  padding: 10px 14px;
  background: var(--soil-800);
  border-bottom: 1px solid var(--soil-700);
  white-space: nowrap;
}
tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--soil-800);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(226, 160, 61, 0.04); }
/* The buttons live in an inner .actions-row div, not directly on the <td>.
   Making the <td> itself display:flex (an earlier version of this rule)
   pulls it out of table-cell layout entirely, so it stops stretching to
   match the row's height like its sibling cells do — its border-bottom
   then sits wherever the buttons end, not at the row's actual bottom edge,
   visibly misaligned against taller rows (e.g. a listing with a long
   wrapped description). Keeping the <td> a plain table-cell means it
   stretches correctly, and the existing tbody td { vertical-align: middle }
   centers the inner flex row within it, same visual result as before. */
.actions-row {
  display: flex;
  align-items: center;
  gap: 8px;
  /* Deliberately NOT flex-wrap:wrap. A flex container with wrap enabled
     can size itself down to its widest single *item* rather than the sum
     of all items — a well-known bad interaction between flexbox and the
     table auto-layout algorithm — so this column was collapsing to a
     narrow width and wrapping its 2-3 buttons onto separate lines. That's
     exactly the exploded-row-height bug from the mobile screenshot.
     .table-wrap's own overflow-x:auto already handles any overflow at the
     whole-table level, so nothing needs to wrap inside one cell as well. */
  flex-wrap: nowrap;
  white-space: nowrap;
}
td .muted { color: var(--parchment-500); font-size: 0.8rem; }
.cell-strong { color: var(--parchment-050); font-weight: 600; }
.cell-with-icon { display: flex; align-items: center; gap: 7px; }

.loading-row td {
  text-align: center;
  color: var(--parchment-500);
  padding: 28px;
  animation: loading-pulse 1.1s ease-in-out infinite;
}
@keyframes loading-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}
.empty-row td {
  text-align: center;
  color: var(--parchment-500);
  padding: 28px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

/* ---- Mobile top bar + bottom tab bar ----
   Hidden by default (desktop uses .sidebar instead); shown only under the
   max-width:760px query below. Built as their own fixed elements rather
   than a squeezed version of .sidebar — seem "Mobile-only" comment in
   dashboard.js's renderApp() for why. */
.mobile-topbar, .mobile-tabbar { display: none; }

.mobile-topbar {
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--soil-700);
  background: var(--soil-900);
  position: sticky;
  top: 0;
  z-index: 30;
  min-width: 0; /* same grid-item-shrinking fix as .content, defensively */
}
.mobile-topbar .mark { display: inline-flex; }
.mobile-topbar-name {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--parchment-050);
  flex: 1;
}
#mobile-logout-btn { padding: 8px; }

.mobile-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: var(--soil-900);
  border-top: 1px solid var(--soil-700);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.3);
}
.mobile-tab {
  flex: 1;
  flex-direction: column;
  gap: 3px;
  width: auto; /* override .nav-item's width:100%, which assumed a vertical list, not equal-width columns in a row */
  padding: 8px 4px 10px;
  border-radius: 0;
  font-size: 0.66rem;
  text-align: center;
}
.mobile-tab .icon { width: 1.3em; height: 1.3em; }
.mobile-tab span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.mobile-tab.active { background: none; box-shadow: inset 0 2px 0 var(--brand-500); }

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .mobile-topbar, .mobile-tabbar { display: flex; }
  /* Clear the fixed bottom tab bar (its own height plus the iPhone
     home-indicator safe area) so the last row of a table or the submit
     button on a form is never hidden behind it. */
  .content { padding-bottom: calc(78px + env(safe-area-inset-bottom)); }

  /* ---- Tables become stacked cards instead of scrolling sideways ----
     Every <td> in every table already carries a data-label="Column Name"
     attribute (added specifically for this) — that's what lets the exact
     same markup drive both the desktop table AND this mobile card layout;
     nothing is duplicated or rendered differently by JS, only re-styled.
     Each <tr> becomes one bordered card; each <td> becomes one labeled
     line inside it, with the column header re-appearing as a small label
     via ::before (CSS attr()) since <thead> itself is hidden. This
     replaces horizontal scrolling entirely — every field is visible
     without scrolling in either direction. */
  .table-wrap { border: none; overflow-x: visible; }
  table { display: block; width: 100%; }
  thead { display: none; }
  tbody { display: block; }
  tbody tr {
    display: block;
    margin-bottom: 12px;
    padding: 4px 14px;
    background: var(--soil-900);
    border: 1px solid var(--soil-700);
    border-radius: var(--radius-md);
  }
  tbody tr:hover { background: var(--soil-900); }
  tbody tr:last-child { margin-bottom: 0; }
  tbody td {
    display: block;
    padding: 10px 0;
    border-bottom: 1px solid var(--soil-800);
  }
  tbody tr td:last-child { border-bottom: none; }
  td::before {
    content: attr(data-label);
    display: block;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--parchment-500);
    margin-bottom: 5px;
  }
  /* Status messages ("Loading…", "No listings match this filter.") are a
     single unlabeled <td colspan>, not a real data row — no column label
     to show for them. */
  .loading-row td, .empty-row td { text-align: left; }
  .loading-row td::before, .empty-row td::before { content: none; }
  /* Actions already read fine as a row of buttons on their own; a
     "ACTIONS" label above them is redundant, and wrapping (rather than
     the desktop's deliberate nowrap-and-scroll) is exactly right now that
     there's no horizontal scroll to fall back on. */
  td.actions::before { content: none; }
  td.actions { padding-top: 12px; }
  .actions-row { flex-wrap: wrap; white-space: normal; }
}
