/* ==========================================================================
   EstateOS — Application Design System (app.css)
   Premium light SaaS theme. White-label ready: brand tokens below are
   FALLBACKS. At runtime the layout injects Branding::cssVars() in a
   <style> tag AFTER this file, overriding any --brand-* token.
   No dark mode. Mobile-first.
   ========================================================================== */

:root {
  /* Brand (overridden at runtime by Branding::cssVars()) */
  --brand-primary: #0A1628;          /* deep navy */
  --brand-primary-600: #13263f;
  --brand-primary-700: #0c1a30;
  --brand-secondary: #B8922A;        /* gold */
  --brand-secondary-600: #a37f21;
  --brand-accent: #2E7CF6;

  /* Surfaces & text */
  --bg: #F4F6FA;
  --surface: #FFFFFF;
  --surface-2: #FAFBFD;
  --border: #E4E9F2;
  --border-strong: #CFD8E5;
  --text: #101C2E;
  --muted: #5D6D84;
  --faint: #8A97AB;

  /* Status */
  --green: #15803D;  --green-bg: #E7F6EC;
  --amber: #B45309;  --amber-bg: #FDF1DE;
  --red: #B91C1C;    --red-bg: #FBEAEA;
  --blue: #1D4ED8;   --blue-bg: #E8F0FE;
  --gray: #475569;   --gray-bg: #EEF2F7;

  /* Shape & depth */
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 20px -6px rgba(16, 24, 40, .10);
  --shadow-lg: 0 12px 40px -8px rgba(10, 22, 40, .22);

  /* Layout */
  --sidebar-w: 250px;
  --topbar-h: 64px;
  --bottomnav-h: 64px;

  /* Type */
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75em; }
.muted { color: var(--muted); }
.small { font-size: .83rem; }
.nowrap { white-space: nowrap; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: linear-gradient(180deg, var(--brand-primary) 0%, var(--brand-primary-700) 100%);
  color: #E8EDF5;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  transition: transform .32s cubic-bezier(.2, .7, .25, 1);
  will-change: transform;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid rgba(255,255,255,.10);
}
.sidebar-close {
  display: none; margin-left: auto;
  width: 36px; height: 36px; border: none; border-radius: 10px;
  background: rgba(255,255,255,.08); color: #fff;
  font-size: 1.4rem; line-height: 1; cursor: pointer;
}
.sidebar-close:active { background: rgba(255,255,255,.16); }
@media (max-width: 900px) {
  .sidebar-close { display: inline-flex; align-items: center; justify-content: center; }
}
.sidebar-brand img { height: 34px; width: 34px; object-fit: contain; border-radius: 8px; background: #fff; }
.sidebar-brand .name { font-weight: 700; font-size: 1.02rem; color: #fff; line-height: 1.2; }
.sidebar-brand .sub { font-size: .72rem; color: rgba(255,255,255,.55); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 10px 20px; }
.nav-section {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .09em;
  color: rgba(255,255,255,.45); padding: 14px 10px 6px; font-weight: 700;
}
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: rgba(255,255,255,.82); font-size: .93rem; font-weight: 500;
  min-height: 44px;
}
.nav-link:hover { background: rgba(255,255,255,.08); text-decoration: none; color: #fff; }
.nav-link.active {
  background: rgba(255,255,255,.12); color: #fff; font-weight: 650;
  box-shadow: inset 3px 0 0 var(--brand-secondary);
}
.nav-link .ico { width: 20px; text-align: center; font-size: 1.05rem; flex: 0 0 20px; }
.sidebar-foot {
  padding: 12px 16px; font-size: .72rem; color: rgba(255,255,255,.45);
  border-top: 1px solid rgba(255,255,255,.10);
}
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; z-index: 55;
  background: rgba(10, 22, 40, .5);
}

/* Main column */
.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }

