/* =========================================================================
   PropertyLedger design system
   ========================================================================= */

:root {
  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Brand */
  --brand-950: #071a38;
  --brand-900: #0b2c5c;
  --brand-800: #0f4c9c;
  --brand-700: #12579f;
  --brand-600: #1b6ec2;
  --brand-500: #2f86dd;
  --brand-400: #63a7ee;
  --brand-200: #b6d8fb;
  --brand-100: #dcebff;
  --brand-50: #f3f8ff;

  /* Neutrals */
  --slate-950: #0a0f1a;
  --slate-900: #0f172a;
  --slate-800: #1e293b;
  --slate-700: #334155;
  --slate-600: #475569;
  --slate-500: #64748b;
  --slate-400: #94a3b8;
  --slate-300: #cbd5e1;
  --slate-200: #e2e8f0;
  --slate-100: #f1f5f9;
  --slate-50: #f8fafc;

  /* Semantic */
  --success-700: #15803d;
  --success-600: #16a34a;
  --success-100: #dcfce7;
  --danger-700: #b91c1c;
  --danger-600: #dc2626;
  --danger-100: #fee2e2;
  --warning-700: #b45309;
  --warning-600: #d97706;
  --warning-100: #fef3c7;
  --info-700: #0e7490;
  --info-600: #0891b2;
  --info-100: #cffafe;

  /* Surfaces */
  --surface: #ffffff;
  --surface-muted: var(--slate-50);
  --page-bg: #f4f7fb;
  --border-subtle: var(--slate-200);
  --text-body: var(--slate-800);
  --text-muted: #667085;
  --text-heading: var(--slate-900);

  /* Geometry */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-sm: 0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 10px 28px rgba(15, 23, 42, 0.09);
  --shadow-lg: 0 22px 48px rgba(15, 23, 42, 0.14);
  --sidebar-width: 272px;
}

[data-theme="dark"] {
  --surface: #111a2c;
  --surface-muted: #0e1728;
  --page-bg: #0b1220;
  --border-subtle: #1f3b63;
  --text-body: #dbeafe;
  --text-muted: #9cc5f2;
  --text-heading: #e0f2fe;
  --brand-50: #0f2d52;
  --brand-100: #0f2d52;
}

html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page-bg);
  color: var(--text-body);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--text-heading);
  font-weight: 800;
  letter-spacing: -0.01em;
}

.app-main > h1:first-child,
.app-main > h2:first-child,
.app-main > h3:first-child {
  margin-bottom: 1.1rem;
}

h1 {
  font-size: 1.85rem;
}

a {
  color: var(--brand-600);
}

a:hover {
  color: var(--brand-700);
}

::selection {
  background: var(--brand-200);
}

/* -------------------------------------------------------------------------
   Focus states
   ------------------------------------------------------------------------- */
.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
  box-shadow: 0 0 0 3px var(--brand-100);
  outline: none;
}

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

.app-sidebar {
  background: linear-gradient(185deg, var(--slate-950) 0%, #0d1730 55%, var(--brand-950) 130%);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: var(--shadow-lg);
  color: #ffffff;
  width: var(--sidebar-width);
  z-index: 1020;
}

.sidebar-backdrop {
  display: none;
}

.app-sidebar-header {
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  min-height: 72px;
  padding: 1rem 1.1rem;
}

.app-brand {
  align-items: center;
  color: #ffffff;
  display: flex;
  font-weight: 800;
  font-size: 1.02rem;
  gap: 0.7rem;
  line-height: 1.15;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.app-brand-logo {
  background: #ffffff;
  border-radius: 9px;
  flex: 0 0 40px;
  height: 40px;
  object-fit: contain;
  padding: 0.2rem;
  width: 40px;
}

.app-brand:hover {
  color: #ffffff;
}

.app-brand-text {
  max-width: 160px;
}

.app-sidebar-toggle {
  align-items: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-sm);
  display: inline-flex;
  justify-content: center;
  min-height: 42px;
  padding: 0.45rem 0.6rem;
  width: 46px;
  transition: background 0.15s ease;
}

.app-sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.16);
}

.app-hamburger,
.app-hamburger::before,
.app-hamburger::after {
  background: #ffffff;
  border-radius: 999px;
  display: block;
  height: 2px;
  transition: transform 0.18s ease, opacity 0.18s ease;
  width: 22px;
}

