:root {
  --ink:           #1a1a18;
  --ink-mid:       #4a4a46;
  --ink-faint:     #9a9a94;
  --rule:          #e2e2dc;
  --surface:       #f7f7f4;
  --surface-raised: #ffffff;
  --white:         #ffffff;
  --accent:        #2a4390;
  --accent-mid:    #3a5ab0;
  --accent-light:  #e8ecf6;
  --accent-text:   #1a2d60;
  --amber:         #f36c21;
  --amber-light:   #fef0e8;
  --amber-text:    #a03d0a;
  --red:           #ef463e;
  --red-light:     #fdecea;
  --red-text:      #a01a14;
  --blue:          #33a7d7;
  --blue-light:    #e6f5fb;
  --blue-text:     #1a6080;
  --green:         #46b978;
  --green-light:   #e8f7ee;
  --green-text:    #1e6b3a;
  --sans:  'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono:  'DM Mono', 'Courier New', monospace;
  --text-xs:   11px; --text-sm: 13px; --text-base: 14px;
  --text-md:   15px; --text-lg: 17px; --text-xl:   20px; --text-2xl: 24px;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px; --space-12: 48px;
  --radius-sm: 3px; --radius-md: 6px; --radius-lg: 10px;
  --sidebar-width: 220px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.10);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--sans); background: var(--surface); color: var(--ink); font-size: var(--text-base); line-height: 1.55; -webkit-font-smoothing: antialiased; min-height: 100vh; }