/* Topbar */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  position: sticky; top: 0; z-index: 50;
}
.hamburger {
  display: none; border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--radius-sm); width: 44px; height: 44px;
  font-size: 1.25rem; cursor: pointer; color: var(--text);
}
.topbar-search { flex: 1; max-width: 420px; }
.topbar-search input {
  width: 100%; height: 42px; border: 1px solid var(--border); border-radius: 999px;
  padding: 0 16px 0 40px; font-size: .92rem; background: var(--surface-2);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238A97AB' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M21 21l-4.3-4.3'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 14px center;
}
.topbar-search input:focus { outline: 2px solid var(--brand-secondary); border-color: var(--brand-secondary); background-color: #fff; }
.topbar-spacer { flex: 1; }
.icon-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 1.15rem; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); text-decoration: none; }
.icon-btn .dot {
  position: absolute; top: 2px; right: 2px; min-width: 20px; height: 20px;
  padding: 0 5px; border-radius: 999px; background: var(--red); color: #fff;
  font-size: .68rem; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
/* user menu (pure <details> dropdown — no JS needed) */
.user-menu { position: relative; }
.user-menu summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 6px 6px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); min-height: 44px;
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: var(--surface-2); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: 0 0 34px;
  background: var(--brand-primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem;
}
.user-menu .who { line-height: 1.2; }
.user-menu .who .n { font-weight: 650; font-size: .88rem; display: block; }
.user-menu .who .r { font-size: .72rem; color: var(--muted); display: block; }
.user-menu .drop {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 210px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 6px; z-index: 70;
}
.user-menu .drop a {
  display: block; padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text); font-size: .92rem; min-height: 44px;
}
.user-menu .drop a:hover { background: var(--surface-2); text-decoration: none; }

/* Content */
.content { padding: 24px; width: 100%; max-width: 1280px; margin: 0 auto; }
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 18px; flex-wrap: wrap;
}
.page-head h1 { margin: 0; }
.page-head .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.footer {
  margin-top: auto; padding: 18px 24px; text-align: center;
  color: var(--faint); font-size: .78rem; border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font-size: .93rem; font-weight: 650; font-family: var(--font);
  cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--brand-primary); color: #fff; }
.btn-primary:hover { background: var(--brand-primary-600); color: #fff; }
.btn-accent { background: var(--brand-secondary); color: #1a1405; }
.btn-accent:hover { background: var(--brand-secondary-600); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #991b1b; color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-outline { background: #fff; border-color: var(--brand-primary); color: var(--brand-primary); }
.btn-outline:hover { background: var(--brand-primary); color: #fff; }
.btn-sm { min-height: 38px; padding: 7px 12px; font-size: .85rem; }
.btn-block { width: 100%; }
.btn[disabled], .btn.disabled { opacity: .55; cursor: not-allowed; }
.link-danger { color: var(--red); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  margin-bottom: 18px; overflow: hidden;
}
.card-pad { padding: 20px; }
.card-head {
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface-2);
}
.card-head h3 { margin: 0; font-size: 1rem; }
.card-body { padding: 20px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }

/* Stat cards */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.stat::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--brand-secondary);
}
.stat .label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 650; }
.stat .value { font-size: 1.65rem; font-weight: 750; margin: 4px 0 2px; letter-spacing: -0.02em; }
.stat .hint { font-size: .8rem; color: var(--muted); }
.stat.stat-navy { background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-600)); color: #fff; border: none; }
.stat.stat-navy .label, .stat.stat-navy .hint { color: rgba(255,255,255,.7); }
.stat.stat-gold::before { background: var(--brand-secondary); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; min-width: 640px; }
.table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2); text-align: left;
  padding: 12px 14px; font-size: .76rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 700; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody td { padding: 13px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #F8FAFD; }
.table .row-actions { white-space: nowrap; text-align: right; }
.table tfoot td { padding: 12px 14px; font-weight: 700; background: var(--surface-2); }
.table a.sort { color: var(--muted); }
.table a.sort:hover { color: var(--text); text-decoration: none; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 700; letter-spacing: .02em; white-space: nowrap;
}
.b-green { background: var(--green-bg); color: var(--green); }
.b-amber { background: var(--amber-bg); color: var(--amber); }
.b-red { background: var(--red-bg); color: var(--red); }
.b-blue { background: var(--blue-bg); color: var(--blue); }
.b-gray { background: var(--gray-bg); color: var(--gray); }
.b-navy { background: var(--brand-primary); color: #fff; }
.b-gold { background: #FBF3DC; color: #8a6d1a; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 650; font-size: .88rem; margin-bottom: 6px; }
.form-group .req { color: var(--red); }
.form-control, input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="datetime-local"], input[type="tel"],
input[type="url"], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: .95rem; font-family: var(--font); color: var(--text); background: #fff;
}
textarea { min-height: 110px; resize: vertical; }
.form-control:focus, input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand-secondary); border-color: var(--brand-secondary);
}
.form-hint { font-size: .8rem; color: var(--muted); margin-top: 5px; }
.form-error { font-size: .83rem; color: var(--red); margin-top: 5px; font-weight: 600; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
fieldset.form-fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 0 0 18px; }
fieldset.form-fieldset legend { padding: 0 8px; font-weight: 700; font-size: .9rem; }
.checkbox-row { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.checkbox-row input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--brand-primary); }
.inline-form { display: inline; }

