:root {
  --blue: #4A7FA5;
  --blue-hover: #3d6d8f;
  --blue-soft: rgba(74, 127, 165, 0.14);
  --gold: #B8973A;
  --gold-text: #8a6f2c;
  --gold-soft: rgba(184, 151, 58, 0.15);
  --ink: #0f172a;
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --white: #fff;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  --radius: 10px;
  --sidebar: 220px;
  --topbar: 56px;
  --bottomnav: 64px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--slate-800);
  background: var(--slate-50);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--blue); }

#app { min-height: 100%; }

.boot {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--slate-500);
}

.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar);
  flex-shrink: 0;
  background: var(--white);
  border-right: 1px solid var(--slate-200);
  padding: 18px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--slate-500);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: var(--slate-100); color: var(--slate-700); }
.nav-item.active { background: var(--blue); color: var(--white); }
.nav-item svg { flex-shrink: 0; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar);
  background: var(--white);
  border-bottom: 1px solid var(--slate-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { font-size: 15px; margin: 0; font-weight: 650; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.content { padding: 20px; flex: 1; }

.brand { display: flex; align-items: center; gap: 8px; padding: 0 8px 14px; }
.brand-text { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.firm-name {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--slate-800);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
.wordmark { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; color: var(--slate-400); }
.wordmark span { color: var(--slate-300); font-weight: 500; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 650;
  text-decoration: none;
}
.btn-primary { background: var(--blue); color: var(--white); }
.btn-primary:hover { background: var(--blue-hover); }
.btn-ghost { background: var(--slate-100); color: var(--slate-600); }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-outline { background: transparent; border: 1px solid var(--slate-200); color: var(--slate-700); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.seg {
  display: inline-flex;
  background: var(--slate-100);
  border-radius: 8px;
  padding: 3px;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--slate-500);
  font-size: 11px;
  font-weight: 650;
  padding: 6px 10px;
  border-radius: 6px;
}
.seg button.on { background: var(--blue); color: var(--white); }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--slate-50);
  border: 1px solid var(--slate-200);
  border-radius: 8px;
  padding: 6px 10px;
  min-width: 180px;
  position: relative;
}
.search input {
  border: 0;
  background: transparent;
  outline: none;
  width: 160px;
  font-size: 12px;
  color: var(--slate-800);
}
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 320px;
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
  max-height: 360px;
  overflow: auto;
  z-index: 50;
}
.search-hit {
  display: block;
  padding: 10px 12px;
  text-decoration: none;
  color: var(--slate-700);
  font-size: 12px;
  border-bottom: 1px solid var(--slate-100);
}
.search-hit:hover { background: var(--slate-50); }
.search-hit small { display: block; color: var(--slate-400); margin-top: 2px; }

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--blue-soft);
  border: 1px solid rgba(74, 127, 165, 0.3);
  color: var(--blue);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
}

.grid-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.card {
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.card.clickable { cursor: pointer; text-decoration: none; color: inherit; display: block; }
.card.clickable:hover { border-color: var(--blue); }
.card-title { font-size: 13px; font-weight: 650; }
.muted { color: var(--slate-400); font-size: 12px; }
.tiny { font-size: 11px; color: var(--slate-400); }

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--slate-100);
  color: var(--slate-500);
}
.badge-open { background: var(--gold-soft); color: var(--gold-text); }
.badge-pending { background: var(--blue-soft); color: var(--blue); }
.badge-scoped { background: var(--slate-100); color: var(--slate-500); gap: 4px; }

.money { color: var(--gold-text); font-weight: 700; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 0;
  background: var(--slate-100);
  color: var(--slate-500);
  font-size: 11px;
  font-weight: 650;
  padding: 6px 10px;
  border-radius: 999px;
}
.chip.on { background: var(--blue); color: var(--white); }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--slate-400);
  padding: 10px 12px;
  border-bottom: 1px solid var(--slate-200);
}
.table td { padding: 11px 12px; border-bottom: 1px solid var(--slate-100); }
.table tr { cursor: pointer; }
.table tr:hover td { background: var(--slate-50); }
.table a { color: inherit; text-decoration: none; font-weight: 650; }

.tabs { display: flex; gap: 18px; border-bottom: 1px solid var(--slate-200); }
.tab {
  border: 0;
  background: none;
  padding: 0 0 10px;
  font-size: 12px;
  font-weight: 650;
  color: var(--slate-400);
}
.tab.on { color: var(--blue); box-shadow: inset 0 -2px 0 var(--blue); }