#app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-width); min-width: var(--sidebar-width); background: var(--ink); color: var(--white); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 200; overflow-y: auto; }
.sidebar-logo { padding: var(--space-6) var(--space-5) var(--space-5); border-bottom: 1px solid rgba(255,255,255,0.08); display: flex; align-items: flex-start; gap: var(--space-3); }
.sidebar-logo-inner { display: flex; flex-direction: column; }
.sidebar-logo .wordmark { font-size: var(--text-lg); font-weight: 600; letter-spacing: -0.4px; color: var(--white); line-height: 1.2; }
.sidebar-logo .wordmark-plus { font-size: 1.25em; font-weight: 600; color: var(--white); }
.sidebar-logo .practice { font-size: var(--text-xs); color: rgba(255,255,255,0.38); margin-top: 1px; font-weight: 400; letter-spacing: 0.4px; }
.sidebar-icon { width: 48px; height: 48px; object-fit: contain; filter: invert(1); opacity: 0.85; display: block; flex-shrink: 0; }
.sidebar-nav { padding: var(--space-4) 0; flex: 1; }
.nav-group-label { font-size: 10px; font-weight: 500; letter-spacing: 0.9px; text-transform: uppercase; color: rgba(255,255,255,0.28); padding: var(--space-3) var(--space-5) var(--space-1); }
.nav-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-5); color: rgba(255,255,255,0.65); font-size: var(--text-sm); font-weight: 400; cursor: pointer; text-decoration: none; border-left: 2px solid transparent; transition: color 0.12s, background 0.12s; user-select: none; }
.nav-item:hover { color: var(--white); background: rgba(255,255,255,0.06); }
.nav-item.active { color: var(--white); border-left-color: var(--accent-mid); background: rgba(255,255,255,0.08); font-weight: 500; }
.nav-item .nav-icon { width: 16px; height: 16px; opacity: 0.7; flex-shrink: 0; }
.nav-item.active .nav-icon { opacity: 1; }
.sidebar-user { padding: var(--space-4) var(--space-5); border-top: 1px solid rgba(255,255,255,0.08); font-size: var(--text-xs); color: rgba(255,255,255,0.4); }
.sidebar-user .user-name { color: rgba(255,255,255,0.7); font-weight: 500; font-size: var(--text-sm); }
.main-content { margin-left: var(--sidebar-width); flex: 1; min-width: 0; min-height: 100vh; display: flex; flex-direction: column; }
.page-header { padding: var(--space-8) var(--space-8) var(--space-5); background: var(--surface-raised); border-bottom: 1px solid var(--rule); position: sticky; top: 0; z-index: 40; }
.page-header-inner { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); }
.page-title { font-size: var(--text-2xl); font-weight: 500; letter-spacing: -0.5px; color: var(--ink); }
.page-subtitle { font-size: var(--text-sm); color: var(--ink-faint); margin-top: var(--space-1); }
.page-body { padding: var(--space-8); flex: 1; }
.card { background: var(--surface-raised); border: 1px solid var(--rule); border-radius: var(--radius-lg); padding: var(--space-6); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-5); }
.card-title { font-size: var(--text-md); font-weight: 500; color: var(--ink); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: var(--space-4); margin-bottom: var(--space-8); }
.stat-block { background: var(--surface-raised); border: 1px solid var(--rule); border-radius: var(--radius-lg); padding: var(--space-5) var(--space-5) var(--space-4); }
.stat-value { font-size: var(--text-2xl); font-weight: 500; letter-spacing: -0.5px; color: var(--ink); font-family: var(--mono); }
.stat-value.stat-accent { color: var(--accent); }
.stat-label { font-size: var(--text-xs); color: var(--ink-faint); margin-top: var(--space-1); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 500; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
thead th { font-size: var(--text-xs); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; color: var(--ink-faint); padding: var(--space-2) var(--space-4); text-align: left; border-bottom: 1px solid var(--rule); }
tbody tr { border-bottom: 1px solid var(--rule); cursor: pointer; transition: background 0.1s; }
tbody tr:hover { background: var(--surface); }
tbody tr:last-child { border-bottom: none; }
tbody td { padding: var(--space-3) var(--space-4); color: var(--ink); }
.td-muted { color: var(--ink-faint); }
.td-mono { font-family: var(--mono); font-size: var(--text-xs); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 3px; font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.2px; }
.badge-green { background: var(--green-light); color: var(--green-text); }
.badge-amber { background: var(--amber-light); color: var(--amber-text); }
.badge-red { background: var(--red-light); color: var(--red-text); }
.badge-blue { background: var(--blue-light); color: var(--blue-text); }
.badge-grey { background: var(--surface); color: var(--ink-mid); border: 1px solid var(--rule); }
.btn { display: inline-flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-4); border-radius: var(--radius-md); font-family: var(--sans); font-size: var(--text-sm); font-weight: 500; cursor: pointer; border: 1px solid transparent; transition: background 0.12s, border-color 0.12s, color 0.12s; text-decoration: none; white-space: nowrap; }
.btn-primary { background: var(--accent); color: var(--white); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-text); border-color: var(--accent-text); }
.btn-secondary { background: var(--surface-raised); color: var(--ink); border-color: var(--rule); }
.btn-secondary:hover { background: var(--surface); border-color: var(--ink-faint); }
.btn-ghost { background: transparent; color: var(--ink-mid); border-color: transparent; }
.btn-ghost:hover { background: var(--surface); color: var(--ink); }
.btn-danger { background: var(--red); color: var(--white); border-color: var(--red); }
.btn-danger:hover { background: var(--red-text); border-color: var(--red-text); }
.btn-green { background: var(--green); color: var(--white); border-color: var(--green); }
.btn-green:hover { background: var(--green-text); border-color: var(--green-text); }
.btn-lg { padding: var(--space-3) var(--space-6); font-size: var(--text-md); }
.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.form-group { margin-bottom: var(--space-5); }
.form-label { display: block; font-size: var(--text-sm); font-weight: 500; color: var(--ink); margin-bottom: var(--space-2); }
.form-hint { font-size: var(--text-xs); color: var(--ink-faint); margin-top: var(--space-1); }
.form-input, .form-select, .form-textarea { display: block; width: 100%; padding: var(--space-2) var(--space-3); border: 1px solid var(--rule); border-radius: var(--radius-md); font-family: var(--sans); font-size: var(--text-sm); color: var(--ink); background: var(--surface-raised); transition: border-color 0.12s; outline: none; appearance: none; }
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--accent); }
.form-textarea { resize: vertical; min-height: 80px; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(26,26,24,0.5); z-index: 500; display: flex; align-items: center; justify-content: center; padding: var(--space-6); }
.modal { background: var(--surface-raised); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; display: flex; flex-direction: column; }
.modal-lg { max-width: 900px; max-height: 96vh; }
.modal-header { padding: var(--space-6) var(--space-6) 0; display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); }
.modal-title { font-size: var(--text-xl); font-weight: 500; letter-spacing: -0.3px; }
.modal-close { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); cursor: pointer; color: var(--ink-faint); border: none; background: none; font-size: 18px; flex-shrink: 0; transition: color 0.1s, background 0.1s; }
.modal-close:hover { background: var(--surface); color: var(--ink); }
.modal-body { padding: var(--space-5) var(--space-6); flex: 1; }
.modal-footer { padding: 0 var(--space-6) var(--space-6); display: flex; gap: var(--space-3); justify-content: flex-end; }
.chat-thread { display: flex; flex-direction: column; gap: var(--space-4); min-height: 300px; max-height: 400px; overflow-y: auto; padding: var(--space-1) 0 var(--space-4); }
.chat-bubble { display: flex; gap: var(--space-3); align-items: flex-start; }
.chat-bubble.user { flex-direction: row-reverse; }
.chat-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-light); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: var(--text-xs); font-weight: 600; flex-shrink: 0; }
.chat-bubble.user .chat-avatar { background: var(--ink); color: var(--white); }
.chat-message { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); font-size: var(--text-sm); color: var(--ink); max-width: 85%; line-height: 1.55; }
.chat-bubble.user .chat-message { background: var(--accent); color: var(--white); border-color: var(--accent); }
.chat-input-area { border-top: 1px solid var(--rule); padding-top: var(--space-4); margin-top: var(--space-2); }
.chat-options { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-3); }
.chat-option { padding: var(--space-2) var(--space-4); border: 1px solid var(--rule); border-radius: var(--radius-md); font-size: var(--text-sm); cursor: pointer; background: var(--surface-raised); color: var(--ink); transition: border-color 0.1s, background 0.1s; }
.chat-option:hover, .chat-option.selected { border-color: var(--accent); background: var(--accent-light); color: var(--accent-text); }
.spinner { width: 18px; height: 18px; border: 2px solid var(--rule); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row { display: flex; align-items: center; gap: var(--space-3); color: var(--ink-faint); font-size: var(--text-sm); padding: var(--space-4); }
.empty-state { text-align: center; padding: var(--space-12) var(--space-8); color: var(--ink-faint); }
.empty-state-title { font-size: var(--text-lg); font-weight: 500; color: var(--ink-mid); margin-bottom: var(--space-2); }
.folder-tree { font-family: var(--mono); font-size: var(--text-xs); color: var(--ink-mid); background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-md); padding: var(--space-4); line-height: 1.7; }
.folder-tree .folder-item { display: flex; align-items: center; gap: 6px; }
.folder-tree .folder-item.new { color: var(--accent); font-weight: 500; }
.folder-tree .indent-1 { padding-left: 16px; }
.folder-tree .indent-2 { padding-left: 32px; }
.notice { display: flex; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-size: var(--text-sm); line-height: 1.5; }
.notice-amber { background: var(--amber-light); color: var(--amber-text); border: 1px solid var(--amber); }
.notice-green  { background: var(--green-light); color: var(--green-text); border: 1px solid var(--green); }
.notice-red    { background: var(--red-light); color: var(--red-text); border: 1px solid var(--red); }
.notice-blue   { background: var(--blue-light); color: var(--blue-text); border: 1px solid var(--blue); }
hr.divider { border: none; border-top: 1px solid var(--rule); margin: var(--space-6) 0; }
.section-label { font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.6px; text-transform: uppercase; color: var(--ink-faint); margin-bottom: var(--space-3); }
.flex { display: flex; } .flex-col { flex-direction: column; } .items-center { align-items: center; } .justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); } .gap-3 { gap: var(--space-3); } .gap-4 { gap: var(--space-4); }
.mt-4 { margin-top: var(--space-4); } .mt-6 { margin-top: var(--space-6); } .mb-4 { margin-bottom: var(--space-4); } .mb-6 { margin-bottom: var(--space-6); }
.text-sm { font-size: var(--text-sm); } .text-xs { font-size: var(--text-xs); } .text-muted { color: var(--ink-faint); } .font-mono { font-family: var(--mono); } .w-full { width: 100%; }

