/* ==========================================================================
   Hanti-Dhowr Staff Portal — Design System
   Internal CSS design system (CLAUDE.md Module 6 Track B §17): Tailwind's
   build toolchain would add disproportionate infra complexity for this
   project, so tokens + components live here instead, hand-maintained and
   loaded with zero external/CDN dependencies (safe for production).
   ========================================================================== */

:root {
  /* Brand */
  --navy-950: #0b1220;
  --navy-900: #0f1b30;
  --navy-800: #16253f;
  --navy-700: #1e3252;
  --navy-600: #2a4468;
  --gold-500: #c9973f;
  --gold-400: #dcae5c;
  --gold-100: #f7ead1;

  /* Surfaces */
  --bg-canvas: #f6f5f2;
  --bg-surface: #ffffff;
  --bg-muted: #f1efe9;
  --border-subtle: #e6e2d8;
  --border-strong: #d8d2c4;

  /* Text */
  --text-primary: #1b1f27;
  --text-secondary: #5b5f6a;
  --text-muted: #8b8f99;
  --text-inverse: #f7f6f3;

  /* Status */
  --success-600: #0f7a53;
  --success-100: #e3f5ec;
  --warning-600: #a6650b;
  --warning-100: #fbf0dc;
  --critical-600: #b32a2a;
  --critical-100: #fbe6e6;
  --info-600: #2159a6;
  --info-100: #e6eefb;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --sidebar-width: 264px;
  --topbar-height: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}

/* ---------- App shell ---------- */

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

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--navy-950), var(--navy-900));
  color: var(--text-inverse);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: width 0.2s ease, padding 0.2s ease;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 25;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-mark {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--gold-400), var(--gold-500));
  display: flex; align-items: center; justify-content: center;
  color: var(--navy-950); font-weight: 700; font-size: 15px;
}

.brand-mark-logo { object-fit: contain; background: var(--bg-surface); padding: 3px; }

.brand-word { font-size: 16px; font-weight: 700; color: var(--text-inverse); }
.brand-sub { font-size: 11px; color: rgba(247, 246, 243, 0.55); letter-spacing: 0.04em; text-transform: uppercase; }

.nav { flex: 1; padding: var(--space-4) var(--space-3); }

.nav-section { margin-bottom: var(--space-4); }
.nav-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: rgba(247, 246, 243, 0.4); padding: 0 var(--space-3); margin-bottom: var(--space-2);
}

.nav-link {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 9px var(--space-3); border-radius: var(--radius-sm);
  color: rgba(247, 246, 243, 0.78); text-decoration: none; font-size: 14px; font-weight: 500;
  margin-bottom: 2px;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.06); color: var(--text-inverse); }
.nav-link.active { background: rgba(201, 151, 63, 0.16); color: var(--gold-100); }
.nav-link.active::before { content: ""; }
.nav-link .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.5; flex-shrink: 0; }

.nav-link.disabled {
  color: rgba(247, 246, 243, 0.32); cursor: default;
}
.nav-link .soon {
  margin-left: auto; font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em;
  background: rgba(255, 255, 255, 0.08); padding: 2px 6px; border-radius: var(--radius-pill);
}

.sidebar-footer {
  padding: var(--space-4); border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px; color: rgba(247, 246, 243, 0.45);
}

/* ---------- Main column ---------- */

.main-column { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-height); flex-shrink: 0;
  background: var(--bg-surface); border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--space-5); position: sticky; top: 0; z-index: 10;
}

.search-box { display: flex; align-items: center; gap: var(--space-2); flex: 1; max-width: 420px; }
.search-box input {
  width: 100%; border: 1px solid var(--border-subtle); border-radius: var(--radius-md);
  padding: 8px 12px 8px 34px; font-size: 14px; background: var(--bg-muted) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238b8f99' stroke-width='2'%3E%3Ccircle cx='7' cy='7' r='5.5'/%3E%3Cpath d='M11 11l3.5 3.5' stroke-linecap='round'/%3E%3C/svg%3E") 10px center no-repeat;
}
.search-box input:focus { outline: 2px solid var(--gold-500); outline-offset: 1px; background-color: var(--bg-surface); }

.topbar-right { display: flex; align-items: center; gap: var(--space-4); }

.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border-subtle);
  background: var(--bg-surface); display: flex; align-items: center; justify-content: center;
  position: relative; color: var(--text-secondary); cursor: pointer; text-decoration: none;
}
.icon-btn .badge-dot {
  position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--critical-600); border: 2px solid var(--bg-surface);
}

.user-menu { display: flex; align-items: center; gap: var(--space-2); }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--navy-800); color: var(--text-inverse);
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--text-muted); }

