/* ============================================================
   LegalSuite Portal — Premium Design System
   Clean · Calm · Professional · Luxury
   ============================================================ */

/* ── Google Fonts ──────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Playfair+Display:wght@600;700&display=swap');

/* ── CSS Custom Properties (Light Theme) ──────────────────── */
:root {
  /* Surfaces (Warm Sage) */
  --bg:           #F4F3EE;
  --bg-2:         #E8E6E1;
  --bg-3:         #E1DED6;
  --bg-4:         #D6D2C4;

  /* Text */
  --text:         #111111;
  --text-2:       #1A1A1A;
  --text-3:       #5A5A5A;
  --text-4:       #8A8A8A;

  /* Brand (black) */
  --primary:      #000000;
  --primary-h:    #1A1A1A;
  --primary-a:    #E8E8E6;
  --primary-b:    #C9C9C9;

  /* Accent (gold) */
  --accent:       #92400E;
  --accent-h:     #78350F;
  --accent-a:     #F3EAD3;

  /* Status */
  --success:      #059669;
  --success-a:    #D9EEDD;
  --danger:       #DC2626;
  --danger-a:     #F6E1DC;
  --warning:      #D97706;
  --warning-a:    #F3EAD3;
  --info:         #2563EB;
  --info-a:       #E0E6EA;

  /* Borders */
  --border:       #D6D2C4;
  --border-2:     #C6C1B0;
  --border-focus: #000000;

  /* Fonts */
  --font-serif:   Georgia, 'Times New Roman', 'Playfair Display', serif;

  /* Shadows */
  --shadow-sm:    0 1px 2px 0 rgb(0 0 0 / .05);
  --shadow:       0 1px 3px 0 rgb(0 0 0 / .1), 0 1px 2px -1px rgb(0 0 0 / .1);
  --shadow-md:    0 4px 6px -1px rgb(0 0 0 / .1), 0 2px 4px -2px rgb(0 0 0 / .1);
  --shadow-lg:    0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);
  --shadow-xl:    0 20px 25px -5px rgb(0 0 0 / .1), 0 8px 10px -6px rgb(0 0 0 / .1);
  --shadow-2xl:   0 25px 50px -12px rgb(0 0 0 / .25);

  /* Layout */
  --sidebar-w:    256px;
  --navbar-h:     60px;
  --radius:       8px;
  --radius-lg:    12px;
  --radius-xl:    16px;
  --radius-2xl:   20px;

  /* Motion */
  --ease:         cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out:     cubic-bezier(0, 0, 0.2, 1);
  --ease-in:      cubic-bezier(0.4, 0, 1, 1);
  --dur-fast:     150ms;
  --dur:          200ms;
  --dur-slow:     300ms;
}

