/* ============================================================
   Renterman
   Sidebar Layout Design System
   ============================================================ */

/* ── CSS Custom Properties (Dark Mode Default) ─────────────── */
:root {
  --bg: #0a0f1e;
  --sidebar-bg: #0d1527;
  --topbar-bg: #0d1527;
  --panel: #131e35;
  --panel-strong: #1a2744;
  --primary: #00d6ae;
  --accent: #6366f1;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --font-display: "Space Grotesk", "Work Sans", system-ui, -apple-system, sans-serif;
  --font-body: "Work Sans", system-ui, -apple-system, sans-serif;
}

/* ── Light Mode ────────────────────────────────────────────── */
body.light-mode {
  --bg: #f1f5f9;
  --sidebar-bg: #1e293b;
  --topbar-bg: #ffffff;
  --panel: #ffffff;
  --panel-strong: #f8fafc;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

/* Light mode specific overrides */
body.light-mode tbody tr:hover {
  background: rgba(0, 0, 0, 0.02);
}

body.light-mode .modal-content {
  background: #ffffff;
}

body.light-mode .toast {
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
}

body.light-mode .search-results {
  background: var(--panel);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
}

body.light-mode mark.table-match {
  background: rgba(0, 140, 110, 0.18);
}

body.light-mode input[type="date"]::-webkit-calendar-picker-indicator,
body.light-mode input[type="month"]::-webkit-calendar-picker-indicator {
  filter: invert(0);
}

body.light-mode .sidebar {
  background: var(--sidebar-bg);
}

body.light-mode .sidebar .nav-item {
  color: #cbd5e1;
}

body.light-mode .sidebar .nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
}

body.light-mode .sidebar .nav-item.active {
  color: var(--primary);
}

body.light-mode .sidebar .nav-group-label {
  color: #64748b;
}

body.light-mode .sidebar-subtitle {
  color: #94a3b8;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

/* ── Base Body & App Layout ────────────────────────────────── */
body {
  margin: 0;
  display: flex;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
}

#appPage {
  display: flex;
  flex: 1;
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  min-width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 200;
  border-right: 1px solid var(--border);
}

/* Sidebar Header / Brand */
.sidebar-header {
  height: 64px;
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-logo {
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.sidebar-title {
  font-size: 15px;
  font-weight: 600;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
  line-height: 1.2;
}

.sidebar-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
  line-height: 1.2;
}

/* Sidebar Navigation */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.nav-group {
  margin-top: 8px;
}

.nav-group:first-child {
  margin-top: 4px;
}

.nav-group-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 8px 20px 4px;
  display: block;
  user-select: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 20px;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-body);
  text-align: left;
  transition: background 0.12s ease, color 0.12s ease;
  position: relative;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(0, 214, 174, 0.15), transparent);
  color: var(--primary);
  border-left-color: var(--primary);
  padding-left: 17px;
}

.nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.sidebar-meta {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
}

.sidebar-meta-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.sidebar-meta-line {
  font-size: 11px;
  color: var(--muted-text);
  line-height: 1.4;
}

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  height: 56px;
  min-height: 56px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  z-index: 100;
}

#sidebarToggle {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
  font-size: 18px;
  flex-shrink: 0;
  transition: background 0.12s;
}

#sidebarToggle:hover {
  background: rgba(255, 255, 255, 0.06);
}

/* Topbar Search */
.topbar-search {
  flex: 1;
  max-width: 480px;
  position: relative;
}

.global-search-input {
  width: 100%;
  height: 36px;
  border-radius: 8px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0 12px 0 36px;
  font-size: 13px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.15s;
}

.global-search-input:focus {
  border-color: var(--primary);
}

.global-search-input::placeholder {
  color: var(--text-muted);
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  font-size: 14px;
  display: flex;
  align-items: center;
}

/* Search Results Dropdown */
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 400px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 1000;
  padding: 6px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.search-results::-webkit-scrollbar {
  width: 4px;
}

