:root {
  --bg: #F3F0E7;
  --surface: #FFFFFF;
  --surface-2: #FAF8F2;
  --border: #E7E1CF;
  --navy-900: #12192B;
  --navy-800: #1B2740;
  --navy-700: #25355A;
  --navy-600: #334876;
  --ink-900: #1B2333;
  --ink-700: #3D4659;
  --ink-600: #5B6478;
  --ink-400: #8B92A6;
  --gold-500: #C79A3E;
  --gold-400: #DAB35F;
  --gold-100: #F4E8CA;
  --green-600: #3C6E52;
  --green-100: #DEEAE1;
  --red-500: #B5544A;
  --red-100: #F3DEDB;
  --radius: 14px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink-900);
  min-height: 100vh;
}

::selection { background: var(--gold-100); }

/* ---------- App shell ---------- */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-shell.authenticated {
  flex-direction: row;
}

.app-sidebar {
  width: 264px;
  flex: 0 0 264px;
  background: linear-gradient(180deg, var(--navy-900) 0%, #101725 100%);
  color: #C9CEDB;
  display: flex;
  flex-direction: column;
  padding: 26px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.app-main {
  flex: 1;
  min-width: 0;
  padding: 34px 40px 80px 40px;
  background: var(--bg);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 10px 22px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 18px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--gold-400), var(--gold-500));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Source Serif 4', serif;
  font-weight: 700;
  color: var(--navy-900);
  font-size: 17px;
  flex-shrink: 0;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  display: block;
}

.brand-text .name {
  font-family: 'Source Serif 4', serif;
  font-size: 16.5px;
  color: #fff;
  font-weight: 600;
  line-height: 1.15;
}

.brand-text .sub {
  font-size: 10.5px;
  letter-spacing: .09em;
  color: #8590AA;
  text-transform: uppercase;
  margin-top: 2px;
}

.nav-section-label {
  font-size: 10.5px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: #5E6A87;
  font-weight: 600;
  padding: 16px 12px 6px 12px;
}

.nav-section-label:first-of-type { padding-top: 4px; }

.app-nav .nav-link-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 9px;
  font-size: 13.5px;
  color: #AEB6CC !important;
  cursor: pointer;
  border-left: 3px solid transparent;
  margin-bottom: 2px;
  transition: background .12s ease, color .12s ease;
  text-decoration: none !important;
  line-height: 1.3;
  height: auto;
}

.app-nav .nav-link-item i,
.app-nav .nav-link-item .nav-ico {
  flex-shrink: 0;
  opacity: .85;
  width: 17px;
  text-align: center;
  font-size: 14px;
}

.app-nav .nav-link-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #E7E9F2 !important;
}

.app-nav .nav-link-item.active {
  background: var(--navy-700) !important;
  color: #fff !important;
  border-left: 3px solid var(--gold-500);
  font-weight: 600;
}

.app-nav .nav-link-item.active i {
  opacity: 1;
  color: var(--gold-400);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 6px;
}

.sidebar-footer .logout-btn {
  margin-left: auto;
  background: transparent;
  border: none;
  color: #7C86A0;
  cursor: pointer;
  padding: 6px;
  font-size: 14px;
}

.sidebar-footer .logout-btn:hover { color: #fff; }

.avatar-chip {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--gold-100);
  color: var(--gold-500);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12.5px;
  font-family: 'Source Serif 4', serif;
  flex-shrink: 0;
}

.sidebar-footer .who { font-size: 13px; color: #fff; font-weight: 600; }
.sidebar-footer .role { font-size: 11px; color: #7C86A0; }

.navbar-toggler-sl {
  display: none;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: #fff;
  padding: 6px 10px;
  margin-left: auto;
}

/* ---------- Page chrome ---------- */
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 26px;
  flex-wrap: wrap;
  gap: 14px;
}

.eyebrow {
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--gold-500);
  font-weight: 700;
  margin-bottom: 6px;
}

.page-title {
  font-family: 'Source Serif 4', serif;
  font-size: 30px;
  font-weight: 600;
  color: var(--ink-900);
  letter-spacing: -.01em;
  margin: 0;
}

.page-sub {
  font-size: 13.5px;
  color: var(--ink-600);
  margin-top: 4px;
}

.btn-sl {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 16px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  font-family: 'Inter', sans-serif;
  white-space: nowrap;
  text-decoration: none;
}

.btn-gold { background: var(--gold-500); color: var(--navy-900); }
.btn-gold:hover { background: var(--gold-400); color: var(--navy-900); }
.btn-navy { background: var(--navy-900); color: #fff; }
.btn-navy:hover { background: var(--navy-800); color: #fff; }
.btn-outline-sl {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink-900);
}
.btn-outline-sl:hover { border-color: var(--gold-500); }
.btn-ghost-sl { background: transparent; color: var(--ink-600); }
.btn-sm-sl { padding: 7px 12px; font-size: 12px; }

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-58 { display: grid; grid-template-columns: 1.5fr 2.5fr; gap: 18px; }
.grid-form3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.grid-form2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }

