/* ═══════════════════════════════════════════════════════════════
   Cartograph — Application Styles
   Brand: US Housing Consultants 2026
   ═══════════════════════════════════════════════════════════════ */

/* ── Brand tokens ─────────────────────────────────────────────── */
:root {
  --navy:       #0A2A43;
  --navy-light: #0d3454;
  --navy-dark:  #071e30;
  --burgundy:   #720000;
  --burgundy-h: #8a0000;
  --gold:       #D6C7A1;
  --copper:     #A86F4C;
  --stone:      #B4B3AE;
  --charcoal:   #3A3F45;
  --bg:         #F2F3F5;
  --white:      #FFFFFF;
  --border:     #E2E4E8;
  --text:       #1A1D21;
  --text-muted: #6B7280;
  --sidebar-w:  240px;
}

/* ── Base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  font-family: 'Nunito Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

a { text-decoration: none; }

/* ── App wrapper (sidebar + main) ────────────────────────────── */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: #F8F8F8;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

/* Logo area */
.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 12px 14px;
  border-bottom: 1px solid rgba(0,0,0,0.1);
  position: relative;
}

.sidebar-logo-img {
  height: 52px;
  width: auto;
  max-width: none;
  display: block;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: rgba(0,0,0,0.35);
  padding: 16px 10px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--charcoal);
  font-size: 13.5px;
  font-weight: 600;
  transition: all 0.15s ease;
  cursor: pointer;
}

.nav-item i {
  font-size: 16px;
  flex-shrink: 0;
  width: 18px;
}

.nav-item:hover {
  background: rgba(0,0,0,0.07);
  color: var(--navy);
}

.nav-item.active {
  background: var(--burgundy);
  color: var(--white);
}

/* Footer */
.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--text-muted);
  font-size: 12px;
}

.user-info i { font-size: 16px; flex-shrink: 0; }
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.logout-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 13px;
  transition: all 0.15s ease;
}

.logout-btn:hover {
  background: rgba(0,0,0,0.07);
  color: var(--charcoal);
}

/* ── Main content area ───────────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.main-content > .alert {
  margin: 16px 24px 0;
}

/* ── Page header ─────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 28px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--white);
}

.page-header h1 {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  color: var(--navy);
  margin: 0;
}

.page-header .page-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.page-body {
  padding: 24px 28px;
  flex: 1;
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  font-weight: 700;
  font-size: 13px;
  color: var(--charcoal);
  letter-spacing: 0.2px;
}

/* Stat cards */
.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.stat-card .stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  margin-bottom: 12px;
}

.stat-icon.navy   { background: rgba(10,42,67,0.1);  color: var(--navy); }
.stat-icon.burg   { background: rgba(114,0,0,0.1);   color: var(--burgundy); }
.stat-icon.copper { background: rgba(168,111,76,0.12); color: var(--copper); }
.stat-icon.stone  { background: rgba(180,179,174,0.25); color: var(--charcoal); }

.stat-number {
  font-size: 28px;
  font-weight: 800;
  color: var(--navy);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

/* ── Tables ──────────────────────────────────────────────────── */
.table {
  font-size: 13.5px;
  margin-bottom: 0;
}

.table thead th {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  background: var(--bg);
  padding: 10px 16px;
  white-space: nowrap;
}

.table tbody td {
  padding: 12px 16px;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.table-hover tbody tr:hover td {
  background: rgba(10,42,67,0.03);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

/* ── Status badges ───────────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.status-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-active   { background: #E8F5E9; color: #2E7D32; }
.status-review   { background: #FFF8E1; color: #F57F17; }
.status-complete { background: #E3F2FD; color: #1565C0; }
.status-template { background: #F3E5F5; color: #6A1B9A; }
.status-cancelled{ background: #FAFAFA; color: #9E9E9E; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn-primary {
  background: var(--burgundy);
  border-color: var(--burgundy);
  font-weight: 600;
  font-size: 13px;
}

.btn-primary:hover, .btn-primary:focus {
  background: var(--burgundy-h);
  border-color: var(--burgundy-h);
}

.btn-outline-primary {
  border-color: var(--burgundy);
  color: var(--burgundy);
  font-weight: 600;
  font-size: 13px;
}

.btn-outline-primary:hover {
  background: var(--burgundy);
  border-color: var(--burgundy);
}

.btn-navy {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--white);
  font-weight: 600;
  font-size: 13px;
}

.btn-navy:hover {
  background: var(--navy-light);
  color: var(--white);
}

/* ── Forms ───────────────────────────────────────────────────── */
.form-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--charcoal);
  margin-bottom: 4px;
}

.form-control, .form-select {
  font-size: 13.5px;
  border-color: var(--border);
  border-radius: 6px;
}

.form-control:focus, .form-select:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(10,42,67,0.12);
}