/* ── Dark Theme ────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:           #161616;
  --bg-2:         #0D0D0D;
  --bg-3:         #1F1F1F;
  --bg-4:         #2A2A2A;

  --text:         #F2F2F2;
  --text-2:       #DEDEDE;
  --text-3:       #A6A6A6;
  --text-4:       #7A7A7A;

  --primary:      #CCCCCC;
  --primary-h:    #E2E2E2;
  --primary-a:    #232323;
  --primary-b:    #3A3A3A;

  --accent:       #E4C980;
  --accent-h:     #D9B45E;
  --accent-a:     #33301F;

  --success:      #34D399;
  --success-a:    #12362A;
  --danger:       #F87171;
  --danger-a:     #452020;
  --warning:      #FCD34D;
  --warning-a:    #33301F;
  --info:         #93B5E8;
  --info-a:       #263041;

  --border:       #3A3A3A;
  --border-2:     #4A4A4A;
  --border-focus: #CCCCCC;

  --shadow-sm:    0 1px 2px 0 rgb(0 0 0 / .3);
  --shadow:       0 1px 3px 0 rgb(0 0 0 / .4), 0 1px 2px -1px rgb(0 0 0 / .3);
  --shadow-md:    0 4px 6px -1px rgb(0 0 0 / .4), 0 2px 4px -2px rgb(0 0 0 / .3);
  --shadow-lg:    0 10px 15px -3px rgb(0 0 0 / .4), 0 4px 6px -4px rgb(0 0 0 / .3);
  --shadow-xl:    0 20px 25px -5px rgb(0 0 0 / .5), 0 8px 10px -6px rgb(0 0 0 / .4);
  --shadow-2xl:   0 25px 50px -12px rgb(0 0 0 / .6);
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.9375rem;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg-2);
  transition: background var(--dur-slow) var(--ease),
              color var(--dur-slow) var(--ease);
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; transition: color var(--dur-fast) var(--ease); }
a:hover { color: var(--primary-h); }

img, svg { display: block; max-width: 100%; }
h1 svg, h2 svg, h3 svg, .workspace-title svg, .page-title svg,
button svg, .btn svg, a svg, span svg, label svg, td svg,
.tab-btn svg, .charge-pill svg, .badge svg, .alert-icon svg,
.form-section-title svg { display: inline-block; }

/* ── Typography ────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
  letter-spacing: -0.02em;
}
h1, h2, .page-title, .workspace-title, .auth-card-title, .module-card-title, .auth-brand-name {
  font-family: var(--font-serif);
  letter-spacing: -0.01em;
}
.font-display { font-family: 'Playfair Display', Georgia, serif; }

.text-xs   { font-size: 0.75rem; }
.text-sm   { font-size: 0.8125rem; }
.text-base { font-size: 0.9375rem; }
.text-lg   { font-size: 1.0625rem; }
.text-xl   { font-size: 1.25rem; }
.text-2xl  { font-size: 1.5rem; }
.text-3xl  { font-size: 1.875rem; }

.text-muted  { color: var(--text-3); }
.text-faint  { color: var(--text-4); }
.text-primary { color: var(--primary); }
.text-accent  { color: var(--accent); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.font-medium  { font-weight: 500; }
.font-semi    { font-weight: 600; }
.font-bold    { font-weight: 700; }

/* ── Page transition (HTMX fade-in) ───────────────────────── */
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.page-enter {
  animation: fadeSlideUp var(--dur-slow) var(--ease-out) both;
}
.fade-in {
  animation: fadeIn var(--dur-slow) var(--ease-out) both;
}
.slide-down {
  animation: slideDown var(--dur) var(--ease-out) both;
}

/* ── Loading spinner ───────────────────────────────────────── */
@keyframes spin {
  to { transform: rotate(360deg); }
}
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--border-2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
.spinner-lg {
  width: 40px; height: 40px;
  border-width: 3px;
}

/* Full-page loading overlay */
#page-loader {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px;
  z-index: 9999;
  opacity: 1;
  transition: opacity var(--dur) var(--ease);
}
#page-loader.hidden { opacity: 0; pointer-events: none; }
#page-loader .loader-logo {
  font-size: 2rem;
  animation: fadeIn 0.5s var(--ease-out) both;
}
#page-loader .loader-text {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-3);
  letter-spacing: 0.05em;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0.5625rem 1.25rem;
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.25;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  outline: none;
  white-space: nowrap;
  text-decoration: none;
  position: relative;
  overflow: hidden;
}
.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
.btn:not(:disabled):active {
  transform: translateY(0) !important;
  transition-duration: var(--dur-fast);
}

