:root {
  --bg: #faf9f5;
  --card: #ffffff;
  --border: #e6e4dd;
  --ink: #1a1a1a;
  --muted: #6b7280;
  --muted-2: #9ca3af;
  --primary: #2b3ff0;
  --primary-dark: #1f2fc7;
  --primary-tint: #e8eaff;
  --danger: #b42318;
  --danger-tint: #fde2e1;
  --warn: #92400e;
  --warn-tint: #fdedd3;
  --ok: #067647;
  --ok-tint: #d1fae5;
  --gray-tint: #eeeeec;
  --radius: 10px;
  --radius-lg: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3, .serif {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
  margin: 0;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* Sidebar */
.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 20px;
  font-size: 17px;
}
.sidebar-logo .icon {
  width: 28px; height: 28px;
  background: var(--primary);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 14px;
}
.sidebar nav a {
  display: block;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 14px;
  margin-bottom: 2px;
}
.sidebar nav a:hover { background: var(--gray-tint); text-decoration: none; }
.sidebar nav a.active { background: var(--primary-tint); color: var(--primary-dark); font-weight: 600; }
.nav-section-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted-2); padding: 14px 12px 6px;
}

/* Main column */
.main { flex: 1; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.topbar .search {
  padding: 9px 14px 9px 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--muted);
  width: 100%;
}
.search-form { flex: 1; max-width: 480px; position: relative; }
.topbar > .search { flex: 1; max-width: 480px; }

/* Icon overlaid inside a text input — wrap the input in
   <div class="input-with-icon">, icon first, then the input itself. */
.input-with-icon { position: relative; display: inline-block; }
.input-with-icon svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted-2); pointer-events: none; }
.input-with-icon input[type=text] { padding-left: 38px; }
.search-form svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted-2); pointer-events: none; }
.search-suggestions {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.1); z-index: 150; overflow: hidden;
}
.search-suggestion {
  display: block; width: 100%; text-align: left; padding: 10px 14px;
  border: 0; border-bottom: 1px solid var(--border); background: none; cursor: pointer;
  color: var(--ink); font-size: 14px;
}
.search-suggestion:last-child { border-bottom: 0; }
.search-suggestion:hover, .search-suggestion.active { background: var(--primary-tint); }
.search-suggestion .type { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted-2); margin-right: 8px; }
.search-suggestion .sub { color: var(--muted); font-size: 12px; margin-left: 6px; }
.topbar .spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary-tint); color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.user-chip .name { font-weight: 600; font-size: 13px; }
.user-chip .role { color: var(--muted); font-size: 12px; }

.content { padding: 28px 32px 60px; max-width: 1240px; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.page-header h1 { font-size: 30px; }
.page-header p { color: var(--muted); margin-top: 6px; }
.page-header .actions { display: flex; gap: 10px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: var(--gray-tint); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { border-color: var(--danger); color: var(--danger); background: #fff; }
.btn-danger:hover { background: var(--danger-tint); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* Cards / grid */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.grid { display: grid; gap: 18px; }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid-2 { grid-template-columns: 2fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }

.stat-card { padding: 16px 18px; }
.stat-card .label { color: var(--muted); font-size: 13px; }
.stat-card .value { font-family: Georgia, serif; font-size: 26px; margin-top: 6px; }

/* Pills */
.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill-critical { background: var(--danger-tint); color: var(--danger); }
.pill-warn { background: var(--warn-tint); color: var(--warn); }
.pill-missing { background: var(--gray-tint); color: var(--muted); }
.pill-ok { background: var(--ok-tint); color: var(--ok); }
.pill-neutral { background: var(--primary-tint); color: var(--primary-dark); }

/* Tables — a card whose content is (or contains) a table scrolls
   horizontally within itself on narrow screens, so the page body never
   scrolls sideways. */
.card:has(table) { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 480px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); }
td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: none; }

/* Forms */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=tel], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}
textarea { resize: vertical; }
.field { margin-bottom: 16px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.help { color: var(--muted-2); font-size: 12px; margin-top: 4px; }
.error-text { color: var(--danger); font-size: 13px; margin-top: 4px; }

/* Flash */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; font-size: 14px; }
.flash-success { background: var(--ok-tint); color: var(--ok); }
.flash-error { background: var(--danger-tint); color: var(--danger); }
.flash-info { background: var(--primary-tint); color: var(--primary-dark); }