.logout-form button {
  border: 1px solid var(--border-subtle); background: var(--bg-surface); border-radius: var(--radius-sm);
  padding: 7px 12px; font-size: 13px; font-weight: 600; color: var(--text-secondary); cursor: pointer;
}
.logout-form button:hover { border-color: var(--critical-600); color: var(--critical-600); }

.content { flex: 1; padding: var(--space-5) var(--space-6) var(--space-7); }

/* ---------- Breadcrumbs / page header ---------- */

.breadcrumbs { display: flex; align-items: center; gap: var(--space-2); font-size: 13px; color: var(--text-muted); margin-bottom: var(--space-3); }
.breadcrumbs a { text-decoration: none; color: var(--text-muted); }
.breadcrumbs a:hover { color: var(--navy-700); }
.breadcrumbs .sep { opacity: 0.5; }
.breadcrumbs .current { color: var(--text-secondary); font-weight: 500; }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-5); flex-wrap: wrap; }
.page-title { font-size: 24px; }
.page-subtitle { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }
.page-actions { display: flex; gap: var(--space-2); flex-shrink: 0; }

/* ---------- Cards ---------- */

.card {
  background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-body { padding: var(--space-5); }
.card-header { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; justify-content: space-between; }
.card-header h2 { font-size: 16px; }

/* ---------- KPI cards ---------- */

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-4); margin-bottom: var(--space-6); }
.kpi-card { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: var(--space-4) var(--space-5); box-shadow: var(--shadow-sm); }
.kpi-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.kpi-value { font-size: 30px; font-weight: 700; margin-top: 6px; color: var(--navy-900); }
.kpi-value .unit { font-size: 15px; color: var(--text-muted); font-weight: 500; margin-left: 2px; }
.kpi-accent { border-left: 3px solid var(--gold-500); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 9px 16px; border-radius: var(--radius-md); font-size: 14px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; text-decoration: none; line-height: 1.2;
}
.btn-primary { background: var(--navy-900); color: var(--text-inverse); }
.btn-primary:hover { background: var(--navy-800); }
.btn-gold { background: var(--gold-500); color: var(--navy-950); }
.btn-gold:hover { background: var(--gold-400); }
.btn-secondary { background: var(--bg-surface); color: var(--text-primary); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--bg-muted); }
.btn-danger { background: var(--bg-surface); color: var(--critical-600); border-color: var(--critical-600); }
.btn-danger:hover { background: var(--critical-100); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Forms ---------- */

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-section { margin-bottom: var(--space-6); }
.form-section h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: var(--space-3); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-4); }
.field label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.field .required { color: var(--critical-600); }
.field input[type="text"], .field input[type="email"], .field input[type="password"],
.field input[type="search"], .field select, .field textarea {
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 9px 12px;
  font-size: 14px; font-family: inherit; background: var(--bg-surface); color: var(--text-primary);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--gold-500); outline-offset: 1px; border-color: var(--gold-500);
}
.field .help-text { font-size: 12px; color: var(--text-muted); }
.field .field-error { font-size: 12px; color: var(--critical-600); font-weight: 500; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--critical-600); }
.form-actions { display: flex; gap: var(--space-3); padding-top: var(--space-4); border-top: 1px solid var(--border-subtle); margin-top: var(--space-2); }

.alert { border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); font-size: 14px; margin-bottom: var(--space-4); border: 1px solid transparent; }
.alert-error { background: var(--critical-100); color: var(--critical-600); border-color: rgba(179, 42, 42, 0.25); }
.alert-success { background: var(--success-100); color: var(--success-600); border-color: rgba(15, 122, 83, 0.25); }
.alert-info { background: var(--info-100); color: var(--info-600); border-color: rgba(33, 89, 166, 0.2); }

/* ---------- Table ---------- */

.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border-subtle); flex-wrap: wrap; }
.table-toolbar form { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.table-toolbar input[type="search"], .table-toolbar select {
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 7px 10px; font-size: 13px; background: var(--bg-surface);
}
.table-scroll { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted);
  padding: 10px var(--space-5); border-bottom: 1px solid var(--border-subtle); white-space: nowrap;
}
table.data-table td { padding: 12px var(--space-5); border-bottom: 1px solid var(--border-subtle); vertical-align: middle; }
table.data-table tbody tr:hover { background: var(--bg-muted); }
table.data-table tbody tr:last-child td { border-bottom: none; }
.cell-code { font-weight: 600; color: var(--navy-800); }
.cell-muted { color: var(--text-muted); }
.row-link { text-decoration: none; color: inherit; display: block; }
/* Module 11: unread notifications get a subtle tint — never the only cue, always paired with an "Unread" badge/label. */
table.data-table tr.notification-unread { background: var(--info-100); }
table.data-table tr.notification-unread:hover { background: var(--bg-muted); }