/* Primary */
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
[data-theme="dark"] .btn-primary { color: #161616; }
[data-theme="dark"] .btn-primary:not(:disabled):hover { color: #161616; }
.btn-primary:not(:disabled):hover {
  background: var(--primary-h);
  border-color: var(--primary-h);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  color: #fff;
}

/* Secondary */
.btn-secondary {
  background: var(--bg);
  border-color: var(--border-2);
  color: var(--text-2);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:not(:disabled):hover {
  background: var(--bg-2);
  border-color: var(--border-focus);
  color: var(--primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* Ghost */
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}
.btn-ghost:not(:disabled):hover {
  background: var(--bg-3);
  color: var(--text);
}

/* Danger */
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:not(:disabled):hover {
  background: #B91C1C;
  border-color: #B91C1C;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  color: #fff;
}

/* Accent */
.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-accent:not(:disabled):hover {
  background: var(--accent-h);
  border-color: var(--accent-h);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  color: #fff;
}

/* Sizes */
.btn-sm { padding: 0.375rem 0.875rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.75rem 1.75rem; font-size: 1rem; border-radius: var(--radius-lg); }
.btn-xl { padding: 0.875rem 2rem; font-size: 1.0625rem; border-radius: var(--radius-lg); }
.btn-full { width: 100%; }

/* Loading state */
.btn.loading { pointer-events: none; }
.btn.loading .btn-text { opacity: 0; }
.btn.loading::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.btn-secondary.loading::after,
.btn-ghost.loading::after {
  border-color: var(--border-2);
  border-top-color: var(--primary);
}

/* ── Form Elements ─────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.form-section .form-group { margin-bottom: 1rem; }
.form-section .form-group:last-child { margin-bottom: 0; }
.form-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-2);
  letter-spacing: 0.01em;
}
.form-label .required {
  color: var(--danger);
  margin-left: 2px;
}
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.5625rem 0.875rem;
  font-family: 'Inter', sans-serif;
  font-size: 0.9375rem;
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  outline: none;
  transition: all var(--dur) var(--ease);
  box-shadow: var(--shadow-sm);
}
.form-input::placeholder { color: var(--text-4); }
.form-input:hover { border-color: var(--text-3); }
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent);
}
.form-input.error { border-color: var(--danger); }
.form-input.error:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 15%, transparent);
}
.form-hint {
  font-size: 0.75rem;
  color: var(--text-4);
}
.form-error {
  font-size: 0.75rem;
  color: var(--danger);
}
.form-textarea { resize: vertical; min-height: 100px; line-height: 1.6; }
.form-select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236B7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 1.25rem;
  padding-right: 2.5rem;
  appearance: none;
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  transition: box-shadow var(--dur) var(--ease),
              border-color var(--dur) var(--ease),
              transform var(--dur) var(--ease);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-hover:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}
.card-body { padding: 1.5rem; }
.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.card-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* KPI / stat card */
.kpi-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur) var(--ease);
}
.kpi-card:hover { box-shadow: var(--shadow-md); }
.kpi-label { font-size: 0.75rem; font-weight: 500; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; }
.kpi-value { font-size: 1.75rem; font-weight: 700; color: var(--text); letter-spacing: -0.03em; margin-top: 4px; }
.kpi-sub   { font-size: 0.75rem; color: var(--text-3); margin-top: 4px; }

/* ── Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0.2rem 0.6rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  border-radius: 999px;
  text-transform: uppercase;
}
.badge-primary  { background: var(--primary-a); color: var(--primary); }
.badge-success  { background: var(--success-a); color: var(--success); }
.badge-danger   { background: var(--danger-a);  color: var(--danger);  }
.badge-warning  { background: var(--warning-a); color: var(--warning); }
.badge-accent   { background: var(--accent-a);  color: var(--accent);  }
.badge-neutral  {
  background: var(--bg-2);
  color: var(--text-2);
  border: 1px solid var(--border);
  text-transform: none;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0;
  padding: 0.375rem 0.75rem;
  border-radius: 999px;
}

/* ── Alerts / Banners ──────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.875rem;
  line-height: 1.5;
  animation: slideDown var(--dur) var(--ease-out) both;
}
.alert-icon { flex-shrink: 0; font-size: 1rem; margin-top: 1px; }
.alert-success { background: var(--success-a); border-color: var(--success); color: var(--success); }
.alert-error   { background: var(--danger-a);  border-color: var(--danger);  color: var(--danger);  }
.alert-warning { background: var(--warning-a); border-color: var(--warning); color: var(--warning); }
.alert-info    { background: var(--info-a);    border-color: var(--info);    color: var(--info);    }

/* ── Dividers ──────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 1.25rem 0;
}
.divider-label {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 1rem 0;
}
.divider-label::before, .divider-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.divider-label span { font-size: 0.75rem; color: var(--text-4); white-space: nowrap; }

/* ── Navbar ────────────────────────────────────────────────── */
.navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--navbar-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 12px;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  transition: background var(--dur-slow) var(--ease),
              border-color var(--dur-slow) var(--ease);
}
.navbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
}
.navbar-logo {
  font-size: 1.25rem;
  line-height: 1;
}
.navbar-name {
  font-family: var(--font-sans, 'Inter', sans-serif);
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-2);
  letter-spacing: -0.02em;
}
.navbar-sep { flex: 1; }
.navbar-actions { display: flex; align-items: center; gap: 8px; }
.navbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}
.navbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--primary);
  color: #F4F3EE;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  font-weight: 600;
  flex-shrink: 0;
  margin-left: 4px;
}