/* Masked value + reveal */
.masked-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.masked-row:last-child { border-bottom: none; }
.masked-row .k { color: var(--muted); font-size: 13px; }
.masked-row .v { font-variant-numeric: tabular-nums; }

/* Auth pages */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 32px; }
.auth-card h1 { font-size: 22px; margin-bottom: 6px; }
.auth-card .sub { color: var(--muted); margin-bottom: 24px; font-size: 13px; }

/* Choose-profile screen */
.choose-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; max-width: 900px; margin: 40px auto; }
.choose-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px; }
.choose-card.selected { border-color: var(--primary); background: var(--primary-tint); }
.choose-card .icon-box { width: 44px; height: 44px; border-radius: 10px; background: var(--primary-tint); color: var(--primary-dark); display: flex; align-items: center; justify-content: center; margin-bottom: 14px; font-size: 20px; }

.empty-state { border: 1px dashed var(--border); border-radius: var(--radius-lg); padding: 40px 20px; text-align: center; color: var(--muted); }

/* Asset breakdown tile grid */
.asset-tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 18px 12px; }
.asset-tile-grid.list-view { grid-template-columns: 1fr; }
.asset-tile { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; text-decoration: none; color: var(--ink); }
.asset-tile:hover { text-decoration: none; }
.asset-tile-grid.list-view .asset-tile { flex-direction: row; text-align: left; justify-content: space-between; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.asset-tile .icon-circle {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--primary-tint); display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.asset-tile .tile-label { font-size: 13px; color: var(--muted); }
.asset-tile .tile-value { font-weight: 700; font-size: 14px; }
.toggle-switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-switch .slider { position: absolute; inset: 0; background: var(--border); border-radius: 999px; cursor: pointer; transition: background .15s; }
.toggle-switch .slider::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; }
.toggle-switch input:checked + .slider { background: var(--primary); }
.toggle-switch input:checked + .slider::before { transform: translateX(18px); }

.tabs { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); color: var(--ink); font-size: 13px; }
.tabs a.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* Mobile nav drawer — hidden on desktop */
.menu-toggle { display: none; flex-direction: column; justify-content: center; gap: 4px; width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); cursor: pointer; flex-shrink: 0; padding: 0; }
.menu-toggle span { display: block; width: 16px; height: 2px; background: var(--ink); margin: 0 auto; border-radius: 2px; }
.sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .choose-grid { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .menu-toggle { display: flex; }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; z-index: 100;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 0 0 24px rgba(0,0,0,.15);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35);
    z-index: 99; opacity: 0; pointer-events: none; transition: opacity .2s ease;
  }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
  .content { padding: 20px; }
  .topbar { padding: 14px 20px; gap: 10px; }
  .topbar .search { display: none; }
  .search-form { display: none; }
  .user-chip .role { display: none; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header .actions { width: 100%; flex-wrap: wrap; }
  .page-header .actions .btn, .page-header .actions form { flex: 1 1 auto; min-width: 140px; }
  .grid-stats { grid-template-columns: repeat(2, 1fr); }
  table { font-size: 13px; }
}
@media (max-width: 480px) {
  .grid-stats { grid-template-columns: 1fr; }
  .asset-tile-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Belt-and-braces: no single element (a button row that doesn't wrap, a
   wide table, a long unbroken filename/label) should ever be able to
   force the whole page to scroll sideways — that's what made the mobile
   dashboard feel "stuck", since the page was wider than the viewport and
   a vertical swipe could land on the horizontal scroll instead. */
html, body { max-width: 100%; overflow-x: hidden; }

/* "View sample data" popup (see modules/dashboard/sample-preview.php) */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(20,18,14,.45);
  z-index: 200; align-items: center; justify-content: center; padding: 24px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--card); border-radius: var(--radius-lg); width: 100%; max-width: 980px;
  height: 85vh; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--border);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal-box iframe { flex: 1; width: 100%; border: 0; }