.app-hamburger {
  position: relative;
}

.app-hamburger::before,
.app-hamburger::after {
  content: "";
  left: 0;
  position: absolute;
}

.app-hamburger::before {
  top: -7px;
}

.app-hamburger::after {
  top: 7px;
}

.app-sidebar-toggle[aria-expanded="true"] .app-hamburger {
  transform: rotate(45deg);
}

.app-sidebar-toggle[aria-expanded="true"] .app-hamburger::before {
  opacity: 0;
}

.app-sidebar-toggle[aria-expanded="true"] .app-hamburger::after {
  transform: translateY(-7px) rotate(-90deg);
}

.app-sidebar-nav {
  padding: 0.9rem 0.85rem 0.5rem;
}

.sidebar-group {
  color: rgba(255, 255, 255, 0.42);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  margin: 1.1rem 0.5rem 0.35rem;
  text-transform: uppercase;
}

.sidebar-group:first-child {
  margin-top: 0.15rem;
}

.sidebar-menu-button {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.86);
  display: flex;
  font-size: 0.9rem;
  font-weight: 700;
  gap: 0.65rem;
  justify-content: flex-start;
  margin-top: 0.15rem;
  min-height: 40px;
  padding: 0.55rem 0.65rem;
  width: 100%;
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-menu-button .nav-icon {
  flex: 0 0 auto;
  opacity: 0.8;
}

.sidebar-menu-button .nav-chevron {
  margin-left: auto;
  transition: transform 0.18s ease;
  opacity: 0.55;
}

.sidebar-menu-button:not(.collapsed) .nav-chevron {
  transform: rotate(90deg);
}