/* ── Sidebar — floating icon rail ─────────────────────────── */
.sidebar {
  position: fixed;
  top: 50%;
  left: 1rem;
  transform: translateY(calc(-50% + var(--navbar-h) / 2));
  width: 60px;
  max-height: calc(100vh - var(--navbar-h) - 2rem);
  background: #000000;
  border-radius: 28px;
  box-shadow: 0 16px 40px rgba(0,0,0,.35), 0 4px 12px rgba(0,0,0,.25);
  overflow: visible;
  z-index: 50;
  transition: transform var(--dur) var(--ease);
  padding: 1.25rem 0.625rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }
.sidebar-section {
  display: none;
}
.rail-divider {
  width: 24px;
  height: 1px;
  background: #3A3A3A;
  margin: 6px 0;
  flex-shrink: 0;
}
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 16px;
  color: #CFCFCF;
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: transparent;
  transition: all var(--dur-fast) var(--ease);
}
.nav-item svg { display: block; }
.nav-item:hover { background: #3A3A3A; color: #F2F2F2; }
.nav-item.active {
  background: #F2F2F2;
  color: #161616;
  box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.nav-item.active:hover { background: #F2F2F2; color: #161616; }
/* Tooltip */
.nav-item::after {
  content: attr(data-tip);
  position: absolute;
  left: calc(100% + 14px);
  top: 50%;
  transform: translateY(-50%) translateX(-4px);
  background: #14161A;
  color: #F4F3EE;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.375rem 0.625rem;
  border-radius: 8px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
  box-shadow: var(--shadow-lg);
  z-index: 10;
}
.nav-item:hover::after {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}
.sidebar-spacer { flex: 1; min-height: 8px; }

/* ── Main Layout ───────────────────────────────────────────── */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--navbar-h) 1fr;
  min-height: 100vh;
}
.main-content {
  grid-column: 2;
  grid-row: 2;
  padding: 2rem;
  overflow-y: auto;
  max-width: 100%;
  animation: fadeSlideUp var(--dur-slow) var(--ease-out) both;
}

/* ── Auth pages ────────────────────────────────────────────── */
.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg);
}
@media (max-width: 768px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
}