.search-results::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.search-group {
  padding: 4px 0;
}

.search-group + .search-group {
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 8px;
}

.search-group-label {
  padding: 2px 14px 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--primary);
}

.search-item {
  padding: 7px 14px;
  cursor: pointer;
  border-radius: 8px;
  margin: 1px 5px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  transition: background 0.1s;
}

.search-item:hover {
  background: var(--panel-strong);
}

.search-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.search-item-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.search-highlight {
  color: var(--primary);
  font-weight: 700;
}

.search-no-results {
  padding: 18px 14px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

/* Topbar Right */
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.topbar-user {
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Main Content Area ─────────────────────────────────────── */
.main-content {
  padding: 24px;
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}

/* ── Progress Bar ──────────────────────────────────────────── */
.progress-bar {
  display: none;
  margin: 0 0 18px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(0, 214, 174, 0.22);
  background: linear-gradient(135deg, rgba(0, 214, 174, 0.14), rgba(99, 102, 241, 0.10));
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
  color: var(--text);
  line-height: 1.45;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  transform: translateY(-4px);
}

.progress-bar.active {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

.progress-bar strong {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
}

.progress-bar span {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Typography ────────────────────────────────────────────── */
h1 {
  font-family: var(--font-display);
  font-size: clamp(22px, 3vw, 32px);
  margin: 0 0 8px;
  line-height: 1.2;
  color: var(--text);
}

h2 {
  font-family: var(--font-display);
  font-size: 18px;
  margin: 0;
  color: var(--text);
}

h3 {
  font-family: var(--font-display);
  font-size: 15px;
  margin: 0;
  color: var(--text);
}

.eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  margin: 0 0 4px;
}

.muted {
  color: var(--text-muted);
  font-size: 13px;
}

.lede {
  color: var(--text-muted);
  max-width: 720px;
  margin: 0 0 18px;
}

/* ── Metric Cards (Dashboard) ──────────────────────────────── */
.metric-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.metric-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--card-accent, var(--primary));
}

.metric-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  margin: 8px 0 4px;
  color: var(--text);
}

.metric-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.metric-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Panels ────────────────────────────────────────────────── */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 20px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.section-export-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.section-export-btn {
  white-space: nowrap;
}

.panel-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  color: var(--text);
}

.panel-eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  margin: 0 0 4px;
}