.form-section-title {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--navy);
  padding-bottom: 8px;
  border-bottom: 2px solid var(--gold);
  margin-bottom: 16px;
  margin-top: 24px;
}

/* ── Action links (table) ────────────────────────────────────── */
.action-links { white-space: nowrap; }
.action-links .btn { font-size: 12px; padding: 3px 10px; }

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 48px;
  color: var(--stone);
  display: block;
  margin-bottom: 12px;
}

.empty-state p { font-size: 15px; margin-bottom: 16px; }

/* ── Breadcrumb ──────────────────────────────────────────────── */
.breadcrumb {
  font-size: 12px;
  margin-bottom: 0;
}

.breadcrumb-item a { color: var(--copper); }
.breadcrumb-item.active { color: var(--text-muted); }

/* ── Spreadsheet / Line items table ─────────────────────────── */
.spreadsheet-table {
  font-size: 12px;
  white-space: nowrap;
}

.spreadsheet-table thead th {
  font-size: 10.5px;
  vertical-align: middle;
  padding: 6px 4px;
}

.spreadsheet-table td {
  padding: 2px 3px;
  vertical-align: middle;
}

.spreadsheet-table .form-control-sm,
.spreadsheet-table .form-select-sm {
  padding: 1px 4px;
  font-size: 12px;
  height: 24px;
  border-radius: 2px;
}