/* Left brand panel */
.auth-brand {
  position: relative;
  background: linear-gradient(160deg, #050505 0%, #111111 40%, #1A1A1A 80%, #2A2A2A 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 4rem 3rem;
  overflow: hidden;
}
.auth-brand::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.auth-brand-logo {
  font-size: 3rem;
  margin-bottom: 1rem;
  position: relative;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,.3));
}
.auth-brand-name {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
  position: relative;
}
.auth-brand-tag {
  font-size: 0.9375rem;
  color: rgba(255,255,255,.7);
  margin-bottom: 2.5rem;
  position: relative;
}
.auth-feature-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  position: relative;
}
.auth-feature-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9375rem;
  color: rgba(255,255,255,.85);
}
.auth-feature-list li .icon {
  width: 28px; height: 28px;
  background: rgba(255,255,255,.15);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  flex-shrink: 0;
}
.auth-brand-footer {
  position: absolute;
  bottom: 2rem;
  left: 3rem;
  right: 3rem;
  font-size: 0.75rem;
  color: rgba(255,255,255,.4);
}

/* Right form panel */
.auth-form-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 3rem 2rem;
  min-height: 100vh;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  animation: fadeSlideUp var(--dur-slow) var(--ease-out) both;
}
.auth-card-header { margin-bottom: 2rem; }
.auth-card-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 0.375rem;
}
.auth-card-sub {
  font-size: 0.875rem;
  color: var(--text-3);
}
.auth-form { display: flex; flex-direction: column; gap: 1.125rem; }
.auth-footer {
  margin-top: 1.75rem;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-3);
}
.auth-footer a { font-weight: 500; }

/* OTP input */
.otp-input {
  letter-spacing: 0.5em;
  font-size: 1.5rem !important;
  font-weight: 700;
  text-align: center;
}

/* ── Theme toggle button ───────────────────────────────────── */
.theme-toggle {
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-3);
  font-size: 1rem;
  transition: all var(--dur) var(--ease);
}
.theme-toggle span { display: flex; align-items: center; justify-content: center; }
.theme-toggle:hover {
  background: transparent;
  color: var(--text-2);
}

/* ── Toast Notifications ───────────────────────────────────── */
#toast-container {
  position: fixed;
  top: calc(var(--navbar-h) + 1rem);
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  font-size: 0.875rem;
  font-weight: 500;
  max-width: 360px;
  pointer-events: all;
  animation: slideDown var(--dur) var(--ease-out) both;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.toast.hiding { opacity: 0; transform: translateX(20px); }
.toast-icon { font-size: 1rem; flex-shrink: 0; }
.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--danger);  }
.toast-info    { border-left: 3px solid var(--info);    }
.toast-warning { border-left: 3px solid var(--warning); }

/* ── Tables ────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
thead th {
  padding: 0.75rem 1rem;
  background: var(--bg-2);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 0.75rem 1rem;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-2); }
tbody tr { transition: background var(--dur-fast) var(--ease); }

/* ── Tabs ──────────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  gap: 4px;
  margin-bottom: 1.5rem;
}
.tab-btn {
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-3);
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  margin-bottom: -1px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* ── Section titles ────────────────────────────────────────── */
.section-title {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-4);
  margin-bottom: 0.75rem;
}
.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 0.375rem;
}
.page-sub {
  font-size: 0.9375rem;
  color: var(--text-3);
  margin-bottom: 2rem;
}

/* ── Wallet capsule ────────────────────────────────────────── */
.wallet-capsule {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.3125rem 0.875rem;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
}
.wallet-capsule:hover { border-color: var(--border-2); color: var(--text); }

/* ── Plan badge ────────────────────────────────────────────── */
.plan-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.3125rem 0.875rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
}
.plan-free,
.plan-solo,
.plan-partnership,
.plan-enterprise {
  background: var(--bg);
  color: var(--text-2);
  border: 1px solid var(--border);
}