@media (max-width: 1100px) {
  .grid-3, .grid-4, .grid-2, .grid-58, .grid-form3, .grid-form2 { grid-template-columns: 1fr; }
}

.sl-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 18px;
}

.sl-card:last-child { margin-bottom: 0; }

.card-title {
  font-family: 'Source Serif 4', serif;
  font-size: 17px;
  font-weight: 600;
  color: var(--ink-900);
}

.card-sub {
  font-size: 12.5px;
  color: var(--ink-400);
  margin-top: 3px;
  margin-bottom: 18px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
}

.stat-tile .label {
  font-size: 10.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-400);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-tile .label i { color: var(--gold-500); }

.stat-tile .value {
  font-family: 'Source Serif 4', serif;
  font-size: 34px;
  font-weight: 600;
  color: var(--ink-900);
  margin-top: 10px;
}

.stat-tile .delta {
  font-size: 11.5px;
  color: var(--green-600);
  margin-top: 6px;
  font-weight: 600;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-600);
}

.field input,
.field select,
.field textarea {
  font-family: 'Inter', sans-serif;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13.5px;
  color: var(--ink-900);
  outline: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--gold-500);
  background: #fff;
}

.field-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-700);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 11px;
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 0;
}

.table-wrap thead th {
  text-align: left;
  font-size: 10.5px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-400);
  font-weight: 700;
  padding: 12px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table-wrap tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--ink-900);
  white-space: nowrap;
}

.table-wrap tbody tr:last-child td { border-bottom: none; }
.table-wrap tbody tr:hover { background: var(--surface-2); }

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  color: var(--ink-600);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
}

.pill-active { background: var(--green-100); color: var(--green-600); }
.pill-inactive { background: var(--red-100); color: var(--red-500); }
.pill-gold { background: var(--gold-100); color: #93701F; }

.badge-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--gold-100);
  color: #93701F;
  font-size: 11px;
  font-weight: 700;
}

.firm-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 520px;
  overflow-y: auto;
}

.firm-list li,
.firm-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 12px;
  border-radius: 9px;
  font-size: 13.5px;
  color: var(--ink-700);
  cursor: pointer;
  margin-bottom: 2px;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.firm-list li:hover,
.firm-list-item:hover { background: var(--surface-2); }

.firm-list li.active,
.firm-list-item.active {
  background: var(--navy-900);
  color: #fff;
}

.firm-list li.active .badge-count,
.firm-list-item.active .badge-count {
  background: var(--gold-500);
  color: var(--navy-900);
}

.search-input {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 12px;
  background: var(--surface-2);
  width: 220px;
}

.search-input input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 13px;
  width: 100%;
  color: var(--ink-900);
}

.tabbar {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 22px;
}

.tab-sl {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-400);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}

.tab-sl.active {
  color: var(--ink-900);
  border-bottom: 2px solid var(--gold-500);
}

.toggle-sl {
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  border: none;
  padding: 0;
}

.toggle-sl.on { background: var(--gold-500); }

.toggle-sl::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  top: 3px;
  left: 3px;
  transition: left .15s ease;
}

.toggle-sl.on::after { left: 19px; }

.chip {
  display: inline-flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink-700);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  margin: 3px 4px 0 0;
}

.footnote {
  font-size: 11.5px;
  color: var(--ink-400);
  margin-top: 14px;
}

.donut-wrap {
  display: flex;
  align-items: center;
  gap: 26px;
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
  flex: 1;
}

.legend .row {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink-700);
}

.legend .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend .num {
  margin-left: auto;
  font-weight: 700;
  color: var(--ink-900);
  padding-left: 20px;
}

.bars {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  height: 130px;
  padding-top: 10px;
}

.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.bar {
  width: 100%;
  max-width: 26px;
  border-radius: 5px 5px 2px 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.bar.filled {
  background: var(--navy-700);
  border-color: var(--navy-700);
}

.bar-label {
  font-size: 11px;
  color: var(--ink-400);
  font-weight: 600;
}

.split {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 18px;
}

/* User Management: narrow user list, wide edit form */
.split-user-mgmt {
  grid-template-columns: minmax(200px, 0.72fr) minmax(0, 2.28fr);
  align-items: start;
}

@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
  .split-user-mgmt { grid-template-columns: 1fr; }
}

.log-entry {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 10px;
}

.log-entry .ts {
  font-size: 11.5px;
  color: var(--ink-400);
  font-weight: 700;
  margin-bottom: 6px;
}

.action-row {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 18px;
  flex-wrap: wrap;
}

.filter-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.filter-row .field {
  margin-bottom: 0;
}

/* Firm Management toolbar: dropdown + actions aligned */
.firm-toolbar {
  gap: 12px;
  align-items: flex-end;
}

.firm-toolbar-field {
  flex: 1 1 280px;
  max-width: 340px;
  min-width: 220px;
  margin-bottom: 0;
}

.firm-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  padding-bottom: 0;
}

