/* ============================================================
   AAVIVR — CA Practice Management  |  Design system
   ============================================================ */
:root {
  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --brand-light: #eef2ff;
  --brand-50: #f5f7ff;

  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;

  --text: #111827;
  --text-soft: #4b5563;
  --text-muted: #9ca3af;

  --green: #16a34a;   --green-bg: #dcfce7;
  --amber: #d97706;   --amber-bg: #fef3c7;
  --red: #dc2626;     --red-bg: #fee2e2;
  --blue: #2563eb;    --blue-bg: #dbeafe;
  --purple: #7c3aed;  --purple-bg: #ede9fe;
  --slate: #475569;   --slate-bg: #e2e8f0;
  --teal: #0d9488;    --teal-bg: #ccfbf1;

  --shadow-sm: 0 1px 2px rgba(16,24,40,.06);
  --shadow: 0 1px 3px rgba(16,24,40,.1), 0 1px 2px rgba(16,24,40,.06);
  --shadow-lg: 0 10px 25px rgba(16,24,40,.12), 0 4px 10px rgba(16,24,40,.05);
  --radius: 10px;
  --radius-sm: 7px;
  --sidebar-w: 248px;
  --header-h: 60px;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
h1,h2,h3,h4 { margin: 0; font-weight: 600; color: var(--text); }
.boot-loader { display:flex; align-items:center; justify-content:center; height:100vh; color:var(--text-muted); font-size:15px; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: #1e1b4b; color: #c7d2fe; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.sidebar .brand { display:flex; align-items:center; gap:10px; padding: 16px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar .brand .logo {
  width: 34px; height: 34px; border-radius: 9px; background: var(--brand);
  display:flex; align-items:center; justify-content:center; color:#fff; font-weight:800; font-size:18px;
}
.sidebar .brand .name { color:#fff; font-weight:700; font-size:16px; line-height:1.1; }
.sidebar .brand .name small { display:block; color:#a5b4fc; font-weight:500; font-size:10.5px; letter-spacing:.04em; text-transform:uppercase; }

.nav { flex:1; overflow-y:auto; padding: 10px 10px 24px; }
.nav-section { color:#818cf8; font-size:10.5px; text-transform:uppercase; letter-spacing:.08em; font-weight:700; padding: 16px 12px 6px; }
.nav a {
  display:flex; align-items:center; gap:11px; padding: 9px 12px; border-radius: 8px;
  color:#c7d2fe; font-weight:500; font-size:13.5px; margin-bottom:2px; transition: background .12s, color .12s;
}
.nav a .ico { width:18px; text-align:center; opacity:.9; font-size:15px; }
.nav a:hover { background: rgba(255,255,255,.06); color:#fff; }
.nav a.active { background: var(--brand); color:#fff; box-shadow: var(--shadow-sm); }
.nav a .badge-count { margin-left:auto; background: rgba(255,255,255,.15); color:#fff; font-size:11px; padding: 1px 7px; border-radius: 999px; font-weight:600; }
.nav a.active .badge-count { background: rgba(255,255,255,.25); }

.main { display:flex; flex-direction:column; min-width:0; }
.header {
  height: var(--header-h); background: var(--surface); border-bottom: 1px solid var(--border);
  display:flex; align-items:center; gap:14px; padding: 0 22px; position: sticky; top:0; z-index: 20;
}
.header .page-title { font-size: 17px; font-weight: 700; }
.header .spacer { flex:1; }
.search-box { position: relative; width: 320px; max-width: 36vw; }
.search-box input {
  width:100%; padding: 8px 12px 8px 34px; border:1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); font-size: 13px;
}
.search-box input:focus { outline:none; border-color: var(--brand); background:#fff; box-shadow: 0 0 0 3px var(--brand-light); }
.search-box .s-ico { position:absolute; left:11px; top:50%; transform: translateY(-50%); color: var(--text-muted); }
.header-btn {
  position: relative; width: 38px; height: 38px; border-radius: 8px; border:1px solid var(--border);
  background: var(--surface); cursor:pointer; font-size: 16px; display:flex; align-items:center; justify-content:center; color: var(--text-soft);
}
.header-btn:hover { background: var(--surface-2); }
.header-btn .dot { position:absolute; top:6px; right:7px; width:8px; height:8px; background: var(--red); border-radius:50%; border:2px solid #fff; }
.avatar { width: 36px; height:36px; border-radius:50%; background: var(--brand); color:#fff; display:flex; align-items:center; justify-content:center; font-weight:700; font-size:13px; }

.content { padding: 22px; flex:1; max-width: 1400px; width: 100%; }

/* ---------- Buttons ---------- */
.btn {
  display:inline-flex; align-items:center; gap:7px; padding: 8px 14px; border-radius: 8px; border:1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-size: 13px; font-weight: 600; cursor:pointer; transition: all .12s; white-space:nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--brand); border-color: var(--brand); color:#fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { background: var(--red); border-color: var(--red); color:#fff; }
.btn-danger:hover { filter: brightness(.94); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }
.btn:disabled { opacity:.5; cursor: not-allowed; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border:1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 18px; }
.card-head { display:flex; align-items:center; gap:10px; padding: 14px 18px; border-bottom:1px solid var(--border); }
.card-head h3 { font-size: 14.5px; }
.card-head .spacer { flex:1; }
.card-head .sub { color: var(--text-muted); font-size: 12.5px; font-weight:500; }

.grid { display:grid; gap:16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px){ .grid-4 { grid-template-columns: repeat(2,1fr);} .grid-3{grid-template-columns:repeat(2,1fr);} }
@media (max-width: 720px){ .grid-2,.grid-3,.grid-4 { grid-template-columns: 1fr; } }

/* ---------- KPI ---------- */
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--text-muted); font-size: 12.5px; font-weight:600; text-transform:uppercase; letter-spacing:.03em; }
.kpi .value { font-size: 27px; font-weight: 700; margin-top: 6px; letter-spacing:-.01em; }
.kpi .meta { font-size: 12.5px; margin-top: 4px; color: var(--text-soft); display:flex; align-items:center; gap:6px; }
.kpi .ico-box { float:right; width:40px; height:40px; border-radius:10px; display:flex; align-items:center; justify-content:center; font-size:18px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x:auto; }
table.tbl { width:100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align:left; padding: 10px 14px; color: var(--text-muted); font-weight:600; font-size:11.5px;
  text-transform: uppercase; letter-spacing:.04em; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space:nowrap;
}
table.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tbody tr { transition: background .1s; }
table.tbl tbody tr:hover { background: var(--brand-50); }
table.tbl .row-click { cursor:pointer; }
.t-strong { font-weight: 600; color: var(--text); }
.t-sub { color: var(--text-muted); font-size: 12px; }
.t-right { text-align: right; }
.t-num { font-variant-numeric: tabular-nums; }

.empty { text-align:center; padding: 44px 20px; color: var(--text-muted); }
.empty .e-ico { font-size: 34px; margin-bottom: 8px; opacity:.6; }

/* ---------- Badges / pills ---------- */
.badge { display:inline-flex; align-items:center; gap:5px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight:600; line-height: 1.4; white-space:nowrap; }
.badge .b-dot { width:6px; height:6px; border-radius:50%; background: currentColor; }
.b-green { color: var(--green); background: var(--green-bg); }
.b-amber { color: var(--amber); background: var(--amber-bg); }
.b-red   { color: var(--red);   background: var(--red-bg); }
.b-blue  { color: var(--blue);  background: var(--blue-bg); }
.b-purple{ color: var(--purple);background: var(--purple-bg); }
.b-slate { color: var(--slate); background: var(--slate-bg); }
.b-teal  { color: var(--teal);  background: var(--teal-bg); }

.chip { display:inline-flex; align-items:center; gap:6px; padding: 4px 10px; border-radius: 8px; background: var(--surface-2); border:1px solid var(--border); font-size:12.5px; font-weight:500; }
.chip.active { background: var(--brand); color:#fff; border-color: var(--brand); }
.chip-row { display:flex; flex-wrap:wrap; gap:8px; }

/* ---------- Forms ---------- */
.form-grid { display:grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display:block; font-size: 12.5px; font-weight:600; color: var(--text-soft); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width:100%; padding: 8px 11px; border:1px solid var(--border-strong); border-radius: 8px; font-size: 13.5px;
  font-family: inherit; background:#fff; color: var(--text);
}
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field select:focus, .field textarea:focus { outline:none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-light); }
.field .hint { font-size: 11.5px; color: var(--text-muted); margin-top:4px; }
.field.required label::after { content:" *"; color: var(--red); }

.toolbar { display:flex; align-items:center; gap:10px; flex-wrap:wrap; margin-bottom: 16px; }
.toolbar .spacer { flex:1; }
.filter-input { padding: 7px 11px; border:1px solid var(--border-strong); border-radius: 8px; font-size:13px; background:#fff; }
.filter-input:focus { outline:none; border-color: var(--brand); }

.page-head { display:flex; align-items:flex-start; gap:14px; margin-bottom: 18px; }
.page-head .spacer { flex:1; }
.page-head h2 { font-size: 20px; }
.page-head p { margin: 3px 0 0; color: var(--text-muted); font-size: 13px; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset:0; background: rgba(17,24,39,.5); display:flex; align-items:flex-start; justify-content:center; z-index: 100; padding: 40px 16px; overflow-y:auto; animation: fade .12s ease; }
@keyframes fade { from { opacity:0 } to { opacity:1 } }
.modal {
  background:#fff; border-radius: 14px; width: 100%; max-width: 560px; box-shadow: var(--shadow-lg); animation: pop .14s ease;
}
.modal.lg { max-width: 760px; }
.modal.sm { max-width: 420px; }
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity:.6 } to { transform:none; opacity:1 } }
.modal-head { display:flex; align-items:center; padding: 16px 20px; border-bottom:1px solid var(--border); }
.modal-head h3 { font-size: 16px; }
.modal-head .x { margin-left:auto; cursor:pointer; color: var(--text-muted); font-size: 20px; line-height:1; padding:4px; border-radius:6px; }
.modal-head .x:hover { background: var(--surface-2); color: var(--text); }
.modal-body { padding: 20px; max-height: 68vh; overflow-y:auto; }
.modal-foot { display:flex; gap:10px; justify-content:flex-end; padding: 14px 20px; border-top:1px solid var(--border); background: var(--surface-2); border-radius: 0 0 14px 14px; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: 22px; right: 22px; z-index: 200; display:flex; flex-direction:column; gap:10px; }
.toast { background:#111827; color:#fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13.5px; display:flex; align-items:center; gap:10px; animation: slidein .18s ease; max-width: 360px; }
@keyframes slidein { from { transform: translateX(20px); opacity:0 } to { transform:none; opacity:1 } }
.toast.success { background:#065f46; }
.toast.error { background:#991b1b; }
.toast .t-ico { font-size:16px; }

/* ---------- Misc ---------- */
.row { display:flex; align-items:center; gap:10px; }
.between { display:flex; align-items:center; justify-content:space-between; gap:10px; }
.muted { color: var(--text-muted); }
.soft { color: var(--text-soft); }
.mt-0 { margin-top:0 } .mt-8{margin-top:8px} .mt-16{margin-top:16px} .mt-24{margin-top:24px}
.mb-0 { margin-bottom:0 } .mb-8{margin-bottom:8px} .mb-16{margin-bottom:16px}
.tabs { display:flex; gap:4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tabs button { background:none; border:none; padding: 10px 14px; font-size: 13.5px; font-weight:600; color: var(--text-muted); cursor:pointer; border-bottom: 2px solid transparent; margin-bottom:-1px; }
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

.progress { height: 7px; background: var(--surface-2); border-radius: 999px; overflow:hidden; }
.progress > span { display:block; height:100%; background: var(--brand); border-radius:999px; }

.avatar-sm { width:28px; height:28px; border-radius:50%; background: var(--slate-bg); color: var(--slate); display:inline-flex; align-items:center; justify-content:center; font-weight:700; font-size:11px; }
.stack { display:flex; flex-direction:column; gap:2px; }

.list-item { display:flex; align-items:center; gap:12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom:none; }
.dot-led { width:9px; height:9px; border-radius:50%; flex:none; }

.detail-grid { display:grid; grid-template-columns: 140px 1fr; gap: 9px 16px; font-size:13.5px; }
.detail-grid dt { color: var(--text-muted); font-weight:600; }
.detail-grid dd { margin:0; color: var(--text); }

.kanban { display:grid; grid-template-columns: repeat(6, minmax(180px,1fr)); gap: 12px; overflow-x:auto; padding-bottom: 6px; }
.kanban .col { background: var(--surface-2); border-radius: 10px; padding: 10px; min-height: 120px; }
.kanban .col h4 { font-size: 12px; text-transform: uppercase; letter-spacing:.04em; color: var(--text-soft); display:flex; justify-content:space-between; margin-bottom: 8px; }
.kanban .lead-card { background:#fff; border:1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom:8px; box-shadow: var(--shadow-sm); cursor:pointer; }
.kanban .lead-card:hover { border-color: var(--brand); }
.kanban .lead-card .nm { font-weight:600; font-size:13px; }

.bar-chart { display:flex; align-items:flex-end; gap:10px; height: 180px; padding-top: 10px; }
.bar-chart .bar-col { flex:1; display:flex; flex-direction:column; align-items:center; gap:6px; justify-content:flex-end; height:100%; }
.bar-chart .bar { width: 70%; max-width: 38px; background: var(--brand); border-radius: 6px 6px 0 0; transition: height .4s; min-height: 2px; }
.bar-chart .bar-lbl { font-size: 11px; color: var(--text-muted); }
.bar-chart .bar-val { font-size: 11px; font-weight:600; }

.legend { display:flex; flex-wrap:wrap; gap: 12px; margin-top: 14px; font-size: 12.5px; }
.legend span { display:flex; align-items:center; gap:6px; }
.legend i { width:11px; height:11px; border-radius:3px; display:inline-block; }

.inline-stat { display:flex; gap: 22px; flex-wrap:wrap; }
.inline-stat > div .v { font-size: 19px; font-weight:700; }
.inline-stat > div .l { font-size: 12px; color: var(--text-muted); }

hr.sep { border:none; border-top:1px solid var(--border); margin: 16px 0; }

.banner { padding: 11px 14px; border-radius: 9px; font-size: 13px; display:flex; gap:10px; align-items:center; }
.banner.info { background: var(--blue-bg); color: #1e40af; }
.banner.warn { background: var(--amber-bg); color: #92400e; }

.tag-link { cursor:pointer; color: var(--brand); font-weight:600; }
.tag-link:hover { text-decoration: underline; }

.scroll-y { max-height: 360px; overflow-y:auto; }

/* ---------- Mobile / responsive ---------- */
.ham-btn { display: none; }
.nav-scrim { display: none; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: var(--sidebar-w);
    transform: translateX(-100%); transition: transform .22s ease; z-index: 60;
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .nav-scrim.show { display: block; position: fixed; inset: 0; background: rgba(17,24,39,.45); z-index: 55; animation: fade .12s ease; }
  .ham-btn { display: flex; }
  .header { padding: 0 12px; gap: 8px; }
  .search-box { display: none; }
  .content { padding: 14px; }
  .page-head { flex-wrap: wrap; }
  .page-head h2 { font-size: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .modal-body { max-height: 74vh; }
  .kpi .value { font-size: 23px; }
  .detail-grid { grid-template-columns: 110px 1fr; }
}

@media (max-width: 480px) {
  .header .page-title { font-size: 15px; }
  .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 11px; }
}