/* ── Tables ────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.pdf-export-stage {
  position: fixed;
  left: -20000px;
  top: 0;
  z-index: -1;
  pointer-events: none;
  width: 1320px;
}

.pdf-export-sheet {
  background: var(--bg);
  color: var(--text);
  padding: 28px;
}

.pdf-export-sheet .panel {
  overflow: hidden;
}

.pdf-export-sheet .section-export-actions,
.pdf-export-sheet .section-export-btn,
.pdf-export-sheet button,
.pdf-export-sheet .btn,
.pdf-export-sheet .btn-icon,
.pdf-export-sheet input,
.pdf-export-sheet select,
.pdf-export-sheet textarea,
.pdf-export-sheet .toggle,
.pdf-export-sheet [data-action] {
  display: none !important;
}

.pdf-export-sheet .table-wrapper {
  overflow: visible;
}

.pdf-export-sheet .panel-header > :not(:first-child) {
  display: none !important;
}

.pdf-export-sheet table {
  table-layout: fixed;
}

.pdf-export-sheet th,
.pdf-export-sheet td {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: 12px;
}

.pdf-export-field {
  display: block;
  min-height: 30px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  white-space: nowrap;
}

.pdf-export-field.multiline {
  white-space: pre-wrap;
}

.pdf-export-sheet .summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.pdf-export-sheet .summary-item {
  min-width: 0;
}

.pdf-export-banner {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 22px;
  margin-bottom: 18px;
  background: linear-gradient(135deg, rgba(0, 214, 174, 0.16), rgba(75, 138, 255, 0.14));
  border: 1px solid rgba(0, 214, 174, 0.22);
  border-radius: 18px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.22);
}

.pdf-export-banner h1 {
  margin: 0 0 6px;
  font-size: 26px;
}

.pdf-export-banner p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}

.pdf-export-meta {
  text-align: right;
  min-width: 240px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead {
  background: var(--panel-strong);
}

th {
  padding: 10px 14px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  text-align: left;
  white-space: nowrap;
}

td {
  padding: 11px 14px;
  border-top: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-body);
  padding: 7px 14px;
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text);
  background: var(--panel-strong);
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.4;
  text-decoration: none;
}

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

.btn.primary {
  background: var(--primary);
  color: #04101c;
  border: none;
  font-weight: 600;
}

.btn.primary:hover {
  opacity: 0.9;
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
}

.btn.ghost:hover {
  background: rgba(255, 255, 255, 0.06);
}

.btn.danger {
  border-color: var(--danger);
  color: var(--danger);
  background: transparent;
}

.btn.danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

.btn.success {
  border-color: var(--success);
  color: var(--success);
  background: transparent;
}

.btn.success:hover {
  background: rgba(16, 185, 129, 0.1);
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 15px;
  padding: 4px 6px;
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-body);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s;
}

.btn-icon:hover {
  background: var(--panel-strong);
}

/* ── Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--panel-strong);
  color: var(--text-muted);
  gap: 4px;
}

.badge.success {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.badge.warning {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.badge.danger {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.badge-north {
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
}

.badge-south {
  background: rgba(234, 88, 12, 0.15);
  color: #ea580c;
}

.badge-owner {
  background: rgba(99, 102, 241, 0.15);
  color: #6366f1;
}

.badge-other {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  font-weight: 700;
}

.badge-other-btn {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border-color: rgba(245, 158, 11, 0.35);
}
.badge-other-btn:hover {
  background: rgba(245, 158, 11, 0.25);
}

.category-select {
  font-size: 11px;
  padding: 2px 4px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.btn-xs {
  padding: 2px 6px;
  font-size: 11px;
  line-height: 1.4;
}

.discom-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.discom-select {
  min-width: 92px;
  padding: 5px 8px;
  font-size: 12px;
}

.location-input {
  min-width: 140px;
  padding: 6px 8px;
  font-size: 12px;
}

tr.special-bill-row td {
  background: rgba(245, 158, 11, 0.12);
}

tbody tr.special-bill-row:hover td {
  background: rgba(245, 158, 11, 0.18);
}

tr.archived-paid-row td {
  background: rgba(148, 163, 184, 0.14);
  color: var(--muted-text);
}

tbody tr.archived-paid-row:hover td {
  background: rgba(148, 163, 184, 0.18);
}

.inline-edit-trigger {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px dashed rgba(148, 163, 184, 0.35);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
}

.inline-edit-trigger:hover {
  border-color: rgba(0, 214, 174, 0.45);
  color: var(--text);
}

.inline-edit-trigger.missing {
  color: var(--text-muted);
}

.copy-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
}

.copy-inline-value {
  min-width: 0;
}

.copy-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  opacity: 0.78;
  transition: opacity .18s ease, color .18s ease, border-color .18s ease, background .18s ease;
}

.copy-btn::before,
.copy-btn::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 10px;
  border: 1.5px solid currentColor;
  border-radius: 2px;
}

.copy-btn::before {
  transform: translate(2px, -2px);
  opacity: 0.55;
}

.copy-btn::after {
  background: var(--panel);
  transform: translate(-1px, 1px);
}

td:hover .copy-btn,
.copy-inline:focus-within .copy-btn,
.copy-btn:focus-visible {
  opacity: 1;
}

.copy-btn:hover,
.copy-btn:focus-visible {
  color: var(--text);
  border-color: var(--border);
  background: rgba(148, 163, 184, 0.12);
}

.inline-edit-popover {
  position: fixed;
  z-index: 1500;
  min-width: 220px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.inline-edit-popover label {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}

.inline-edit-popover input {
  width: 100%;
  margin-bottom: 10px;
}

.inline-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

tr.location-section-row td {
  background: rgba(59, 130, 246, 0.12);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-top: 1px solid rgba(59, 130, 246, 0.24);
}

.usc-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.usc-summary-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  background: var(--panel-strong);
}

.usc-summary-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.usc-summary-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.usc-summary-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Actions Grid ──────────────────────────────────────────── */
.actions-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── Map / Properties Layout ───────────────────────────────── */
.map-layout {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 16px;
  align-items: start;
}