/* ── Progress / Step indicator ─────────────────────────────── */
.steps {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 2rem;
}
.step-item {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}
.step-circle {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
  border: 2px solid var(--border-2);
  color: var(--text-4);
  background: var(--bg);
  transition: all var(--dur) var(--ease);
}
.step-circle.done  { background: var(--success); border-color: var(--success); color: #fff; }
.step-circle.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.step-label { font-size: 0.75rem; font-weight: 500; color: var(--text-3); }
.step-label.active { color: var(--primary); font-weight: 600; }
.step-line {
  flex: 1;
  height: 1px;
  background: var(--border-2);
  margin: 0 8px;
}
.step-line.done { background: var(--success); }

/* ── Misc utilities ────────────────────────────────────────── */
.flex   { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1  { gap: 4px; }
.gap-2  { gap: 8px; }
.gap-3  { gap: 12px; }
.gap-4  { gap: 16px; }
.gap-6  { gap: 24px; }
.grid-2 { display: grid; grid-template-columns: repeat(2,1fr); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 1rem; }
@media (max-width: 900px) { .grid-4 { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 600px) { .grid-4,.grid-3,.grid-2 { grid-template-columns: 1fr; } }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mt-8 { margin-top: 32px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* ── Tab content ────────────────────────────────────────────── */
.tab-content { display: block; }

/* ── Alert auto-dismiss (JS optional, degrades gracefully) ─── */
.alert-auto-dismiss { animation: fadeSlideUp .3s ease; }

/* ── HTMX request indicator ─────────────────────────────────── */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-flex; }
.htmx-request.htmx-indicator { display: inline-flex; }

/* ═══════════════════════════════════════════════════════════════
   NEW WORKSPACE UI COMPONENTS  (appended)
═══════════════════════════════════════════════════════════════ */

/* ── Utility ─────────────────────────────────────────────────── */
.mb-0  { margin-bottom: 0 !important; }
.btn-full { width: 100%; justify-content: center; }

/* ── Sidebar extras ─────────────────────────────────────────── */
.nav-section-label {
  padding: .25rem .75rem;
  font-size: .6375rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-4);
  margin-top: .5rem;
  margin-bottom: .125rem;
}
.nav-badge {
  margin-left: auto;
  font-size: .625rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--text-3);
  letter-spacing: 0;
  text-transform: none;
}
.nav-item:hover .nav-badge,
.nav-item.active .nav-badge {
  background: var(--primary-a);
  color: var(--primary);
}
.sidebar-user-chip {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: .75rem;
  border-radius: var(--radius);
  background: var(--bg-2);
  border: 1px solid var(--border);
  margin-top: auto;
}
.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8125rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

/* ── Card heading ────────────────────────────────────────────── */
.card-heading {
  font-size: .8125rem;
  font-weight: 600;
  color: var(--text);
}
.card-header {
  display: flex;
  align-items: center;
  gap: .625rem;
}

/* ── Workspace header row ───────────────────────────────────── */
.workspace-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.workspace-title {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.025em;
  margin: 0 0 .25rem;
}
.workspace-sub {
  font-size: .875rem;
  color: var(--text-3);
  margin: 0;
  line-height: 1.5;
}
.charge-pill {
  display: inline-flex;
  align-items: center;
  padding: .3125rem .75rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  background: var(--primary-a);
  color: var(--primary);
  white-space: nowrap;
  border: 1px solid rgba(79,70,229,.15);
}

/* ── Split panel ─────────────────────────────────────────────── */
.split-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}
.split-left, .split-right { min-width: 0; }