.dropzone {
  border: 1.5px dashed var(--slate-300);
  background: var(--slate-50);
  border-radius: var(--radius);
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--slate-400);
  font-size: 12px;
}
.dropzone.drag { border-color: var(--blue); background: var(--blue-soft); color: var(--blue); }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.three-col { display: grid; grid-template-columns: 1fr 2fr; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field span { font-size: 11px; color: var(--slate-400); font-weight: 650; }
.field input, .field select, .field textarea {
  border: 1px solid var(--slate-200);
  border-radius: 8px;
  padding: 9px 10px;
  background: var(--white);
  color: var(--slate-800);
}
.field textarea { min-height: 90px; resize: vertical; }

.banner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--slate-100);
  color: var(--slate-600);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
}

.fab {
  display: none;
  position: fixed;
  right: 20px;
  bottom: calc(var(--bottomnav) + 16px);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--blue);
  color: var(--white);
  border: 0;
  box-shadow: 0 8px 20px rgba(74, 127, 165, 0.35);
  z-index: 30;
}

.bottomnav {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--bottomnav);
  background: var(--white);
  border-top: 1px solid var(--slate-200);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 25;
}
.bottomnav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--slate-400);
  font-size: 10px;
  font-weight: 650;
}
.bottomnav a.on { color: var(--blue); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 80;
}
.modal {
  background: var(--white);
  width: min(520px, 100%);
  border-radius: 16px 16px 0 0;
  padding: 18px;
  max-height: 88vh;
  overflow: auto;
}
.sheet-handle {
  width: 32px;
  height: 4px;
  background: var(--slate-300);
  border-radius: 99px;
  margin: 0 auto 12px;
}
.toast-wrap {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 90;
}
.toast {
  background: var(--slate-800);
  color: var(--white);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, #f8fafc 0%, #eef3f7 100%);
}
.login-card {
  width: min(420px, 100%);
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.06);
}
.login-card h1 { font-size: 20px; margin: 16px 0 8px; }
.ms-btn {
  width: 100%;
  margin-top: 18px;
  background: var(--slate-800);
  color: var(--white);
  padding: 12px;
  border-radius: 10px;
  border: 0;
  font-weight: 650;
}
.google-btn {
  width: 100%;
  margin-top: 8px;
  background: var(--white);
  color: var(--slate-800);
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--slate-200);
  font-weight: 650;
}
.preview {
  border: 1px solid var(--slate-200);
  border-radius: 10px;
  overflow: hidden;
  background: var(--slate-100);
  min-height: 240px;
}
.preview iframe, .preview img { width: 100%; height: 70vh; border: 0; display: block; background: var(--white); }
.preview-text {
  margin: 0;
  padding: 16px;
  max-height: 70vh;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 13px;
}
.preview-fallback { padding: 32px; text-align: center; }
.progress-bar {
  height: 6px;
  margin-top: 8px;
  background: var(--slate-200);
  border-radius: 99px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  width: 0;
  background: var(--blue);
  border-radius: 99px;
  transition: width 0.15s ease;
}
.doc-row, .note-row, .task-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: 10px;
  padding: 10px 12px;
}
.person {
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
}
.person.on { background: var(--blue); color: var(--white); }
.person:not(.on):hover { background: var(--slate-100); }

.menu { position: relative; }
.menu-pop {
  position: absolute;
  right: 0;
  top: 36px;
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: 10px;
  min-width: 180px;
  box-shadow: 0 12px 32px rgba(15,23,42,.12);
  z-index: 40;
}
.menu-pop button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 0;
  background: none;
  font-size: 12px;
  color: var(--slate-700);
}
.menu-pop button:hover { background: var(--slate-50); }

.offline-pill {
  font-size: 10px;
  font-weight: 700;
  background: var(--gold-soft);
  color: var(--gold-text);
  padding: 4px 8px;
  border-radius: 999px;
}

@media (min-width: 860px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 16px; }
  .sheet-handle { display: none; }
}

@media (max-width: 859px) {
  .sidebar { display: none; }
  .topbar { padding: 0 12px; }
  .content { padding: 14px 14px calc(var(--bottomnav) + 24px); }
  .grid-cards { grid-template-columns: 1fr; }
  .two-col, .three-col { grid-template-columns: 1fr; }
  .search input { width: 110px; }
  .bottomnav { display: flex; }
  .fab { display: grid; place-items: center; }
  .hide-mobile { display: none !important; }
  .table-wrap { overflow: auto; }
}

@media (min-width: 860px) {
  .hide-desktop { display: none !important; }
  .mobile-brand { display: none !important; }
}