.sticky-detail {
  position: sticky;
  top: 80px;
}

.map-grid {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.map-property-name {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--primary);
  margin: 0 0 8px;
}

.map-building {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  background: var(--panel-strong);
}

.building-label {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 8px;
}

.map-floors {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.floor-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.portion-tile {
  width: 120px;
  min-height: 70px;
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s;
  color: #04101c;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.portion-tile:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  border-color: rgba(255, 255, 255, 0.3);
}

.portion-tile .t-num {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
}

.portion-tile .t-name {
  font-size: 11px;
  opacity: 0.85;
}

.portion-tile .t-usc {
  font-size: 10px;
  opacity: 0.7;
}

.portion-tile small {
  display: block;
  font-weight: 600;
  margin-top: 4px;
  font-size: 11px;
}

/* ── Modal ─────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
}

.modal-content {
  background: #131e35;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: min(480px, 92%);
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
}

body.light-mode .modal-content {
  background: #ffffff;
}

#editModal .modal-content {
  width: min(660px, 95%);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}

#editModal .modal-body {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-body table {
  width: 100%;
  border-collapse: collapse;
}

.modal-body th,
.modal-body td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
  gap: 8px;
}

/* ── Form Elements ─────────────────────────────────────────── */
label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
}

input,
select,
textarea {
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-body);
  width: 100%;
  box-sizing: border-box;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

textarea {
  resize: vertical;
}

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="month"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

/* ── Rent Grid ─────────────────────────────────────────────── */
.rent-grid {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.rent-grid table {
  width: 100%;
  border-collapse: collapse;
}

.rent-grid th {
  background: var(--panel-strong);
  padding: 8px 10px;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.rent-grid td {
  padding: 6px 10px;
  border-top: 1px solid var(--border);
}

.rent-grid input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 0;
}

.rent-grid input:focus {
  outline: 1px solid var(--primary);
  border-radius: 4px;
}

.rent-grid th:nth-child(1) { width: 120px; }
.rent-grid th:nth-child(2) { width: 80px; }
.rent-grid th:nth-child(3) { width: 80px; }
.rent-grid th:nth-child(4) { width: 120px; }
.rent-grid th:nth-child(5) { width: 120px; }

/* ── Rent Config inline inputs ─────────────────────────────── */
#rentConfigBody input {
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  color: var(--text);
  font-size: 13px;
  width: auto;
}

#rentConfigBody input:focus {
  outline: none;
  border-color: var(--primary);
}

#propertyTaxBody input,
#propertyTaxBody textarea {
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  color: var(--text);
  font-size: 13px;
  width: auto;
}

#propertyTaxBody input:focus,
#propertyTaxBody textarea:focus {
  outline: none;
  border-color: var(--primary);
}

#rentConfigBody tr.rent-config-total-row td {
  background: rgba(255, 255, 255, 0.04);
  font-weight: 700;
  border-top: 2px solid var(--border);
}

#rentConfigBody tr.rent-config-total-row td strong {
  color: var(--text);
}

/* ── Summary / Rent Summary ────────────────────────────────── */
.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.summary-item {
  background: var(--panel-strong);
  border-radius: 10px;
  padding: 12px 16px;
  flex: 1;
  min-width: 120px;
  border: 1px solid var(--border);
}