.sidebar-menu-button:hover,
.sidebar-menu-button:focus {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.sidebar-submenu {
  margin: 0.1rem 0 0.4rem;
  padding-left: 1.85rem;
  position: relative;
}

.sidebar-submenu::before {
  content: "";
  border-left: 1px solid rgba(255, 255, 255, 0.12);
  bottom: 0.4rem;
  left: 1.15rem;
  position: absolute;
  top: 0.15rem;
}

.sidebar-link {
  align-items: center;
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.62);
  display: flex;
  font-size: 0.87rem;
  font-weight: 600;
  margin: 0.1rem 0.35rem 0.1rem 0;
  min-height: 34px;
  padding: 0.4rem 0.6rem;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-link:hover,
.sidebar-link:focus {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.sidebar-link.active {
  background: var(--brand-600);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(27, 110, 194, 0.45);
}

.sidebar-link.top-level {
  font-weight: 700;
  margin: 0.15rem 0.15rem;
  padding: 0.55rem 0.65rem;
  gap: 0.65rem;
}

.theme-toggle-row {
  align-items: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.82);
  display: flex;
  font-weight: 600;
  font-size: 0.87rem;
  justify-content: space-between;
  margin-top: 1rem;
  padding: 0.6rem 0.7rem;
}

.theme-toggle {
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  height: 26px;
  padding: 2px;
  width: 48px;
  flex: 0 0 auto;
}

.theme-toggle span {
  background: #ffffff;
  border-radius: 50%;
  display: block;
  height: 20px;
  transition: transform 0.15s ease;
  width: 20px;
}

.theme-toggle[aria-pressed="true"] span {
  transform: translateX(22px);
}

.theme-toggle[aria-pressed="true"] {
  background: var(--brand-500);
  border-color: var(--brand-400);
}

.theme-toggle:hover {
  box-shadow: 0 0 0 0.2rem rgba(255, 255, 255, 0.14);
}

.app-sidebar-account {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  margin-top: 0.9rem;
  padding-top: 0.75rem;
}

.account-chip {
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  display: flex;
  gap: 0.6rem;
  padding: 0.55rem 0.6rem;
}

.account-avatar {
  align-items: center;
  background: linear-gradient(145deg, var(--brand-500), var(--brand-800));
  border-radius: 50%;
  color: #ffffff;
  display: flex;
  flex: 0 0 34px;
  font-size: 0.8rem;
  font-weight: 800;
  height: 34px;
  justify-content: center;
  width: 34px;
}

.account-meta {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
  flex: 1 1 auto;
}

.account-name {
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-role {
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.account-logout {
  align-items: center;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.72);
  display: inline-flex;
  flex: 0 0 auto;
  height: 30px;
  justify-content: center;
  width: 30px;
  transition: background 0.15s ease, color 0.15s ease;
}

.account-logout:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.app-sidebar-account .sidebar-link {
  margin: 0;
}

.app-content {
  min-height: 100vh;
}

.app-main {
  padding: 1.75rem 2rem 2rem;
}

.app-footer {
  border-top: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 1rem 2rem;
  font-size: 0.85rem;
}

@media (min-width: 992px) {
  .app-sidebar {
    bottom: 0;
    left: 0;
    overflow-y: auto;
    position: fixed;
    top: 0;
  }

  .app-sidebar-toggle {
    display: none;
  }

  .app-sidebar-nav {
    display: block !important;
  }

  .app-content {
    margin-left: var(--sidebar-width);
  }
}

@media (max-width: 991.98px) {
  .app-sidebar {
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    border-right: 0;
    position: sticky;
    top: 0;
    width: 100%;
  }

  .app-sidebar-nav {
    background: linear-gradient(185deg, var(--slate-950) 0%, #0d1730 55%, var(--brand-950) 130%);
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    bottom: 0;
    box-shadow: -18px 0 44px rgba(15, 23, 42, 0.24);
    display: block !important;
    max-height: none;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1rem;
    position: fixed;
    right: 0;
    top: 72px;
    transform: translateX(100%);
    transition: transform 0.22s ease, visibility 0.22s ease;
    visibility: hidden;
    width: min(86vw, 320px);
    z-index: 1040;
  }

  .app-sidebar-nav.show,
  .app-sidebar-nav.collapsing {
    height: calc(100dvh - 72px) !important;
    transform: translateX(0);
    visibility: visible;
  }

  .sidebar-backdrop {
    background: rgba(15, 23, 42, 0.42);
    bottom: 0;
    display: block;
    left: 0;
    opacity: 0;
    pointer-events: none;
    position: fixed;
    right: 0;
    top: 72px;
    transition: opacity 0.18s ease;
    z-index: 1030;
  }

  body.sidebar-drawer-open {
    overflow: hidden;
  }

  body.sidebar-drawer-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .app-main {
    padding: 1.1rem 1.1rem 1.5rem;
  }
}

@media (max-width: 575.98px) {
  .setup-action-grid {
    grid-template-columns: 1fr;
  }

  .app-main {
    padding: 0.85rem 0.85rem 1.25rem;
  }

  h1 {
    font-size: 1.5rem;
  }
}

/* =========================================================================
   Buttons
   ========================================================================= */
.btn {
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  letter-spacing: 0;
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-sm {
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  padding: 0.32rem 0.65rem;
}

.app-main .btn,
td .btn {
  margin: 2px 4px 2px 0;
}

.btn-primary {
  background: var(--brand-600);
  border-color: var(--brand-600);
  color: #fff;
}

.btn-primary:hover,
.btn-primary:focus {
  background: var(--brand-700);
  border-color: var(--brand-700);
  box-shadow: var(--shadow-sm);
}

.btn-outline-primary {
  border-color: var(--brand-300, var(--brand-400));
  color: var(--brand-700);
}

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

.btn-secondary {
  background: var(--slate-600);
  border-color: var(--slate-600);
}

.btn-secondary:hover {
  background: var(--slate-700);
  border-color: var(--slate-700);
}

.btn-outline-secondary {
  border-color: var(--slate-300);
  color: var(--slate-600);
}

.btn-outline-secondary:hover {
  background: var(--slate-600);
  border-color: var(--slate-600);
}

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

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

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

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

.btn-warning {
  background: var(--warning-600);
  border-color: var(--warning-600);
  color: #fff;
}

.btn-warning:hover {
  background: var(--warning-700);
  border-color: var(--warning-700);
  color: #fff;
}

.btn-info {
  background: var(--info-600);
  border-color: var(--info-600);
  color: #fff;
}

.btn-info:hover {
  background: var(--info-700);
  border-color: var(--info-700);
  color: #fff;
}

/* =========================================================================
   Badges & status pills
   ========================================================================= */
.badge {
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  padding: 0.4em 0.7em;
}

.badge.bg-primary { background: var(--brand-100) !important; color: var(--brand-700) !important; }
.badge.bg-secondary { background: var(--slate-100) !important; color: var(--slate-600) !important; }
.badge.bg-success { background: var(--success-100) !important; color: var(--success-700) !important; }
.badge.bg-danger { background: var(--danger-100) !important; color: var(--danger-700) !important; }
.badge.bg-warning { background: var(--warning-100) !important; color: var(--warning-700) !important; }
.badge.bg-info { background: var(--info-100) !important; color: var(--info-700) !important; }
.badge.bg-dark { background: var(--slate-800) !important; color: #fff !important; }

.status-pill {
  align-items: center;
  display: inline-flex;
  font-weight: 700;
  font-size: 0.85rem;
  gap: 0.45rem;
}

.status-dot {
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 auto;
  height: 0.5rem;
  width: 0.5rem;
}

.status-pill.success { color: var(--success-700); }
.status-pill.success .status-dot { background: var(--success-600); box-shadow: 0 0 0 3px var(--success-100); }
.status-pill.danger { color: var(--danger-700); }
.status-pill.danger .status-dot { background: var(--danger-600); box-shadow: 0 0 0 3px var(--danger-100); }
.status-pill.warning { color: var(--warning-700); }
.status-pill.warning .status-dot { background: var(--warning-600); box-shadow: 0 0 0 3px var(--warning-100); }

/* =========================================================================
   Forms
   ========================================================================= */
.form-label {
  color: var(--slate-700);
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.form-control,
.form-select {
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-md);
  color: var(--text-body);
  padding: 0.55rem 0.85rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--brand-500);
}

.form-check-input:checked {
  background-color: var(--brand-600);
  border-color: var(--brand-600);
}

.form-floating > .form-control-plaintext::placeholder,
.form-floating > .form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder,
.form-floating > .form-control:focus::placeholder {
  text-align: start;
}

/* =========================================================================
   Cards
   ========================================================================= */
.card {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* =========================================================================
   Alerts
   ========================================================================= */
.alert {
  border-radius: var(--radius-md);
  border-width: 1px;
  border-left-width: 4px;
  font-weight: 600;
  padding: 0.85rem 1.1rem;
}

.alert-info {
  background: var(--brand-50);
  border-color: var(--brand-200);
  color: var(--brand-800);
}

.alert-success {
  background: var(--success-100);
  border-color: #86efac;
  color: var(--success-700);
}

.alert-warning {
  background: var(--warning-100);
  border-color: #fcd34d;
  color: var(--warning-700);
}

.alert-danger {
  background: var(--danger-100);
  border-color: #fca5a5;
  color: var(--danger-700);
}

/* =========================================================================
   Tables
   ========================================================================= */
table.table {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-collapse: separate;
  border-spacing: 0;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
  width: 100%;
}

table.table thead th {
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.85rem 1rem;
  position: sticky;
  text-transform: uppercase;
  top: 0;
  white-space: nowrap;
  z-index: 2;
}

table.table.table-sm thead th {
  padding: 0.6rem 0.65rem;
}

table.table.table-sm tbody td {
  padding: 0.45rem 0.65rem;
}

table.table tbody td {
  background-color: var(--surface);
  border-bottom: 1px solid var(--slate-100);
  color: var(--text-body);
  padding: 0.75rem 1rem;
  vertical-align: middle;
}

[data-theme="dark"] table.table tbody td {
  border-bottom-color: var(--border-subtle);
}

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

table.table tbody tr:hover td {
  background: var(--brand-50);
}

/* Keep the rightmost column (almost always row actions) reachable without
   having to scroll a wide table all the way across on every row. Skipped on
   narrow screens, where the action group is usually wider than the viewport
   itself and pinning it would cover the whole table. */
@media (min-width: 768px) {
  table.table thead th:last-child,
  table.table tbody td:last-child {
    position: sticky;
    right: 0;
    z-index: 3;
    box-shadow: -8px 0 8px -8px rgba(15, 23, 42, 0.12);
  }

  table.table thead th:last-child {
    background-color: var(--surface-muted);
  }

  table.table tbody td:last-child {
    background-color: var(--surface);
  }
}

table.table thead tr:first-child th:first-child { border-top-left-radius: var(--radius-lg); }
table.table thead tr:first-child th:last-child { border-top-right-radius: var(--radius-lg); }
table.table tbody tr:last-child td:first-child { border-bottom-left-radius: var(--radius-lg); }
table.table tbody tr:last-child td:last-child { border-bottom-right-radius: var(--radius-lg); }

table.table tr.table-secondary th,
table.table tr.table-secondary td {
  background: var(--surface-muted) !important;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

table.table {
  display: block;
  max-height: 65vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  white-space: nowrap;
}

/* =========================================================================
   Reusable page-header / table-card components
   ========================================================================= */
.page-header {
  align-items: flex-end;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  margin-bottom: 1.4rem;
}

.page-header h1 {
  margin-bottom: 0.3rem;
}

.page-header-subtitle {
  color: var(--text-muted);
  margin: 0;
  max-width: 640px;
}

.page-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.1rem;
}

.filter-pills .btn {
  border-radius: 999px;
  margin: 0;
}

.table-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.table-card-header {
  align-items: center;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: space-between;
  padding: 1rem 1.25rem;
}

.table-card-header h2 {
  color: var(--text-heading);
  font-size: 1rem;
  font-weight: 800;
  margin: 0;
}

.table-card table.table {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  margin-bottom: 0;
}

.table-card table.table thead tr:first-child th:first-child,
.table-card table.table thead tr:first-child th:last-child,
.table-card table.table tbody tr:last-child td:first-child,
.table-card table.table tbody tr:last-child td:last-child {
  border-radius: 0;
}

.table-card .table-empty {
  color: var(--text-muted);
  font-weight: 600;
  padding: 2.5rem 1.25rem;
  text-align: center;
}

/* =========================================================================
   Dashboard
   ========================================================================= */
.eyebrow {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-bottom: 0.35rem;
  text-transform: uppercase;
}

.dashboard-header {
  align-items: flex-end;
  background: linear-gradient(135deg, var(--brand-900), var(--brand-600) 60%, var(--brand-400));
  border: 1px solid var(--brand-700);
  border-radius: var(--radius-lg);
  color: #ffffff;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin-bottom: 1.4rem;
  padding: 1.5rem 1.75rem;
  box-shadow: var(--shadow-md);
}

.dashboard-header h1 {
  color: #ffffff;
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 0.35rem;
}

.dashboard-header .eyebrow,
.dashboard-subtitle {
  color: rgba(255, 255, 255, 0.86);
}

.dashboard-header .btn-primary {
  background: #ffffff;
  border-color: #ffffff;
  color: var(--brand-800);
}

.dashboard-header .btn-primary:hover {
  background: var(--brand-50);
}

.dashboard-header .btn-outline-primary {
  border-color: rgba(255, 255, 255, 0.72);
  color: #ffffff;
}

.dashboard-header .btn-outline-primary:hover {
  background: #ffffff;
  color: var(--brand-800);
}

.dashboard-subtitle {
  margin: 0;
  max-width: 720px;
}

.dashboard-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.dashboard-kpis {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 1rem;
}

.setup-dashboard,
.setup-shell {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1rem;
  padding: 1.25rem;
}

.setup-dashboard {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
}

.setup-dashboard h2,
.setup-panel h1,
.setup-checklist h2 {
  color: var(--brand-800);
  font-weight: 800;
}

.setup-copy {
  color: var(--text-muted);
}

.setup-action-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.setup-action-card {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-body);
  display: flex;
  flex-direction: column;
  min-height: 96px;
  padding: 0.9rem 1rem;
  text-decoration: none;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.setup-action-card:hover,
.setup-action-card:focus {
  border-color: var(--brand-500);
  color: var(--text-body);
  transform: translateY(-1px);
}

.setup-action-card.complete {
  background: var(--success-100);
  border-color: #86efac;
}

.setup-action-card strong {
  color: var(--brand-800);
}

.setup-action-card span,
.setup-checklist li {
  color: var(--text-muted);
}

.setup-shell {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: minmax(0, 1fr) 320px;
}

.setup-checklist {
  border-left: 1px solid var(--border-subtle);
  padding-left: 1.25rem;
}

.setup-checklist ol {
  display: grid;
  gap: 0.75rem;
  margin: 0;
  padding-left: 1.25rem;
}

.setup-checklist li.done {
  color: var(--success-700);
  font-weight: 700;
}

.setup-checklist li.active {
  color: var(--brand-800);
  font-weight: 800;
}

.organization-logo-preview {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  height: 72px;
  object-fit: contain;
  padding: 0.35rem;
  width: 72px;
}

.dashboard-kpis-compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  color: var(--text-body);
  display: flex;
  flex-direction: column;
  min-height: 138px;
  padding: 1.1rem;
  text-decoration: none;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.metric-card:hover,
.metric-card:focus {
  border-color: var(--brand-500);
  box-shadow: var(--shadow-md);
  color: var(--text-body);
  transform: translateY(-3px);
}

.metric-card strong {
  color: var(--brand-800);
  font-size: clamp(1.45rem, 2vw, 2.25rem);
  line-height: 1.1;
  margin: 0.4rem 0;
  overflow-wrap: anywhere;
}

.metric-label,
.metric-note {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.metric-card-warning {
  border-color: var(--warning-600);
  background: linear-gradient(180deg, var(--warning-100), #fffaf0);
}

[data-theme="dark"] .metric-card-warning {
  background: linear-gradient(180deg, #3a2a10, var(--surface));
}

.dashboard-grid {
  display: grid;
  gap: 1.1rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.dashboard-panel {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.1rem;
}

.dashboard-panel h2 {
  color: var(--brand-800);
  font-size: 1.1rem;
  font-weight: 800;
  margin: 0;
}

.dashboard-panel-wide {
  grid-column: span 2;
}

.panel-heading {
  align-items: flex-start;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.panel-chip {
  background: var(--brand-100);
  border-radius: 999px;
  color: var(--brand-700);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.35rem 0.65rem;
  white-space: nowrap;
}

.chart-frame {
  height: 320px;
  position: relative;
}

.chart-frame-compact {
  height: 260px;
}

.cashflow-chart {
  align-items: end;
  border-bottom: 1px solid var(--border-subtle);
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  height: 300px;
  padding: 0.5rem 0.25rem 0;
}

.cashflow-month {
  align-items: center;
  display: grid;
  gap: 0.45rem;
  grid-template-rows: 1fr auto;
  height: 100%;
  min-width: 0;
}

.cashflow-bars {
  align-items: end;
  display: flex;
  gap: 0.25rem;
  height: 100%;
  justify-content: center;
  min-height: 220px;
}

.cashflow-bar {
  border-radius: 6px 6px 0 0;
  display: block;
  min-height: 4px;
  width: 18px;
  transition: opacity 0.15s ease;
}

.cashflow-bar:hover {
  opacity: 0.8;
}

.cashflow-bar.invoicing,
.legend-dot.invoicing {
  background: var(--brand-600);
}

.cashflow-bar.collections,
.legend-dot.collections {
  background: var(--success-600);
}

.cashflow-bar.expenses,
.legend-dot.expenses {
  background: var(--warning-600);
}

.cashflow-label {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
}

.cashflow-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  margin-top: 0.8rem;
}

.cashflow-legend span {
  align-items: center;
  color: var(--text-muted);
  display: inline-flex;
  font-size: 0.85rem;
  gap: 0.35rem;
}

.legend-dot {
  border-radius: 50%;
  display: inline-block;
  height: 0.65rem;
  width: 0.65rem;
}

.dashboard-empty-state {
  align-items: center;
  color: var(--text-muted);
  display: flex;
  font-weight: 700;
  grid-column: 1 / -1;
  justify-content: center;
  min-height: 220px;
}

.occupancy-panel {
  display: flex;
  flex-direction: column;
}

.occupancy-meter {
  background: var(--brand-50);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  height: 16px;
  overflow: hidden;
}

.occupancy-meter span {
  background: linear-gradient(90deg, var(--brand-800), var(--brand-500));
  display: block;
  height: 100%;
}

.occupancy-list,
.receivables-list {
  display: grid;
  gap: 0.65rem;
  margin: 1rem 0;
}

.occupancy-list div,
.receivables-list div {
  align-items: center;
  border-bottom: 1px solid var(--slate-100);
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  padding-bottom: 0.65rem;
}

[data-theme="dark"] .occupancy-list div,
[data-theme="dark"] .receivables-list div {
  border-bottom-color: var(--border-subtle);
}

.occupancy-list dt,
.receivables-list dt {
  color: var(--text-muted);
  font-weight: 600;
}

.occupancy-list dd,
.receivables-list dd {
  color: var(--text-heading);
  font-weight: 800;
  margin: 0;
  text-align: right;
}

.receivables-list .receivables-total {
  background: var(--brand-100);
  border: 0;
  border-radius: var(--radius-md);
  padding: 0.85rem;
}

.finance-list {
  display: grid;
  gap: 0.65rem;
  margin: 1rem 0;
}

.finance-list div {
  align-items: center;
  border-bottom: 1px solid var(--slate-100);
  display: flex;
  justify-content: space-between;
  padding-bottom: 0.65rem;
}

[data-theme="dark"] .finance-list div {
  border-bottom-color: var(--border-subtle);
}

.finance-list dt {
  color: var(--text-muted);
  font-weight: 600;
}

.finance-list dd {
  color: var(--text-heading);
  font-weight: 800;
  margin: 0;
  text-align: right;
}

.collection-meter-label {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.collection-meter-label span {
  color: var(--text-muted);
}

.progress {
  background: var(--brand-50);
  border-radius: 999px;
}

[data-theme="dark"] .progress {
  background: var(--surface-muted);
}

.progress-bar {
  background: linear-gradient(90deg, var(--brand-800), var(--brand-500));
}

.balance-highlight {
  background: var(--brand-100);
  border-radius: var(--radius-md);
  margin: 1rem 0;
  padding: 1rem;
}

.balance-highlight.muted {
  background: var(--surface-muted);
}

.balance-highlight span {
  color: var(--text-muted);
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.balance-highlight strong {
  color: var(--text-heading);
  display: block;
  font-size: 1.35rem;
}

/* =========================================================================
   Login
   ========================================================================= */
.login-page {
  background: var(--slate-950);
  min-height: 100vh;
}

.login-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(420px, 0.85fr);
  min-height: 100vh;
}

.login-visual {
  min-height: 100vh;
  overflow: hidden;
  position: relative;
}

.login-visual-image {
  height: 100%;
  inset: 0;
  object-fit: cover;
  position: absolute;
  width: 100%;
}

.login-visual::after {
  background: linear-gradient(100deg, rgba(7, 12, 24, 0.92), rgba(11, 44, 92, 0.55) 60%, rgba(27, 110, 194, 0.35));
  content: "";
  inset: 0;
  position: absolute;
}

.login-visual-overlay {
  bottom: 8%;
  color: #ffffff;
  left: 7%;
  max-width: 560px;
  position: absolute;
  right: 7%;
  z-index: 1;
}

.login-brand-lockup {
  align-items: center;
  display: flex;
  font-weight: 800;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.login-brand-logo {
  background: #ffffff;
  border-radius: var(--radius-md);
  height: 48px;
  object-fit: contain;
  padding: 0.3rem;
  width: 48px;
}

.login-visual-overlay h1 {
  color: #ffffff;
  font-size: 2.9rem;
  font-weight: 800;
  line-height: 1.08;
  margin-bottom: 1rem;
}

.login-visual-overlay p {
  color: rgba(255, 255, 255, 0.84);
  font-size: 1.08rem;
  margin: 0;
}

.login-panel {
  align-items: center;
  background: var(--surface-muted);
  display: flex;
  justify-content: center;
  padding: 2rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 440px;
  padding: 2.25rem;
  width: 100%;
}

.login-card-header {
  margin-bottom: 1.5rem;
}

.login-card-header h2 {
  color: var(--text-heading);
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 0.4rem;
}

.login-card-header p:last-child {
  color: var(--text-muted);
  margin: 0;
}

.login-submit {
  min-height: 48px;
  width: 100%;
}

.login-options {
  align-items: center;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
  margin-top: 1rem;
}

.login-options a {
  font-weight: 700;
  text-decoration: none;
}

.report-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

/* =========================================================================
   Dark mode overrides for standard bootstrap chrome
   ========================================================================= */
[data-theme="dark"] body {
  background: var(--page-bg);
  color: var(--text-body);
}

[data-theme="dark"] .app-content,
[data-theme="dark"] .app-main {
  background: var(--page-bg);
}

[data-theme="dark"] .dashboard-panel,
[data-theme="dark"] .metric-card,
[data-theme="dark"] .login-card,
[data-theme="dark"] .card,
[data-theme="dark"] .table,
[data-theme="dark"] .table-card,
[data-theme="dark"] .setup-dashboard,
[data-theme="dark"] .setup-shell {
  background: var(--surface);
  border-color: var(--border-subtle);
  color: var(--text-body);
}

[data-theme="dark"] table.table thead th,
[data-theme="dark"] .table-card-header {
  background: var(--surface-muted);
}

[data-theme="dark"] table.table tbody tr:hover td {
  background: var(--surface-muted);
}

[data-theme="dark"] .dashboard-panel h2,
[data-theme="dark"] .metric-card strong,
[data-theme="dark"] .finance-list dd,
[data-theme="dark"] .occupancy-list dd,
[data-theme="dark"] .receivables-list dd,
[data-theme="dark"] .balance-highlight strong,
[data-theme="dark"] h1,
[data-theme="dark"] h2,
[data-theme="dark"] h3,
[data-theme="dark"] h4,
[data-theme="dark"] h5 {
  color: var(--text-heading);
}

[data-theme="dark"] .metric-label,
[data-theme="dark"] .metric-note,
[data-theme="dark"] .dashboard-subtitle,
[data-theme="dark"] .finance-list dt,
[data-theme="dark"] .occupancy-list dt,
[data-theme="dark"] .receivables-list dt,
[data-theme="dark"] .cashflow-label,
[data-theme="dark"] .cashflow-legend span,
[data-theme="dark"] .login-card-header p:last-child,
[data-theme="dark"] .text-muted {
  color: var(--text-muted) !important;
}

[data-theme="dark"] .cashflow-chart {
  border-color: var(--border-subtle);
}

[data-theme="dark"] .occupancy-meter {
  background: var(--surface-muted);
  border-color: var(--border-subtle);
}

[data-theme="dark"] .receivables-list .receivables-total {
  background: var(--surface-muted);
}

[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select {
  background: var(--surface-muted);
  border-color: var(--border-subtle);
  color: var(--text-heading);
}

[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus {
  background: var(--surface-muted);
  color: var(--text-heading);
}

[data-theme="dark"] .app-footer {
  border-color: var(--border-subtle);
}

[data-theme="dark"] .badge.bg-secondary {
  background: var(--surface-muted) !important;
  color: var(--text-muted) !important;
}

/* =========================================================================
   Responsive overrides
   ========================================================================= */
@media (max-width: 1199.98px) {
  .dashboard-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 991.98px) {
  .dashboard-header {
    align-items: stretch;
    flex-direction: column;
  }

  .dashboard-header-actions {
    width: 100%;
  }

  .dashboard-header-actions .btn {
    flex: 1 1 180px;
  }

  .dashboard-grid,
  .dashboard-kpis {
    grid-template-columns: 1fr;
  }

  .dashboard-panel-wide {
    grid-column: auto;
  }

  .cashflow-chart {
    gap: 0.45rem;
  }

  .cashflow-bar {
    width: 13px;
  }

  .login-shell {
    grid-template-columns: 1fr;
  }

  .login-visual {
    min-height: 320px;
  }

  .login-visual-overlay h1 {
    font-size: 2.1rem;
  }

  .login-panel {
    padding: 1rem;
  }

  .page-header {
    align-items: stretch;
    flex-direction: column;
  }

  .page-header-actions {
    width: 100%;
  }

  .page-header-actions .btn {
    flex: 1 1 160px;
  }

  .setup-dashboard,
  .setup-shell {
    grid-template-columns: 1fr;
  }

  .setup-checklist {
    border-left: 0;
    border-top: 1px solid var(--border-subtle);
    padding-left: 0;
    padding-top: 1rem;
  }
}

@media (max-width: 575.98px) {
  .login-card {
    padding: 1.5rem;
  }

  .login-visual-overlay h1 {
    font-size: 1.7rem;
  }

  .metric-card {
    min-height: auto;
  }

  .table-card-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