.firm-toolbar-btn.e-btn,
.firm-toolbar .e-btn.firm-toolbar-btn {
  height: 38px !important;
  min-height: 38px !important;
  padding: 0 16px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  margin: 0 !important;
  line-height: 1 !important;
  box-sizing: border-box !important;
}

.firm-toolbar .e-ddl.e-input-group,
.firm-toolbar .e-input-group.e-control-wrapper,
.firm-toolbar .e-ddl {
  height: 38px !important;
  min-height: 38px !important;
  margin: 0 !important;
}

.firm-toolbar .e-input-group input.e-input,
.firm-toolbar .e-ddl .e-input {
  height: 36px !important;
  min-height: 36px !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}

.firm-toolbar-card {
  margin-bottom: 18px;
  padding: 20px 24px;
}

/* Nested cards inside Firm tabs */
.SlRetabviewdesign1 > .e-tab,
.sl-card.SlRetabviewdesign1 {
  padding-bottom: 8px;
}

.sl-card .sl-card {
  margin-bottom: 16px;
  padding: 20px 22px;
}

.sl-card .sl-card:last-child {
  margin-bottom: 0;
}

.sl-card .card-title {
  margin-bottom: 14px;
}

/* Consistent Bootstrap form rows inside firm cards */
.sl-card .row {
  --bs-gutter-x: 1rem;
  --bs-gutter-y: 0.75rem;
}

.sl-card .form-group {
  margin-bottom: 12px;
}

.sl-card .form-group label,
.sl-card label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-600);
}

.sl-card .e-input-group,
.sl-card .e-control-wrapper.e-input-group,
.sl-card .e-numeric {
  width: 100%;
}

.sl-card .checkbox,
.sl-card .e-checkbox-wrapper {
  margin-bottom: 4px;
}

.firm-save-row {
  margin-top: 28px;
  margin-bottom: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  gap: 12px;
}

.firm-save-row .e-btn {
  min-width: 120px;
  height: 40px !important;
  padding: 0 22px !important;
}

/* Login */
.login-panel {
  max-width: 420px;
  margin: 60px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: 0 12px 40px rgba(18, 25, 43, 0.08);
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.login-logo {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.login-brand-sub {
  font-size: 10.5px;
  letter-spacing: .09em;
  color: var(--ink-400);
  text-transform: uppercase;
  font-weight: 600;
}

.login-panel h3 {
  font-family: 'Source Serif 4', serif;
  font-weight: 600;
  color: var(--ink-900);
  text-align: center;
  margin-bottom: 24px;
}

.login-panel .form-control {
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 10px 12px;
  font-size: 13.5px;
}

.login-panel .form-control:focus {
  border-color: var(--gold-500);
  background: #fff;
  box-shadow: none;
}

.btn-login:disabled {
  opacity: 0.75;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(18, 25, 43, 0.25);
  border-top-color: var(--navy-900);
  border-radius: 50%;
  animation: btn-spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

/* Desktop: always show nav */
@media (min-width: 641px) {
  .app-sidebar .nav-collapse { display: block !important; }
  .navbar-toggler-sl { display: none !important; }
}

@media (max-width: 640.98px) {
  .app-shell.authenticated { flex-direction: column; }

  .app-sidebar {
    width: 100%;
    flex: none;
    height: auto;
    max-height: none;
    position: relative;
    padding: 16px;
  }

  .app-sidebar .nav-collapse:not(.show) { display: none; }
  .app-sidebar .nav-collapse.show { display: block; margin-bottom: 12px; }

  .navbar-toggler-sl { display: inline-flex; align-items: center; }

  .brand { margin-bottom: 8px; padding-bottom: 14px; flex-wrap: wrap; }

  .app-main { padding: 20px 16px 40px; }

  .page-title { font-size: 24px; }

  .sidebar-footer { margin-top: 12px; }
}

/* Bootstrap .card inside pages should not fight sl-card */
.app-main .card.card-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.app-main .form-group label,
.app-main label.lh-base {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-600);
}

/* Prevent Bootstrap containers from fighting cream canvas */
.app-main .container-fluid {
  padding-left: 0;
  padding-right: 0;
}

.app-main .content.text-sm {
  padding-top: 0;
}

/* Active NavLink from Blazor uses .active */
a.nav-link-item.active {
  background: var(--navy-700) !important;
  color: #fff !important;
  border-left: 3px solid var(--gold-500);
  font-weight: 600;
}

/* App-wide toast feedback (Save / validation messages) */
.app-toast,
.firm-toast {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 10000;
  min-width: 280px;
  max-width: 420px;
  padding: 14px 18px;
  border-radius: 10px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(18, 25, 43, 0.18);
  animation: app-toast-in 0.25s ease-out;
}
.app-toast-success,
.firm-toast-success {
  background: var(--green-100);
  color: var(--green-600);
  border: 1px solid var(--green-600);
}
.app-toast-warning,
.firm-toast-warning {
  background: var(--red-100);
  color: var(--red-500);
  border: 1px solid var(--red-500);
}
@keyframes app-toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes firm-toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