/* Filter bar */
.filters {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 16px;
}
.filters .form-group { margin-bottom: 0; min-width: 150px; flex: 1 1 150px; }
.filters .btn { min-height: 44px; }

/* ---------- Alerts ---------- */
.alert {
  padding: 13px 16px; border-radius: var(--radius-sm); margin-bottom: 16px;
  font-size: .92rem; border: 1px solid transparent;
  display: flex; gap: 10px; align-items: flex-start;
}
.alert-success { background: var(--green-bg); border-color: #BFE6CB; color: #14532D; }
.alert-error, .alert-danger { background: var(--red-bg); border-color: #F3C2C2; color: #7F1D1D; }
.alert-warning { background: var(--amber-bg); border-color: #F0D9A8; color: #78350F; }
.alert-info { background: var(--blue-bg); border-color: #BFD4F8; color: #1E3A8A; }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: 6px; align-items: center; justify-content: center; margin: 20px 0 6px; flex-wrap: wrap; }
.pagination a, .pagination span {
  min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: .9rem;
}
.pagination a:hover { background: var(--surface-2); text-decoration: none; }
.pagination .current { background: var(--brand-primary); color: #fff; border-color: var(--brand-primary); }
.pagination .meta { border: none; background: none; color: var(--muted); font-weight: 500; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs a {
  padding: 12px 16px; font-weight: 650; font-size: .92rem; color: var(--muted);
  border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; min-height: 44px;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--brand-primary); border-bottom-color: var(--brand-secondary); }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 9px; top: 8px; bottom: 8px; width: 2px; background: var(--border); }
.timeline li { position: relative; padding: 0 0 18px 34px; }
.timeline li::before {
  content: ""; position: absolute; left: 3px; top: 5px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--surface); border: 3px solid var(--brand-secondary);
}
.timeline .t-time { font-size: .76rem; color: var(--faint); }
.timeline .t-title { font-weight: 650; }
.timeline .t-detail { font-size: .88rem; color: var(--muted); }

/* ---------- Key/value detail grid ---------- */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 24px; }
.kv .k { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.kv .v { font-size: .98rem; font-weight: 600; margin-top: 2px; }

/* ---------- Modal (lite) ---------- */
.modal-backdrop {
  display: none; position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 22, 40, .55); padding: 20px;
  align-items: flex-start; justify-content: center; overflow-y: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px; margin: 8vh auto; overflow: hidden;
}
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background: var(--surface-2); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--muted); width: 44px; height: 44px; }

/* ---------- Login / auth pages ---------- */
.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-primary-600) 60%, #1d3350 100%);
}
.auth-card {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 420px; padding: 36px 32px;
}
.auth-card .logo { text-align: center; margin-bottom: 18px; }
.auth-card .logo img { height: 56px; width: 56px; object-fit: contain; border-radius: 12px; }
.auth-card h1 { text-align: center; font-size: 1.35rem; margin-bottom: 4px; }
.auth-card .sub { text-align: center; color: var(--muted); font-size: .9rem; margin-bottom: 22px; }
.auth-card .btn-block { margin-top: 6px; }
.auth-links { text-align: center; margin-top: 16px; font-size: .88rem; }
.auth-foot { text-align: center; margin-top: 22px; font-size: .75rem; color: var(--faint); }

/* ---------- Empty states ---------- */
.empty {
  text-align: center; padding: 44px 20px; color: var(--muted);
  border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface);
}
.empty .big { font-size: 2.2rem; margin-bottom: 8px; }