@media (max-width: 720px) {
  .modal-overlay { padding: 0; }
  .modal-box { height: 100%; max-width: 100%; border-radius: 0; }
}

/* Loading spinner for in-progress form submits (see assets/js/app.js) */
.btn-spinner {
  display: inline-block; width: 14px; height: 14px; flex-shrink: 0;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  opacity: .6; animation: btn-spin .6s linear infinite;
}
.btn.is-loading { cursor: progress; opacity: .85; }
.btn.is-loading[disabled] { opacity: .85; }
@keyframes btn-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .btn-spinner { animation-duration: 1.4s; }
}

/* Filterable/sortable admin tables (see modules/admin/users.php) */
.table-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.table-toolbar input, .table-toolbar select { width: auto; }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--primary); }
.sort-arrow { display: inline-block; font-size: 10px; color: var(--primary); }
@media (max-width: 720px) {
  .table-toolbar input, .table-toolbar select { flex: 1 1 auto; min-width: 130px; max-width: none !important; }
}

/* Security PIN gate (set-up / verify / forgot) — a full-screen dimmed
   backdrop with a centered card, always shown (not JS-toggled like
   .modal-overlay) since the whole point is that there is nothing else
   on the page behind it to interact with until the PIN is handled. */
.pin-gate-backdrop {
  position: fixed; inset: 0; background: rgba(20,18,14,.55);
  z-index: 300; display: flex; align-items: center; justify-content: center;
  padding: 24px; overflow-y: auto;
}
.pin-gate-box {
  background: var(--card); border-radius: var(--radius-lg); width: 100%; max-width: 420px;
  padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.25); margin: auto;
}
.pin-gate-box h1 { font-size: 22px; margin-bottom: 6px; }
.pin-gate-box .sub { color: var(--muted); margin-bottom: 20px; font-size: 14px; }

/* Will preview — a formal legal-document look (serif, numbered clauses,
   generous margins, ruled signature lines) distinct from the app's own
   card-based UI, since this is the thing that gets printed and signed. */
.will-document {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  max-width: 760px; margin: 0 auto; padding: 56px 64px; font-family: Georgia, "Times New Roman", serif;
  color: var(--ink); line-height: 1.7;
}
.will-title { font-size: 24px; text-align: center; letter-spacing: 1px; margin-bottom: 4px; }
.will-subtitle { text-align: center; color: var(--muted); margin-bottom: 30px; font-style: italic; }
.will-heading { font-size: 17px; margin: 28px 0 10px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.will-clause { text-align: justify; margin-bottom: 14px; }
.will-asset { margin: 16px 0 22px; }
.will-asset-title { font-weight: 700; margin-bottom: 8px; }
.will-asset-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.will-asset-table th, .will-asset-table td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.will-asset-table th { background: var(--gray-tint); font-weight: 600; }
.will-signature-block, .will-witness-block { margin-top: 34px; max-width: 320px; }
.will-signature-line { border-bottom: 1px solid var(--ink); height: 50px; margin-bottom: 6px; display: flex; align-items: flex-end; }

@media print {
  .sidebar, .sidebar-backdrop, .topbar, .page-header .actions, .no-print { display: none !important; }
  .app-shell, .main, .content { display: block !important; margin: 0 !important; padding: 0 !important; }
  .will-document { border: none; box-shadow: none; max-width: none; padding: 0; }
}