.summary-item p {
  margin: 0 0 4px;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.rent-config-group-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.summary-item strong {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

/* ── Chart Rows ────────────────────────────────────────────── */
.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.chart-single {
  max-height: 280px;
}

/* ── Legend ────────────────────────────────────────────────── */
.legend {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.legend-dot.success { background: var(--success); }
.legend-dot.warning { background: var(--warning); }
.legend-dot.danger  { background: var(--danger); }

/* ── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  z-index: 9999;
  transition: opacity 0.2s, transform 0.2s;
  transform: translateY(8px);
  color: var(--text);
  box-shadow: var(--shadow);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* ── Table Search Highlights ───────────────────────────────── */
mark.table-match {
  background: rgba(0, 214, 174, 0.22);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
  font-weight: 600;
}

/* ── Toggle ────────────────────────────────────────────────── */
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}

/* ── Tooltip ───────────────────────────────────────────────── */
.tooltip {
  position: absolute;
  background: rgba(0, 0, 0, 0.88);
  color: #fff;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  pointer-events: none;
  z-index: 4000;
  display: none;
  white-space: nowrap;
}

/* ── SVG Viewer ────────────────────────────────────────────── */
.svg-viewer {
  min-height: 200px;
  border: 1px dashed var(--border);
  padding: 10px;
  border-radius: 8px;
}

/* ── Hero Section (legacy / page header) ───────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ── Section Headings ──────────────────────────────────────── */
.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 12px;
}

/* ── Grid Utilities ────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 16px;
}

/* ── Tab system (kept for legacy tab views inside panels) ──── */
.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.tab-btn {
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-strong);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-body);
  transition: all 0.12s;
}

.tab-btn:hover {
  border-color: var(--primary);
  color: var(--text);
}

.tab-btn.active {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(0, 214, 174, 0.08);
}

/* ── Hero (used in some pages) ─────────────────────────────── */
.hero {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 24px;
  align-items: center;
  margin-bottom: 24px;
}

/* ── Sidebar overlay backdrop (mobile) ─────────────────────── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 190;
}

.sidebar-backdrop.visible {
  display: block;
}

/* ── Scrollbar global ──────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ── Selection ─────────────────────────────────────────────── */
::selection {
  background: rgba(0, 214, 174, 0.25);
  color: var(--text);
}

/* ── Focus visible ─────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ── Utility Classes ───────────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.font-600 { font-weight: 600; }
.font-700 { font-weight: 700; }
.text-primary { color: var(--primary); }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.hidden { display: none !important; }
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Divider ───────────────────────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

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

.empty-state-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state p {
  margin: 0;
  font-size: 14px;
}

/* ── Inline badges in tables ───────────────────────────────── */
td .badge {
  vertical-align: middle;
}

/* ── Number / currency display ─────────────────────────────── */
.currency {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* ── Responsive: Tablet / Mobile ───────────────────────────── */
@media (max-width: 960px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-220px);
    transition: transform 0.25s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* topbar and main-content already in flex flow, no fixed offsets to reset */

  .map-layout {
    grid-template-columns: 1fr;
  }

  .sticky-detail {
    position: static;
  }

  .chart-row {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .hero {
    grid-template-columns: 1fr;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .summary {
    flex-wrap: wrap;
  }
}

@media (max-width: 640px) {
  .metric-cards {
    grid-template-columns: 1fr 1fr;
  }

  .main-content {
    padding: 16px;
  }

  th,
  td {
    font-size: 12px;
    padding: 8px 10px;
  }

  .portion-tile {
    width: 100px;
    min-height: 60px;
  }

  .topbar {
    padding: 0 12px;
    gap: 8px;
  }

  .topbar-user {
    display: none;
  }

  .modal-content {
    padding: 16px;
  }

  .summary-item strong {
    font-size: 18px;
  }
}