/* ---------- Bottom nav (mobile) ---------- */
.bottomnav {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  height: var(--bottomnav-h); background: var(--surface);
  border-top: 1px solid var(--border); box-shadow: 0 -2px 12px rgba(16,24,40,.08);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); font-size: .68rem; font-weight: 600; min-height: var(--bottomnav-h);
}
.bottomnav a .ico { font-size: 1.3rem; }
.bottomnav a.active { color: var(--brand-primary); }
.bottomnav a:hover { text-decoration: none; }

/* ---------- Toast-ish dismissible alerts ---------- */
.alert[data-autodismiss] { transition: opacity .4s; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .content { padding: 18px 16px; }
  .form-row-3 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-105%); box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .sidebar-backdrop { display: block; }
  .main { margin-left: 0; }
  .hamburger { display: inline-flex; align-items: center; justify-content: center; }
  .topbar-search { display: none; } /* search lives on list pages on mobile */
  .user-menu .who { display: none; }
}

@media (max-width: 768px) {
  body { padding-bottom: var(--bottomnav-h); }
  .bottomnav { display: flex; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 1.3rem; }
  .page-head .actions .btn { flex: 1 1 auto; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat .value { font-size: 1.35rem; }

  /* Tables -> labelled card rows. Pages must add data-label="..." on each <td>. */
  .table.responsive-cards { min-width: 0; }
  .table.responsive-cards thead { display: none; }
  .table.responsive-cards, .table.responsive-cards tbody,
  .table.responsive-cards tr, .table.responsive-cards td { display: block; width: 100%; }
  .table.responsive-cards tr {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    margin-bottom: 10px; background: var(--surface); padding: 6px 0;
  }
  .table.responsive-cards tbody tr:hover { background: var(--surface); }
  .table.responsive-cards td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    border: none; border-bottom: 1px solid var(--border); padding: 10px 14px;
    text-align: right;
  }
  .table.responsive-cards td:last-child { border-bottom: none; }
  .table.responsive-cards td::before {
    content: attr(data-label); font-weight: 700; font-size: .78rem;
    text-transform: uppercase; letter-spacing: .04em; color: var(--muted); text-align: left;
  }
  .table.responsive-cards td.no-label::before { content: none; }
  .table.responsive-cards td.no-label { justify-content: flex-end; }
  .table.responsive-cards .row-actions { text-align: right; }
}

@media (max-width: 420px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .auth-card { padding: 28px 20px; }
}