/* ── Detail rows (project / enquiry detail views) ───────────────────────── */
.detail-row { display: flex; align-items: baseline; gap: var(--space-3); padding: var(--space-2) 0; border-bottom: 1px solid var(--rule); font-size: var(--text-sm); }
.detail-row:last-child { border-bottom: none; }
.detail-label { font-size: var(--text-xs); font-weight: 500; text-transform: uppercase; letter-spacing: 0.4px; color: var(--ink-faint); min-width: 120px; flex-shrink: 0; }

/* ── Editable fields (contenteditable inline editing) ───────────────────── */
.editable-field { border-bottom: 1px dashed var(--ink-faint); padding: 1px 4px; border-radius: 2px; min-width: 60px; cursor: text; outline: none; transition: background 0.1s, border-color 0.1s; }
.editable-field:hover { background: var(--surface); border-bottom-color: var(--accent-mid); }
.editable-field:focus { background: var(--accent-light); border-bottom: 1px solid var(--accent); }
.editable-field:empty::before { content: attr(data-placeholder); color: var(--ink-faint); font-style: italic; pointer-events: none; }

/* ── Fee calculator ─────────────────────────────────────────────────────── */
.fee-calculator { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-md); padding: var(--space-4); }
.fee-calc-result { font-family: var(--mono); font-weight: 600; color: var(--accent); }

