/* ── Design tokens ─────────────────────────────────────────────────────── */
:root {
  --bg: #0a0a0a;
  --surface: #111111;
  --border: #222222;
  --border-soft: #1a1a1a;
  --text: #ededed;
  --muted: #888888;
  --accent: #6366f1;
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #22c55e;
  --radius: 8px;
  --radius-sm: 6px;
  --sidebar-w: 240px;
  --font: "Inter", -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  height: 100%;
}

h1, h2, h3, h4 { font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }

/* ── Layout ────────────────────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: #0d0d0d;
  border-right: 1px solid var(--border);
  padding: 20px 0;
  flex-shrink: 0;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 15px;
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 12px;
}
.sidebar nav a {
  display: block;
  padding: 9px 20px;
  color: var(--muted);
  border-left: 3px solid transparent;
  text-decoration: none;
  transition: color .15s;
}
.sidebar nav a:hover { color: var(--text); text-decoration: none; }
.sidebar nav a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(99, 102, 241, .06);
}
.sidebar nav .nav-divider {
  height: 1px; background: var(--border);
  margin: 12px 20px;
}

.admin-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--muted); cursor: pointer;
  margin-right: 6px;
}
.admin-toggle input { width: auto; }

.main { flex: 1; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 30;
}
.topbar .app-name { font-family: var(--mono); font-weight: 700; }
.topbar .user { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }

.content { max-width: 1200px; padding: 32px; margin: 0 auto; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.breadcrumb { color: var(--muted); margin-bottom: 16px; font-size: 13px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--text); }

.hamburger {
  display: none;
  background: none; border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 6px 10px; cursor: pointer; font-size: 16px;
}

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

/* ── Tables ────────────────────────────────────────────────────────────── */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--surface);
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
tbody tr { background: var(--bg); border-bottom: 1px solid var(--border-soft); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #161616; }
tbody tr.clickable { cursor: pointer; }
tbody td { padding: 12px 16px; }
tbody tr.overdue {
  border-left: 3px solid var(--warning);
  background: #1a1500;
}
tbody tr.overdue:hover { background: #221c00; }
tbody tr.doc-overdue:not(.overdue) { border-left: 3px solid #f97316; background: #1a0f00; }
tbody tr.doc-overdue:not(.overdue):hover { background: #241500; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  font: inherit; font-weight: 500;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: filter .15s, border-color .15s, color .15s;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn-ghost { background: transparent; color: var(--muted); border-color: #333; }
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost-danger { background: transparent; color: var(--danger); border-color: rgba(239, 68, 68, .35); }
.btn-ghost-danger:hover:not(:disabled) { border-color: var(--danger); }
.edit-icon {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 12px; padding: 0 4px;
}
.edit-icon:hover { color: var(--accent); }
tbody tr.row-fade { opacity: 0; transition: opacity .4s ease; }
tbody tr.inactive-row { opacity: .45; }

/* ── Pagination ────────────────────────────────────────────────────────── */
.pager {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-top: 16px;
}
.pager-info { color: var(--muted); font-size: 13px; }
.pager-btns { display: flex; align-items: center; gap: 4px; }
.pager-num { background: var(--surface); color: var(--text); border: 1px solid var(--border); min-width: 32px; justify-content: center; }
.pager-num:hover:not(.active) { border-color: var(--accent); }
.pager-num.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.pager-ellipsis { color: var(--muted); padding: 0 4px; }

/* ── Document preview modal ───────────────────────────────────────────── */
.modal .card.modal-wide { width: min(920px, 96vw); }
.preview-top {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.preview-doc {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 80vh;
  overflow: auto;
  text-align: center;
}
.preview-img { max-width: 100%; max-height: 80vh; cursor: zoom-in; display: block; margin: 0 auto; }
.preview-img.zoomed { max-width: none; max-height: none; cursor: zoom-out; }
.preview-pdf { width: 100%; height: 80vh; border: none; display: block; }

/* ── Inline-editable detail meta ──────────────────────────────────────── */
.detail-meta { margin: -12px 0 20px; font-size: 13px; }
.inline-edit { cursor: pointer; border-bottom: 1px dashed #444; padding-bottom: 1px; }
.inline-edit:hover { color: var(--accent); border-bottom-color: var(--accent); }
.inline-edit-input {
  width: 140px; display: inline-block;
  padding: 2px 8px; font-size: 13px; min-height: 0;
}
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon { padding: 6px 8px; }
.btn .spinner { width: 14px; height: 14px; border-width: 2px; }
.btn.copied { background: var(--success); color: #fff; border-color: transparent; }

/* ── Inputs ────────────────────────────────────────────────────────────── */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field { margin-bottom: 16px; }
input, select, textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid #333;
  color: var(--text);
  font: inherit;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .25);
}
input.error, select.error { border-color: var(--danger); }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 6px; }

/* ── Badges ────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}
.badge-indigo { background: rgba(99, 102, 241, .15); color: #a5a7f8; }
.badge-amber  { background: rgba(245, 158, 11, .15); color: #fbbf24; }
.badge-orange { background: rgba(249, 115, 22, .18); color: #f97316; }
.badge-green  { background: rgba(34, 197, 94, .15); color: #4ade80; }
.badge-grey   { background: rgba(136, 136, 136, .15); color: var(--muted); }
.badge-red    { background: rgba(239, 68, 68, .15); color: #f87171; }

/* ── Login (light theme, matches the client portal login) ──────────────── */
/* Everything is scoped under .login-wrap so it overrides the dark app shell
   on the login screen only — the rest of the broker app stays dark. */
.login-wrap {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 20px; padding: 20px;
  background: #f8fafc;
}
.login-wrap .login-logo { max-width: 200px; width: 100%; height: auto; display: block; }
.login-wrap .login-card {
  width: 380px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 28px 24px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}
.login-wrap .login-card .brand {
  text-align: center; margin-bottom: 4px;
  font-family: var(--mono); font-size: 20px; font-weight: 700; color: #0f172a;
}
.login-wrap .login-card .tagline {
  text-align: center; color: #64748b; margin-bottom: 26px; font-size: 13px;
}
.login-wrap label { display: block; font-size: 13px; color: #64748b; margin-bottom: 6px; }
.login-wrap .field { margin-bottom: 16px; }
.login-wrap input {
  width: 100%; font: inherit; color: #0f172a;
  background: #ffffff; border: 1px solid #e2e8f0;
  border-radius: 8px; padding: 9px 12px; outline: none;
}
.login-wrap input:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99, 102, 241, .15); }
.login-wrap input.error { border-color: var(--danger); }
.login-wrap .error-msg { color: var(--danger); font-size: 13px; margin-top: 6px; }
.login-wrap .btn-primary { background: #6366f1; color: #fff; border: 1px solid transparent; }
.login-wrap .btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.login-wrap .btn-block { width: 100%; justify-content: center; min-height: 44px; }

/* ── Slide-over panel ──────────────────────────────────────────────────── */
.backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .6);
  z-index: 40; opacity: 0; transition: opacity .2s;
}
.backdrop.open { opacity: 1; }
.slideover {
  position: fixed; top: 0; right: -480px; bottom: 0;
  width: 480px; max-width: 95vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 50;
  display: flex; flex-direction: column;
  transition: right .25s ease;
}
.slideover.open { right: 0; }
.slideover header {
  padding: 20px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.slideover .body { padding: 20px; flex: 1; overflow-y: auto; }
.slideover footer {
  padding: 16px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ── Modal ─────────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .6); padding: 20px;
}
.modal .card { width: 460px; max-width: 100%; max-height: 85vh; overflow-y: auto; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.code-block {
  font-family: var(--mono); font-size: 13px;
  background: #0d0d1f; border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px; margin: 12px 0; word-break: break-all;
}

/* ── Timeline ──────────────────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 26px; }
.timeline::before {
  content: ""; position: absolute; left: 7px; top: 8px; bottom: 8px;
  width: 2px; background: var(--border);
}
.tl-node { position: relative; padding-bottom: 22px; }
.tl-node:last-child { padding-bottom: 0; }
.tl-dot {
  position: absolute; left: -26px; top: 4px;
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg);
}
.tl-node.done .tl-dot { background: var(--accent); border-color: var(--accent); }
.tl-node .tl-title { font-weight: 500; }
.tl-node .tl-time { color: var(--muted); font-size: 12px; }
.tl-node .log-link { font-size: 13px; }
.tl-form { margin-top: 10px; padding: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); }

/* ── Tabs ──────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  background: none; border: none; color: var(--muted);
  font: inherit; padding: 8px 14px; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  display: inline-flex; align-items: center; gap: 7px;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.count-badge {
  background: var(--accent); color: #fff;
  font-size: 11px; border-radius: 999px;
  padding: 1px 7px; font-weight: 600;
}

/* ── Doc cards ─────────────────────────────────────────────────────────── */
.doc-card { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.doc-card .meta { font-size: 13px; color: var(--muted); }
.doc-card .actions { display: flex; gap: 8px; flex-shrink: 0; }
.tooltip-wrap { position: relative; display: inline-block; }
.tooltip-wrap .tip {
  display: none; position: absolute; bottom: calc(100% + 6px); right: 0;
  background: #222; color: var(--text); font-size: 12px;
  padding: 5px 9px; border-radius: 5px; white-space: nowrap; z-index: 10;
}
.tooltip-wrap:hover .tip { display: block; }

/* ── Notes auto-save indicator ─────────────────────────────────────────── */
.notes-saved {
  font-size: 13px; color: var(--success);
  opacity: 0; transition: opacity .3s ease;
}
.notes-saved.show { opacity: 1; }

/* ── Toasts ────────────────────────────────────────────────────────────── */
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  min-width: 260px; max-width: 380px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  animation: toast-in .2s ease;
}
.toast.success { border-left-color: var(--success); }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Skeletons & spinners ──────────────────────────────────────────────── */
.skeleton {
  height: 14px; border-radius: 4px;
  background: linear-gradient(90deg, #1a1a1a 25%, #242424 50%, #1a1a1a 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.spinner {
  width: 18px; height: 18px;
  border: 3px solid rgba(255, 255, 255, .25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ───────────────────────────────────────────────────────── */
.empty {
  text-align: center; padding: 60px 20px; color: var(--muted);
}
.empty .icon { font-size: 34px; margin-bottom: 12px; opacity: .6; }

/* ── Filter bar ────────────────────────────────────────────────────────── */
.filter-bar { display: flex; gap: 14px; align-items: end; margin-bottom: 20px; flex-wrap: wrap; }
.filter-bar .field { margin: 0; min-width: 160px; }

/* ── Two-column detail ─────────────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

/* ── Mobile ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: calc(-1 * var(--sidebar-w)); top: 0; bottom: 0;
    z-index: 45; transition: left .25s ease; height: 100vh;
  }
  .sidebar.open { left: 0; }
  .hamburger { display: inline-flex; }
  .content { padding: 20px 16px; }
  .topbar { padding: 10px 16px; }
  .detail-grid { grid-template-columns: 1fr; }
  .topbar .user .email { display: none; }
}