/* ---------- Print ---------- */
@media print {
  .sidebar, .topbar, .bottomnav, .page-head .actions, .pagination, .footer { display: none !important; }
  .main { margin-left: 0; }
  body { background: #fff; padding-bottom: 0; }
  .card, .table-wrap { box-shadow: none; }
}

/* ==========================================================================
   POLISH PASS — premium-SaaS refinement (judged on a 360px phone)
   Spacing scale used throughout: 4 / 6 / 8 / 10 / 12 / 14 / 16 / 18 / 20 / 24 / 32 / 44
   (44px = minimum touch target; never smaller for anything tappable).
   ========================================================================== */

/* Crisp, consistent keyboard focus ring */
:focus-visible {
  outline: 2px solid var(--brand-secondary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Buttons: subtle depth on the primary action */
.btn-primary { box-shadow: 0 2px 10px -2px rgba(10, 22, 40, .40); }
.btn-accent  { box-shadow: 0 2px 10px -2px rgba(184, 146, 42, .55); }
.btn-primary:hover, .btn-accent:hover { box-shadow: 0 4px 14px -2px rgba(10, 22, 40, .35); }

/* Stat cards: lift on hover, tighter type */
.stat { transition: transform .16s ease, box-shadow .16s ease; }
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat .value { font-variant-numeric: tabular-nums; }
.stat .label { margin-bottom: 2px; }

/* Cards: slightly stronger separation on small screens */
.card { box-shadow: var(--shadow); }
.card-head h3 { display: flex; align-items: center; gap: 8px; }

/* Empty states: softer, more deliberate */
.empty { background: var(--surface-2); border-style: dashed; }
.empty .big { font-size: 2.4rem; margin-bottom: 10px; line-height: 1; }

/* Alerts: gentle shadow so they sit above content */
.alert { box-shadow: var(--shadow-sm); }

/* Table polish: row dividers breathe, header stays crisp */
.table tbody td { border-bottom-color: #EDF1F7; }
.table thead th { background: #F7F9FC; }

/* Demo countdown pill — subtle, sticky, fixed bottom-right (above the mobile
   bottom nav). Rendered by layout.php only when Demo::bannerInfo() is non-null. */
.demo-pill {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 90;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 36px);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(10, 22, 40, .92);
  color: #fff;
  border: 1px solid rgba(184, 146, 42, .55);
  box-shadow: 0 6px 20px -4px rgba(10, 22, 40, .45);
  font-size: .78rem;
  font-weight: 650;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.demo-pill-dot {
  width: 8px; height: 8px; flex: 0 0 8px;
  border-radius: 50%;
  background: var(--brand-secondary);
  box-shadow: 0 0 6px var(--brand-secondary);
}
.demo-pill.expired { background: rgba(185, 28, 28, .94); border-color: rgba(255, 255, 255, .35); }
.demo-pill.expired .demo-pill-dot { background: #fff; box-shadow: none; }
@media (max-width: 768px) {
  .demo-pill {
    right: 12px;
    bottom: calc(var(--bottomnav-h) + 10px); /* clears the mobile bottom nav */
    font-size: .72rem;
    padding: 7px 12px;
  }
}

/* Auth card: entrance motion + brand accent bar */
.auth-card {
  position: relative;
  overflow: hidden;
  animation: authRise .45s cubic-bezier(.2, .7, .3, 1);
}
.auth-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 5px;
  background: linear-gradient(90deg, var(--brand-secondary), #E3C565 50%, var(--brand-secondary));
}
@keyframes authRise {
  from { opacity: 0; transform: translateY(16px) scale(.99); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .auth-card { animation: none; }
  .sidebar { transition: none; }
  .stat:hover { transform: none; }
}

/* Modal entrance */
.modal-backdrop.open .modal { animation: authRise .28s cubic-bezier(.2, .7, .3, 1); }

/* Sidebar links: smoother hover */
.nav-link { transition: background .14s ease, color .14s ease; }

/* 360px-specific tightening */
@media (max-width: 400px) {
  .topbar { padding: 0 12px; gap: 8px; }
  .content { padding: 14px 12px; }
  .card-pad, .card-body { padding: 16px; }
  .page-head { margin-bottom: 14px; }
  .stat { padding: 13px; }
  .stat .value { font-size: 1.25rem; }
}

/* ---------- Permission matrix (per-user overrides) ---------- */
.perm-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 4px; border-bottom: 1px solid var(--border); min-height: 48px;
}
.perm-row:last-child { border-bottom: none; }
.perm-name { font-weight: 600; font-size: .92rem; }
.perm-opts { display: flex; gap: 6px; flex-wrap: wrap; }
.perm-opt {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .8rem; font-weight: 600; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 7px 12px; cursor: pointer; min-height: 36px;
  transition: all .12s ease;
}
.perm-opt input { accent-color: var(--brand-primary); width: 16px; height: 16px; margin: 0; }
.perm-opt:has(input:checked) { border-color: var(--brand-primary); color: var(--brand-primary); background: #F0F4FA; }
.perm-opt.perm-grant:has(input:checked) { border-color: var(--green); color: var(--green); background: var(--green-bg); }
.perm-opt.perm-deny:has(input:checked) { border-color: var(--red); color: var(--red); background: var(--red-bg); }
@media (max-width: 640px) {
  .perm-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .perm-opts { display: grid; grid-template-columns: 1fr 1fr 1fr; }
  .perm-opt { justify-content: center; }
}

/* ==========================================================================
   v1.0.5 UI POLISH — premium-SaaS refinement
   --------------------------------------------------------------------------
   A) COMPATIBILITY ALIASES — several pages were written with Bootstrap-style
      class names (card-header, badge-success, text-muted, ...) that had no
      matching rules, so they rendered unstyled. These aliases map them onto
      the design-system tokens. New code should use the canonical names.
   ========================================================================== */

/* Card header/footer (canonical: .card-head) */
.card-header {
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface-2);
}
.card-header h2, .card-header h3 { margin: 0; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.card-footer {
  padding: 14px 20px; border-top: 1px solid var(--border);
  background: var(--surface-2); display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}

/* Table wrapper (canonical: .table-wrap) */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }

/* Text utilities */
.text-muted { color: var(--muted); }
.text-center { text-align: center; }
.text-right { text-align: right; }
small.text-muted, .small.text-muted { font-size: .8rem; }

/* Badge variants (canonical: .b-green / .b-red / .b-amber / .b-gray / .b-blue / .b-navy) */
.badge-success { background: var(--green-bg); color: var(--green); }
.badge-danger  { background: var(--red-bg); color: var(--red); }
.badge-warning { background: var(--amber-bg); color: var(--amber); }
.badge-secondary { background: var(--gray-bg); color: var(--gray); }
.badge-info    { background: var(--blue-bg); color: var(--blue); }
.badge-primary { background: var(--brand-primary); color: #fff; }

/* Button variants (canonical: .btn-primary / .btn-accent / .btn-danger / .btn-ghost) */
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { background: #166534; color: #fff; }
.btn-warning { background: var(--amber-bg); border-color: #EAC987; color: #78350F; }
.btn-warning:hover { background: #F7E3BC; color: #78350F; }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-light { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-light:hover { background: var(--border); }

/* Form action row */
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 18px; }

/* ==========================================================================
   B) COMPONENT REFINEMENT
   ========================================================================== */

/* Sidebar: crisper active state, calmer hover, clearer sections */
.nav-section { padding: 18px 12px 6px; }
.nav-section:first-child { padding-top: 8px; }
.nav-link {
  border-left: 3px solid transparent;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-right: 6px;
}
.nav-link:hover { background: rgba(255,255,255,.07); transform: translateX(2px); }
.nav-link.active {
  background: linear-gradient(90deg, rgba(184,146,42,.28) 0%, rgba(255,255,255,.12) 100%);
  border-left-color: var(--brand-secondary);
  box-shadow: none;
  color: #fff; font-weight: 700;
}
.nav-link .ico { opacity: .85; }
.nav-link.active .ico { opacity: 1; }
.sidebar-brand { padding: 20px 18px 16px; }
.sidebar-foot { letter-spacing: .02em; }

/* Topbar: subtle elevation + tighter control alignment */
.topbar { box-shadow: 0 1px 0 rgba(16,24,40,.02); }
.user-menu summary { box-shadow: var(--shadow-sm); }
.icon-btn { transition: background .15s ease, transform .1s ease; }
.icon-btn:active { transform: scale(.94); }

/* Bottom nav: active indicator bar */
.bottomnav a { position: relative; }
.bottomnav a.active::before {
  content: ""; position: absolute; top: 0; left: 24%; right: 24%; height: 3px;
  border-radius: 0 0 4px 4px; background: var(--brand-secondary);
}
.bottomnav a.active { color: var(--brand-primary); font-weight: 700; }

/* Buttons: clearer hierarchy */
.btn { letter-spacing: .01em; }
.btn-primary { box-shadow: 0 2px 10px -2px rgba(10,22,40,.40), inset 0 1px 0 rgba(255,255,255,.12); }
.btn-accent { box-shadow: 0 2px 10px -2px rgba(184,146,42,.55), inset 0 1px 0 rgba(255,255,255,.25); }
.btn:focus-visible { outline: 2px solid var(--brand-secondary); outline-offset: 2px; }

/* Forms: premium selects + consistent focus */
select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235D6D84' stroke-width='2.4'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 34px !important;
}
select[multiple] { background-image: none; padding-right: 12px !important; }
input[type="file"] { padding: 8px 12px; }
.form-control:focus, input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand-secondary);
  box-shadow: 0 0 0 3px rgba(184,146,42,.18);
}
.form-group label { letter-spacing: .01em; }

/* Key/value form tables (settings, confirm screens): label column + dividers */
.table-kv { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table-kv > tbody > tr > td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table-kv > tbody > tr:last-child > td { border-bottom: none; }
.table-kv > tbody > tr > td:first-child { width: 210px; font-weight: 650; font-size: .88rem; color: var(--muted); vertical-align: top; padding-top: 14px; }
.table-kv input, .table-kv select, .table-kv textarea { max-width: 560px; }
@media (max-width: 640px) {
  .table-kv > tbody > tr > td { display: block; width: auto !important; border-bottom: none; padding: 6px 0; }
  .table-kv > tbody > tr { border-bottom: 1px solid var(--border); display: block; padding: 6px 0; }
  .table-kv > tbody > tr > td:first-child { padding-top: 6px; }
}

/* Data tables: numeric alignment + tighter row actions */
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td .btn-sm { margin: 1px 2px; }
.table caption { text-align: left; padding: 10px 14px; font-weight: 700; color: var(--muted); font-size: .85rem; }

/* Cards */
.card-head .actions, .card-header .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Login: refined inputs + brand presence */
.auth-card input { font-size: 1rem; }
.auth-card .logo img { box-shadow: var(--shadow-sm); }
.auth-card .btn-primary { min-height: 48px; font-size: 1rem; }

/* Inline <code> and <kbd> */
code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px; font-size: .85em; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; overflow-x: auto; font-size: .85rem; }

/* Details/summary (used for delete confirmations) */
details summary { cursor: pointer; color: var(--red); font-weight: 600; font-size: .88rem; min-height: 44px; display: inline-flex; align-items: center; }

/* Definition rows inside cards */
.card-body > table.table { margin: -4px 0; }

/* Print stays clean */
@media print {
  .card-header { background: none; }
}

/* ==========================================================================
   Dashboard v2 (mockup-driven): greeting, stat cards, charts, quick
   actions, activity + events. Brand-driven: primary/secondary come from
   --brand-primary / --brand-secondary so each tenant gets their own theme.
   ========================================================================== */
.dash-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.dash-head h1 { margin: 0 0 4px; font-size: 1.65rem; letter-spacing: -0.01em; }
.dash-head .muted { margin: 0; color: var(--text-secondary); }
.dash-range { display: flex; align-items: center; gap: 10px; }
.dash-range select {
  padding: 10px 14px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg-surface); color: var(--text-primary); font-size: .9rem; cursor: pointer;
}
.dash-range-label { font-size: .88rem; color: var(--text-secondary); white-space: nowrap; }

/* Stat cards */
.dash-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-card {
  display: flex; gap: 14px; align-items: center;
  border-radius: 18px; padding: 20px 18px;
  border: 1px solid var(--border); background: var(--bg-surface);
  box-shadow: 0 2px 10px rgba(15,27,46,.05);
}
.sc-ico {
  width: 52px; height: 52px; border-radius: 50%; flex: 0 0 52px;
  display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
  background: rgba(255,255,255,.14);
}
.sc-label { font-size: .82rem; color: inherit; opacity: .75; margin-bottom: 2px; }
.sc-value { font-size: 1.55rem; font-weight: 800; letter-spacing: -0.01em; line-height: 1.15; }
.sc-sub { font-size: .78rem; margin-top: 4px; display: flex; align-items: center; gap: 6px; }
.sc-sub span:last-child { opacity: .65; }
.trend { font-weight: 700; padding: 2px 8px; border-radius: 20px; font-size: .75rem; }
.trend.up { color: #15803d; background: rgba(34,197,94,.14); }
.trend.down { color: #b91c1c; background: rgba(239,68,68,.14); }
.trend.flat { color: var(--text-secondary); background: rgba(100,116,139,.14); }
.sc-navy { background: var(--brand-primary); color: #fff; border-color: transparent; }
.sc-navy .trend.up { color: #4ade80; background: rgba(74,222,128,.16); }
.sc-gold { background: #fdf6e3; border-color: #f3e3b3; }
.sc-gold .sc-ico { background: rgba(184,146,42,.16); }
.sc-blue { background: #eff6ff; border-color: #dbeafe; }
.sc-blue .sc-ico { background: rgba(37,99,235,.12); }
.sc-green { background: #f0fdf4; border-color: #dcfce7; }
.sc-green .sc-ico { background: rgba(34,197,94,.14); }

/* Chart + donut row */
.dash-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-bottom: 20px; }
.dash-chart-card .card-body { padding: 8px 12px 4px; }
.legend { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--text-secondary); }
.lg { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.lg-sales { background: #0f1b2e; margin-left: 8px; }
.lg-pay { background: #d4a017; margin-left: 8px; }
.line-chart { width: 100%; height: auto; display: block; }
.line-chart .grid { stroke: #e8edf3; stroke-width: 1; }
.line-chart .axis { font-size: 11px; fill: #94a3b8; }
.line-chart .line-sales { fill: none; stroke: var(--brand-primary); stroke-width: 2.5; }
.line-chart .line-pay { fill: none; stroke: var(--brand-secondary); stroke-width: 2.5; }
.line-chart .area-pay { fill: rgba(184,146,42,.10); }
.line-chart .dot-sales { fill: var(--brand-primary); stroke: #fff; stroke-width: 1.5; }
.line-chart .dot-pay { fill: var(--brand-secondary); stroke: #fff; stroke-width: 1.5; }

.donut-wrap { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.donut { width: 168px; height: 168px; flex: 0 0 168px; }
.donut-bg { fill: none; stroke: #eef2f7; stroke-width: 26; }
.donut-num { font-size: 26px; font-weight: 800; fill: var(--text-primary); }
.donut-lbl { font-size: 11px; fill: var(--text-secondary); }
.donut-legend { list-style: none; margin: 0; padding: 0; flex: 1 1 160px; }
.donut-legend li { display: flex; align-items: center; gap: 8px; padding: 7px 0; font-size: .88rem; border-bottom: 1px solid var(--border); }
.donut-legend li:last-child { border-bottom: none; }
.donut-legend .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 10px; }
.donut-legend .dl { flex: 1; color: var(--text-secondary); }
.donut-legend .dp { color: var(--text-secondary); font-size: .8rem; min-width: 36px; text-align: right; }

/* Quick actions */
.dash-actions { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 20px; }
.qa-btn {
  display: flex; align-items: center; gap: 12px; padding: 16px;
  border-radius: 16px; text-decoration: none; color: var(--text-primary);
  border: 1px solid var(--border); background: var(--bg-surface);
  transition: transform .12s ease, box-shadow .12s ease;
}
.qa-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(15,27,46,.10); }
.qa-btn strong { display: block; font-size: .92rem; }
.qa-btn small { display: block; font-size: .76rem; opacity: .65; }
.qa-ico {
  width: 46px; height: 46px; border-radius: 14px; flex: 0 0 46px;
  display: flex; align-items: center; justify-content: center; font-size: 1.35rem;
  background: rgba(100,116,139,.12);
}
.qa-go { margin-left: auto; font-size: 1.4rem; opacity: .4; }
.qa-navy { background: var(--brand-primary); color: #fff; border-color: transparent; }
.qa-navy small { opacity: .7; }
.qa-gold { background: #b8922a; color: #fff; border-color: transparent; }
.qa-gold small { opacity: .8; }
.qa-blue { background: #eff6ff; }
.qa-green { background: #f0fdf4; }
.qa-purple { background: #faf5ff; }

/* Activity + events */
.dash-cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.activity-list, .event-list { list-style: none; margin: 0; padding: 0; }
.activity-list li { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.activity-list li:last-child { border-bottom: none; }
.act-ico {
  width: 38px; height: 38px; border-radius: 50%; flex: 0 0 38px;
  display: flex; align-items: center; justify-content: center; font-size: 1.05rem;
  background: rgba(184,146,42,.14);
}
.act-text { flex: 1; font-size: .9rem; }
.act-time { font-size: .76rem; color: var(--text-secondary); white-space: nowrap; }
.event-list li { display: flex; align-items: center; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.event-list li:last-child { border-bottom: none; }
.ev-date {
  width: 52px; flex: 0 0 52px; text-align: center;
  border: 1px solid var(--border); border-radius: 12px; padding: 8px 0; background: var(--bg-page);
}
.ev-date strong { display: block; font-size: 1.15rem; color: var(--brand-primary); }
.ev-date small { font-size: .72rem; color: var(--text-secondary); text-transform: uppercase; }
.ev-text strong { display: block; font-size: .9rem; }
.ev-text small { font-size: .78rem; color: var(--text-secondary); }

/* Dashboard responsive */
@media (max-width: 1100px) {
  .dash-stats { grid-template-columns: repeat(2, 1fr); }
  .dash-actions { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 900px) {
  .dash-grid, .dash-cols { grid-template-columns: 1fr; }
  .dash-actions { grid-template-columns: repeat(2, 1fr); }
  .dash-head h1 { font-size: 1.35rem; }
  .sc-value { font-size: 1.3rem; }
}
@media (max-width: 420px) {
  .dash-actions { grid-template-columns: 1fr; }
  .stat-card { padding: 16px 14px; }
}