/* ── Misc utilities ─────────────────────────────────────────────────────── */
.mt-2 { margin-top: var(--space-2); } .mt-3 { margin-top: var(--space-3); }
.mb-2 { margin-bottom: var(--space-2); } .mb-3 { margin-bottom: var(--space-3); }
.items-end { align-items: flex-end; }

.detail-select { font-family: var(--sans); font-size: var(--text-sm); color: var(--ink); background: var(--surface-raised); border: 1px solid var(--rule); border-radius: var(--radius-sm); padding: 2px 6px; outline: none; cursor: pointer; transition: border-color 0.12s; }
.detail-select:focus { border-color: var(--accent); }

/* ── Typeahead ──────────────────────────────────────────────────────────── */
.typeahead-wrap { position: relative; }
.typeahead-dropdown { position: absolute; top: 100%; left: 0; right: 0; background: var(--surface-raised); border: 1px solid var(--rule); border-radius: var(--radius-md); box-shadow: var(--shadow-md); z-index: 100; max-height: 260px; overflow-y: auto; margin-top: 2px; }
.typeahead-item { display: flex; align-items: baseline; gap: var(--space-3); padding: var(--space-2) var(--space-3); cursor: pointer; font-size: var(--text-sm); border-bottom: 1px solid var(--rule); }
.typeahead-item:last-child { border-bottom: none; }
.typeahead-item:hover { background: var(--surface); }
.typeahead-name { color: var(--ink); font-weight: 500; }
.typeahead-email { color: var(--ink-faint); font-size: var(--text-xs); }
.typeahead-new { color: var(--accent); }
.typeahead-new .typeahead-name { color: var(--accent); font-weight: 400; }

/* ── Disabled button states ──────────────────────────────────────────────────── */
.btn:disabled,
.btn[disabled] {
  opacity: 0.38;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Modal body scroll fix — prevent double scrollbar with iframe content ───── */
/* overflow is controlled per-element; iframe wrapper handles its own scroll */