/* ── Upload zone ─────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border-2);
  border-radius: var(--radius-lg);
  padding: 2.25rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
  background: var(--bg-2);
}
.upload-zone:hover {
  border-color: var(--primary);
  background: var(--primary-a);
}
.upload-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-a);
  box-shadow: 0 0 0 4px rgba(79,70,229,.12);
}

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem;
  color: var(--text-4);
}

/* ── Module cards (dashboard) ───────────────────────────────── */
.module-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .625rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
  height: 100%;
  cursor: pointer;
}
.module-card:hover {
  box-shadow: 0 12px 24px rgba(0, 0, 0, .15);
  transform: translateY(-4px);
  border-color: var(--border);
}
[data-theme="dark"] .module-card {
  border-color: #262626;
}
[data-theme="dark"] .module-card:hover,
.dark .module-card:hover {
  border-color: #303030;
  box-shadow:
    0 18px 40px rgba(0, 0, 0, .55),
    0 6px 16px rgba(0, 0, 0, .35);
}
.module-card-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  margin-bottom: 1.5rem;
  flex-shrink: 0;
  box-shadow: 0 4px 6px rgba(0,0,0,.1);
}
.module-card-icon svg { display: block; }
.module-card-title {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -.01em;
  margin-bottom: .25rem;
}
.module-card-desc {
  font-size: .875rem;
  color: var(--text-3);
  line-height: 1.625;
  flex: 1;
  margin-bottom: 1.375rem;
}
.module-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
}

/* ── Menu hero (dashboard greeting — Warm Sage) ─────────────── */
.menu-firm-label {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: .75rem;
}
.menu-hero-title {
  font-family: var(--font-serif);
  font-size: clamp(2.25rem, 4vw, 3rem);
  font-weight: 500;
  letter-spacing: -.025em;
  color: var(--text);
  line-height: 1.1;
  margin: 0 0 1rem;
}
.menu-hero-sub {
  color: var(--text-3);
  font-size: 1.125rem;
  margin: 0;
}
.module-card-arrow {
  display: flex;
  align-items: center;
  color: var(--text-3);
  transition: transform var(--dur) var(--ease), color var(--dur) var(--ease);
}
.module-card-arrow svg { display: block; }
.module-card:hover .module-card-arrow {
  transform: translateX(4px);
  color: var(--primary);
}

/* ── Draft result area ───────────────────────────────────────── */
.draft-panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.draft-textarea {
  font-family: 'Times New Roman', Georgia, serif !important;
  font-size: .875rem !important;
  line-height: 1.8 !important;
  resize: vertical;
  min-height: 380px;
}
.ai-edit-bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .875rem 1rem;
  background: var(--bg-2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.export-row {
  display: flex;
  gap: .625rem;
}

/* ── Document type selection cards ──────────────────────────── */
.doc-type-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .875rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  background: var(--bg);
}
.doc-type-card:hover {
  border-color: var(--primary);
  background: var(--primary-a);
}
.doc-type-card:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-a);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
.doc-type-radio {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-2);
  flex-shrink: 0;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
  position: relative;
}
.doc-type-card:has(input:checked) .doc-type-radio {
  border-color: var(--primary);
  background: var(--primary);
  box-shadow: inset 0 0 0 3px var(--bg);
}
.doc-type-label {
  font-size: .8125rem;
  font-weight: 500;
  color: var(--text);
}

/* ── Form sections ───────────────────────────────────────────── */
.form-section {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.125rem 1.25rem;
  margin-bottom: 1rem;
}
.form-section-title {
  font-size: .8125rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.01em;
  margin-bottom: .875rem;
  padding-bottom: .625rem;
  border-bottom: 1px solid var(--border);
}
.radio-opt {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .875rem;
  color: var(--text);
  cursor: pointer;
}
.required { color: var(--danger); }

/* ── Operation icon ─────────────────────────────────────────── */
.op-icon {
  font-size: 1rem;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── Status dot ─────────────────────────────────────────────── */
.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: .375rem;
}
.status-dot.active    { background: var(--success); box-shadow: 0 0 0 2px var(--success-a); }
.status-dot.suspended { background: var(--danger);  box-shadow: 0 0 0 2px var(--danger-a);  }