/* Saving state indicators */
.row-saving { background-color: #fffbeb !important; }
.row-saved  { transition: background-color 1.5s; background-color: #f0fdf4 !important; }
.row-error  { background-color: #fef2f2 !important; }

/* Computed cells */
.computed-immediate, .computed-future { font-size: 12px; font-weight: 600; }

/* ── Totals bar ──────────────────────────────────────────────── */
.totals-bar {
  font-size: 13px;
  color: var(--charcoal);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  font-weight: 600;
}

/* ── Section tabs (community detail) ────────────────────────── */
.section-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}

.section-tab {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: color 0.15s;
}

.section-tab:hover { color: var(--navy); }
.section-tab.active { color: var(--burgundy); border-bottom-color: var(--burgundy); }

/* ── PDF Report styles ───────────────────────────────────────── */
.report-title    { font-size: 22pt; font-weight: bold; text-align: center; margin-bottom: 6px; }
.report-subtitle { font-size: 12pt; text-align: center; color: #555; }
.section-heading { font-size: 13pt; font-weight: bold; border-bottom: 2px solid #333; margin: 18px 0 8px; }
.report-table    { width: 100%; border-collapse: collapse; font-size: 8pt; }
.report-table th { background: #0A2A43; color: white; padding: 4px 6px; text-align: center; }
.report-table td { border: 1px solid #ccc; padding: 3px 5px; }
.report-table tr:nth-child(even) td { background: #f5f7fa; }
.immediate-row td { background: #fff9ed !important; }

/* ── Login page ──────────────────────────────────────────────── */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
}

.login-card {
  background: var(--white);
  border-radius: 14px;
  padding: 48px 40px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo-mark {
  width: 56px;
  height: 56px;
  background: var(--burgundy);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 28px;
  font-weight: 600;
  color: var(--gold);
  margin: 0 auto 16px;
}

.login-app-name {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 24px;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 4px;
}

.login-app-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

/* ── Back link ──────────────────────────────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .85rem;
  color: var(--text-muted);
  text-decoration: none;
  margin-bottom: .5rem;
}
.back-link:hover { color: var(--navy); }

/* ── Collapsible Sidebar ─────────────────────────────────────── */

/* Toggle button — fixed to sidebar right edge, vertically centered.
   Lives OUTSIDE <aside> so sidebar overflow:auto never clips it. */
.sidebar-toggle-btn {
  position: fixed;
  left: var(--sidebar-w);       /* right edge of sidebar */
  top: 50vh;
  transform: translateX(-50%) translateY(-50%);
  width: 22px;
  height: 44px;
  border-radius: 0 10px 10px 0;
  border: 1px solid var(--border);
  border-left: none;
  background: var(--white);
  color: var(--charcoal);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  cursor: pointer;
  z-index: 500;
  box-shadow: 3px 0 8px rgba(0,0,0,0.12);
  transition: left 0.22s ease, background 0.15s, color 0.15s;
  padding: 0;
  line-height: 1;
}

.sidebar-toggle-btn:hover {
  background: var(--navy);
  color: var(--white);
  border-color: var(--navy);
}

/* Move button when sidebar is collapsed */
.app-wrapper.sidebar-collapsed .sidebar-toggle-btn {
  left: 60px;
}

/* Backdrop for mobile — hidden by default */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 490;
}

/* Icon-only logo (hidden by default) */
.sidebar-icon-only {
  display: none;
  width: 32px;
  height: 32px;
}

/* Transitions */
.sidebar,
.main-content {
  transition: width 0.22s ease, min-width 0.22s ease, margin-left 0.22s ease;
}

/* Suppress transition on page load */
.no-transition .sidebar,
.no-transition .main-content,
.no-transition .sidebar-toggle-btn {
  transition: none !important;
}

/* ── Mobile overlay sidebar (≤768px) ────────────────────────── */
@media (max-width: 768px) {
  /* Sidebar slides in over content, doesn't push it */
  .sidebar {
    z-index: 1000;
    transition: transform 0.22s ease !important;
  }
  .app-wrapper.sidebar-collapsed .sidebar {
    width: var(--sidebar-w) !important;
    min-width: var(--sidebar-w) !important;
    transform: translateX(calc(-1 * var(--sidebar-w)));
  }
  .app-wrapper:not(.sidebar-collapsed) .sidebar {
    width: var(--sidebar-w) !important;
    min-width: var(--sidebar-w) !important;
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.22);
  }
  /* Content always full-width on mobile */
  .main-content {
    margin-left: 0 !important;
  }
  /* Toggle button: top-left corner when collapsed, rides sidebar edge when open */
  .sidebar-toggle-btn {
    top: 14px !important;
    transform: none !important;
    border-radius: 0 8px 8px 0 !important;
    height: 44px !important;
    left: 0 !important;
    z-index: 1001;
  }
  .app-wrapper:not(.sidebar-collapsed) .sidebar-toggle-btn {
    left: var(--sidebar-w) !important;
  }
  /* Show backdrop when sidebar is open on mobile */
  .sidebar-backdrop {
    display: block;
  }
  .app-wrapper.sidebar-collapsed .sidebar-backdrop {
    pointer-events: none;
    opacity: 0;
  }
  .app-wrapper:not(.sidebar-collapsed) .sidebar-backdrop {
    pointer-events: auto;
    opacity: 1;
  }
  .no-transition .sidebar-toggle-btn {
    transition: none !important;
  }
}

/* ── Collapsed state ────────────────────────────────────────── */

.app-wrapper.sidebar-collapsed .sidebar {
  width: 60px;
  min-width: 60px;
  overflow: visible; /* allow tooltips */
}

.app-wrapper.sidebar-collapsed .main-content {
  margin-left: 60px;
}

/* Hide text labels */
.app-wrapper.sidebar-collapsed .nav-item span,
.app-wrapper.sidebar-collapsed .nav-section-label,
.app-wrapper.sidebar-collapsed .user-name,
.app-wrapper.sidebar-collapsed .logout-btn span,
.app-wrapper.sidebar-collapsed .sidebar-full-logo {
  display: none;
}

/* Show icon-only logo */
.app-wrapper.sidebar-collapsed .sidebar-icon-only {
  display: block;
}

/* Center icons */
.app-wrapper.sidebar-collapsed .nav-item {
  justify-content: center;
  padding: 10px 0;
}

.app-wrapper.sidebar-collapsed .sidebar-nav {
  padding: 12px 4px;
}

.app-wrapper.sidebar-collapsed .sidebar-footer {
  padding: 12px 4px;
}

.app-wrapper.sidebar-collapsed .user-info {
  justify-content: center;
  padding: 8px 0;
}

.app-wrapper.sidebar-collapsed .logout-btn {
  justify-content: center;
  padding: 8px 0;
}

.app-wrapper.sidebar-collapsed .sidebar-logo {
  justify-content: center;
  padding: 16px 0 14px;
}

/* Tooltip-style labels on hover when collapsed */
.app-wrapper.sidebar-collapsed .nav-item {
  position: relative;
}

.app-wrapper.sidebar-collapsed .nav-item::after {
  content: attr(title);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--charcoal);
  color: var(--white);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 500;
}

.app-wrapper.sidebar-collapsed .nav-item:hover::after {
  opacity: 1;
}