.empty-state { padding: var(--space-7) var(--space-5); text-align: center; color: var(--text-muted); }
.empty-state h3 { color: var(--text-secondary); margin-bottom: var(--space-2); }

.pagination { display: flex; align-items: center; justify-content: space-between; padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border-subtle); font-size: 13px; color: var(--text-muted); }
.pagination .pages { display: flex; gap: var(--space-2); }
.pagination a, .pagination span.current {
  padding: 6px 11px; border-radius: var(--radius-sm); border: 1px solid var(--border-subtle); text-decoration: none; color: var(--text-secondary);
}
.pagination span.current { background: var(--navy-900); color: var(--text-inverse); border-color: var(--navy-900); }

/* ---------- Badges ---------- */

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: var(--radius-pill); font-size: 12px; font-weight: 600; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-100); color: var(--success-600); }
.badge-warning { background: var(--warning-100); color: var(--warning-600); }
.badge-critical { background: var(--critical-100); color: var(--critical-600); }
.badge-info { background: var(--info-100); color: var(--info-600); }
.badge-neutral { background: var(--bg-muted); color: var(--text-secondary); }

/* ---------- Tabs ---------- */

.tabs { display: flex; gap: var(--space-2); border-bottom: 1px solid var(--border-subtle); margin-bottom: var(--space-5); flex-wrap: wrap; }
.tab { padding: 10px var(--space-3); font-size: 14px; font-weight: 600; color: var(--text-muted); text-decoration: none; border-bottom: 2px solid transparent; }
.tab.active { color: var(--navy-900); border-color: var(--gold-500); }
.tab.disabled { color: var(--border-strong); cursor: default; }

/* ---------- Detail layout ---------- */

.detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: var(--space-5); align-items: start; }
.definition-list { display: grid; grid-template-columns: 1fr; gap: var(--space-3); }
.definition-row { display: flex; justify-content: space-between; gap: var(--space-4); padding: 10px 0; border-bottom: 1px solid var(--border-subtle); }
.definition-row:last-child { border-bottom: none; }
.definition-label { color: var(--text-muted); font-size: 13px; }
.definition-value { font-weight: 600; text-align: right; }

.action-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.action-list li { display: flex; align-items: center; justify-content: space-between; padding: var(--space-3) 0; border-bottom: 1px solid var(--border-subtle); font-size: 13px; }
.action-list li:last-child { border-bottom: none; }

.coming-soon-card { border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); padding: var(--space-5); text-align: center; color: var(--text-muted); background: var(--bg-muted); }

/* ---------- Auth pages ---------- */

.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at top left, var(--navy-800), var(--navy-950)); padding: var(--space-5); }
.auth-card { width: 100%; max-width: 400px; background: var(--bg-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: var(--space-6); }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); margin-bottom: var(--space-5); }
.auth-brand .brand-mark { width: 48px; height: 48px; font-size: 20px; }
.auth-brand .word { font-size: 20px; font-weight: 700; color: var(--navy-900); }
.auth-brand .tag { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.auth-card h1 { font-size: 18px; text-align: center; margin-bottom: var(--space-5); }
.auth-card .btn { width: 100%; margin-top: var(--space-2); }

/* ---------- Error pages ---------- */

.error-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: var(--space-6); background: var(--bg-canvas); }
.error-page .code { font-size: 72px; font-weight: 700; color: var(--navy-900); }
.error-page p { color: var(--text-secondary); max-width: 420px; margin: var(--space-3) 0 var(--space-5); }

/* ---------- Responsive ---------- */

@media (max-width: 1080px) {
  .detail-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 30; transform: translateX(-100%); transition: transform 0.2s ease; }
  .app-shell.sidebar-toggled .sidebar { transform: translateX(0); }
  .app-shell.sidebar-toggled .sidebar-backdrop { display: block; }
  .content { padding: var(--space-4); }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .search-box { display: none; }
}

@media (min-width: 861px) {
  .app-shell.sidebar-toggled .sidebar {
    width: 0;
    min-width: 0;
    padding: 0;
    border: 0;
    overflow: hidden;
  }
}

@media (max-width: 560px) {
  .topbar { padding: 0 var(--space-3); }
  .user-meta { display: none; }
  .page-header { flex-direction: column; align-items: stretch; }
}

/* ---------- Property Media (Module 4 follow-up) ---------- */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-4);
}
.media-item {
  position: relative;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-surface);
}
.media-thumb { aspect-ratio: 4 / 3; background: var(--bg-muted); }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-cover-badge { position: absolute; top: var(--space-2); left: var(--space-2); }
.media-item-body { padding: var(--space-3); }
.media-item-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