/* ── Btn accent ─────────────────────────────────────────────── */
.btn-accent {
  background: linear-gradient(135deg, #111111, #2A2A2A);
  color: #fff;
  border: none;
}
.btn-accent:hover { background: linear-gradient(135deg, #000000, #1A1A1A); }

/* ── Btn danger ─────────────────────────────────────────────── */
.btn-danger {
  background: var(--danger-a);
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }


/* ── Mobile / responsive app shell ─────────────────────────── */
.app-shell { padding-top: var(--navbar-h); padding-left: 92px; padding-right: 16px; }
.sidebar-toggle {
  display: none;
  background: none; border: none; cursor: pointer;
  font-size: 1.35rem; line-height: 1; color: var(--text-2);
  padding: .35rem .5rem; border-radius: var(--radius);
}
.sidebar-toggle:hover { background: var(--bg-3, rgba(0,0,0,.06)); }
.sidebar-backdrop {
  display: none; position: fixed; inset: 0;
  top: var(--navbar-h); background: rgba(0,0,0,.4); z-index: 49;
}
.sidebar-backdrop.show { display: block; }

@media (max-width: 900px) {
  .app-shell { padding-left: 0; padding-right: 0; }
  .sidebar-toggle { display: inline-flex; flex-shrink: 0; }
  .sidebar {
    transform: translateY(calc(-50% + var(--navbar-h) / 2)) translateX(calc(-100% - 1.5rem));
    z-index: 60;
  }
  .sidebar.open { transform: translateY(calc(-50% + var(--navbar-h) / 2)) translateX(0); }
  .main-content { padding: 1.25rem 1rem; }
  .navbar { padding: 0 .75rem; gap: 8px; }
  .navbar span[style*="border-right"] { display: none; }  /* firm name */
  .navbar-brand { min-width: 0; }
  .navbar-actions { min-width: 0; }
}

@media (max-width: 600px) {
  .navbar { gap: 6px; }
  .navbar-name { display: none; }               /* keep the ⚖ logo only */
  .navbar-name + span { display: none; }        /* PORTAL tag */
  .plan-badge { display: none; }
  .navbar-avatar, .navbar-divider { display: none; }
  .navbar-actions { gap: 6px; }
  .navbar-actions .btn { padding: .35rem .6rem; }
  .toast-container { right: .75rem; left: .75rem; top: calc(var(--navbar-h) + .5rem); }
}

/* Collapse all inline multi-column grids to a single column on phones */
@media (max-width: 700px) {
  .main-content div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
}

/* ── Reference-document dropzone ────────────────────────────── */
.ref-dropzone {
  border: 2px dashed var(--border-2);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1rem;
  text-align: center;
  cursor: pointer;
  background: var(--bg-2);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.ref-dropzone:hover,
.ref-dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-a);
}
.ref-dropzone.dragover { box-shadow: 0 0 0 4px rgba(79,70,229,.12); }
.ref-dropzone input[type=file] { display: none; }
.ref-dz-icon { font-size: 1.5rem; line-height: 1; margin-bottom: .375rem; }
.ref-dz-title { font-size: .8125rem; font-weight: 600; color: var(--text-2); }
.ref-dz-title .browse { color: var(--primary); text-decoration: underline; }
.ref-dz-hint  { font-size: .6875rem; color: var(--text-4); margin-top: .25rem; }
.ref-dz-count { font-size: .75rem; font-weight: 600; color: var(--primary); margin-top: .375rem; }
.ref-file-list { display: flex; flex-direction: column; gap: .375rem; margin-top: .625rem; }
.ref-file-row {
  display: flex; align-items: center; gap: .5rem;
  padding: .4375rem .625rem;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .78125rem;
  text-align: left;
}
.ref-file-icon { flex: none; }
.ref-file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); font-weight: 500; }
.ref-file-size { flex: none; color: var(--text-4); font-size: .6875rem; }
.ref-file-remove {
  flex: none; background: none; border: none; cursor: pointer;
  color: var(--text-4); font-size: .75rem; padding: .125rem .25rem;
  border-radius: 4px; line-height: 1;
}
.ref-file-remove:hover { color: var(--danger, #ef4444); background: rgba(239,68,68,.08); }
