/* ============ Counsel CRM — design system ============ */
:root {
  --brand: #1e3a5f;
  --brand-600: #16304f;
  --brand-50: #eef3f9;
  --ink: #1c2430;
  --ink-2: #46536a;
  --ink-3: #7a869c;
  --line: #e3e8ef;
  --line-2: #d3dae4;
  --bg: #f4f6f9;
  --card: #ffffff;
  --ok: #178a50; --ok-bg: #e5f5ec;
  --warn: #a05a00; --warn-bg: #fdf1de;
  --err: #c0392b; --err-bg: #fdecea;
  --info: #1d6fb8; --info-bg: #e8f2fb;
  --violet: #6b46c1; --violet-bg: #efe9fb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .14);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { margin: 0 0 .5rem; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.02rem; }
code { background: var(--brand-50); padding: .1rem .35rem; border-radius: 4px; font-size: .85em; }
.muted { color: var(--ink-3); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.sr-only { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); }
:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; border-radius: 4px; }

/* ---------- shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 232px; background: var(--brand); color: #dbe4f0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; transition: margin-left .18s ease; }
.sidebar.hidden { margin-left: -232px; }
.side-brand { display: flex; gap: .6rem; align-items: center; padding: 1rem .9rem; border-bottom: 1px solid rgba(255,255,255,.09); }
.side-logo { width: 34px; height: 34px; border-radius: 8px; background: rgba(255,255,255,.14); display: grid; place-items: center; color: #fff; }
.side-firm { font-weight: 700; color: #fff; font-size: .95rem; line-height: 1.15; }
.side-app { font-size: .72rem; color: rgba(255,255,255,.6); }
.side-nav { flex: 1; overflow-y: auto; padding: .6rem .55rem 1rem; }
.side-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: rgba(255,255,255,.42); margin: .9rem .6rem .3rem; }
.side-link { display: flex; align-items: center; gap: .55rem; padding: .44rem .6rem; border-radius: 7px; color: rgba(255,255,255,.82); font-size: .9rem; margin-bottom: 1px; }
.side-link:hover { background: rgba(255,255,255,.08); text-decoration: none; color: #fff; }
.side-link.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.side-link .icon { flex-shrink: 0; opacity: .9; }
.side-foot { border-top: 1px solid rgba(255,255,255,.09); padding: .7rem .8rem; }
.side-user { display: flex; gap: .55rem; align-items: center; }
.side-usermeta { min-width: 0; }
.side-username { color: #fff; font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-usertitle { color: rgba(255,255,255,.55); font-size: .72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: rgba(255,255,255,.2); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .85rem; flex-shrink: 0; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 40; background: var(--card); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: .8rem; padding: .55rem 1.1rem; }
.top-search { flex: 1; max-width: 560px; display: flex; align-items: center; gap: .5rem; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .38rem .7rem; color: var(--ink-3); }
.top-search input { border: 0; background: transparent; outline: none; flex: 1; font-size: .9rem; color: var(--ink); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: .45rem; }
.content { padding: 1.2rem 1.4rem 3rem; max-width: 1500px; width: 100%; }
@media (max-width: 1024px) {
  .sidebar { position: fixed; z-index: 60; margin-left: -232px; }
  .sidebar.open { margin-left: 0; box-shadow: var(--shadow-lg); }
  .content { padding: 1rem .8rem 3rem; }
}

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--line-2); background: var(--card); color: var(--ink); border-radius: 8px; padding: .48rem .9rem; font-size: .88rem; font-weight: 550; cursor: pointer; line-height: 1.1; white-space: nowrap; }
.btn:hover { border-color: var(--line-2); background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); }
.btn-danger { color: var(--err); border-color: #efc9c5; }
.btn-danger:hover { background: var(--err-bg); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: .32rem .65rem; font-size: .82rem; border-radius: 7px; }
.btn-lg { padding: .65rem 1.2rem; font-size: .95rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { position: relative; display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { background: var(--bg); color: var(--ink); }
.avatar-sm { width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: #fff; font-weight: 700; font-size: .8rem; display: grid; place-items: center; border: 0; cursor: pointer; }
.badge-count { position: absolute; top: 2px; right: 0; background: var(--err); color: #fff; font-size: .62rem; font-weight: 700; border-radius: 8px; padding: .05rem .32rem; }
.menu-btn { display: flex; align-items: center; gap: .5rem; width: 100%; border: 0; background: none; padding: .45rem .9rem; font-size: .88rem; color: var(--ink); cursor: pointer; text-align: left; }
.menu-btn:hover { background: var(--bg); }

/* ---------- dropdowns ---------- */
.dropdown { position: relative; }
.dropdown-menu { display: none; position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-lg); z-index: 70; padding: .35rem; }
.dropdown-right { }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a, .dropdown-menu .menu-item { display: flex; align-items: center; gap: .5rem; padding: .45rem .65rem; border-radius: 7px; font-size: .88rem; color: var(--ink); }
.dropdown-menu a:hover { background: var(--bg); text-decoration: none; }
.dropdown-menu a.disabled { opacity: .4; pointer-events: none; }
.dropdown-head { padding: .5rem .7rem; font-size: .8rem; color: var(--ink-2); border-bottom: 1px solid var(--line); margin-bottom: .3rem; }
.dropdown-sep { height: 1px; background: var(--line); margin: .3rem 0; }
.dropdown-wide { min-width: 320px; max-width: 380px; padding: .4rem; }
.notif-item { display: block; padding: .5rem .6rem; border-radius: 7px; }
.notif-item:hover { background: var(--bg); text-decoration: none; }
.notif-item.unread { background: var(--brand-50); }
.notif-title { font-size: .85rem; font-weight: 600; color: var(--ink); }
.notif-body { font-size: .8rem; margin-top: .1rem; }
.notif-time { font-size: .72rem; color: var(--ink-3); margin-top: .15rem; }

/* ---------- cards / grids ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 1rem 1.1rem; }
.card-head { display: flex; align-items: center; gap: .6rem; padding: .8rem 1.1rem; border-bottom: 1px solid var(--line); }
.card-head h2, .card-head h3 { margin: 0; }
.card-head .spacer { flex: 1; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.page-head { display: flex; align-items: center; gap: .8rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .spacer { flex: 1; }
.page-sub { color: var(--ink-3); font-size: .9rem; margin-top: .15rem; }

/* ---------- KPIs ---------- */
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); }
.kpi-label { font-size: .78rem; color: var(--ink-3); display: flex; align-items: center; gap: .4rem; }
.kpi-value { font-size: 1.55rem; font-weight: 700; margin-top: .25rem; letter-spacing: -.02em; }
.kpi-delta { font-size: .76rem; margin-top: .2rem; color: var(--ink-3); }
.kpi-delta.up { color: var(--ok); } .kpi-delta.down { color: var(--err); }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tbl th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 650; padding: .6rem .8rem; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fafbfd; }
.tbl td { padding: .62rem .8rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:hover { background: #f8fafc; }
.tbl tr.clickable { cursor: pointer; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .row-actions { display: flex; gap: .2rem; justify-content: flex-end; }
.tbl .empty { text-align: center; color: var(--ink-3); padding: 2.2rem 1rem; }
.bulkbar { display: flex; align-items: center; gap: .6rem; padding: .5rem .8rem; background: var(--brand-50); border-bottom: 1px solid var(--line); font-size: .85rem; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: .3rem; font-size: .74rem; font-weight: 600; border-radius: 999px; padding: .16rem .6rem; background: var(--bg); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge-warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge-err { background: var(--err-bg); color: var(--err); border-color: transparent; }
.badge-info { background: var(--info-bg); color: var(--info); border-color: transparent; }
.badge-violet { background: var(--violet-bg); color: var(--violet); border-color: transparent; }
.badge-brand { background: var(--brand-50); color: var(--brand); border-color: transparent; }
.tag-chip { display: inline-flex; align-items: center; font-size: .72rem; font-weight: 600; border-radius: 6px; padding: .12rem .45rem; color: #fff; background: #94a3b8; }
.strength { color: var(--ink-3); letter-spacing: .1em; font-size: .8rem; }
.strength .on { color: #e8a13a; }

/* ---------- forms ---------- */
.form-grid { display: grid; gap: .85rem 1rem; }
.form-2 { grid-template-columns: 1fr 1fr; }
.form-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) { .form-2, .form-3 { grid-template-columns: 1fr; } }
.field label { display: block; font-size: .8rem; font-weight: 600; color: var(--ink-2); margin-bottom: .3rem; }
.field .hint { font-size: .75rem; color: var(--ink-3); margin-top: .25rem; }
.field .error-msg { font-size: .78rem; color: var(--err); margin-top: .25rem; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line-2); border-radius: 8px; padding: .48rem .65rem; font-size: .9rem; font-family: inherit; background: #fff; color: var(--ink); }
.input:focus { outline: none; border-color: var(--info); box-shadow: 0 0 0 3px rgba(29,111,184,.12); }
.input[aria-disabled="true"] { background: var(--bg); color: var(--ink-3); }
textarea.input { min-height: 84px; resize: vertical; }
.checkline { display: flex; align-items: center; gap: .5rem; font-size: .88rem; }
.checkline input { width: 16px; height: 16px; }
.form-actions { display: flex; gap: .6rem; justify-content: flex-end; padding-top: .6rem; margin-top: 1rem; border-top: 1px solid var(--line); }

/* ---------- alerts ---------- */
.alert { display: flex; gap: .55rem; align-items: flex-start; border-radius: 8px; padding: .6rem .85rem; font-size: .88rem; margin-bottom: .8rem; border: 1px solid transparent; }
.alert-success { background: var(--ok-bg); color: #116240; }
.alert-error { background: var(--err-bg); color: #8f2b21; }
.alert-warn { background: var(--warn-bg); color: #7a4500; }
.alert-info { background: var(--info-bg); color: #17518a; }
.banner { display: flex; gap: .5rem; align-items: center; border-radius: 8px; padding: .55rem .8rem; font-size: .85rem; margin-bottom: .8rem; }
.banner-confidential { background: var(--err-bg); color: var(--err); font-weight: 600; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: .15rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tab { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem .8rem; font-size: .88rem; font-weight: 550; color: var(--ink-2); border: 0; background: none; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 650; }
.tab .count { font-size: .72rem; background: var(--bg); border-radius: 999px; padding: .05rem .45rem; color: var(--ink-3); }

/* ---------- kanban ---------- */
.kanban { display: flex; gap: .8rem; overflow-x: auto; padding-bottom: .6rem; align-items: flex-start; }
.kanban-col { min-width: 264px; width: 264px; background: #eef1f6; border-radius: 10px; padding: .55rem; max-height: calc(100vh - 260px); display: flex; flex-direction: column; }
.kanban-col.drag-over { outline: 2px dashed var(--info); outline-offset: -2px; }
.kanban-head { display: flex; align-items: center; gap: .45rem; padding: .25rem .35rem .55rem; font-size: .8rem; font-weight: 700; color: var(--ink-2); }
.kanban-head .dot { width: 9px; height: 9px; border-radius: 50%; }
.kanban-head .meta { margin-left: auto; font-weight: 500; color: var(--ink-3); font-size: .74rem; }
.kanban-body { overflow-y: auto; display: flex; flex-direction: column; gap: .45rem; min-height: 40px; }
.kanban-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: .55rem .65rem; box-shadow: var(--shadow); cursor: grab; font-size: .84rem; }
.kanban-card:active { cursor: grabbing; }
.kanban-card .kc-title { font-weight: 650; color: var(--ink); }
.kanban-card a.kc-title { color: var(--ink); }
.kanban-card a.kc-title:hover { color: var(--brand); text-decoration: none; }
.kanban-card .kc-sub { color: var(--ink-3); font-size: .76rem; margin-top: .15rem; }
.kanban-card .kc-foot { display: flex; gap: .4rem; margin-top: .45rem; align-items: center; }
.kanban-card.overdue { border-left: 3px solid var(--err); }

/* ---------- timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: .7rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.tl-icon { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-50); color: var(--brand); display: grid; place-items: center; flex-shrink: 0; }
.tl-body { min-width: 0; flex: 1; }
.tl-title { font-size: .88rem; font-weight: 600; }
.tl-meta { font-size: .76rem; color: var(--ink-3); margin-top: .1rem; }
.tl-content { font-size: .85rem; color: var(--ink-2); margin-top: .2rem; white-space: pre-line; }

/* ---------- modal / drawer ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 90; display: none; align-items: flex-start; justify-content: center; padding: 5vh 1rem; overflow-y: auto; }
.modal-backdrop.open { display: flex; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; box-shadow: var(--shadow-lg); }
.modal-lg { max-width: 920px; }
.modal-head { display: flex; align-items: center; padding: .9rem 1.1rem; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; flex: 1; }
.modal-body { padding: 1rem 1.1rem; }
.modal-foot { display: flex; justify-content: flex-end; gap: .6rem; padding: .8rem 1.1rem; border-top: 1px solid var(--line); }

/* ---------- toasts ---------- */
.toasts { position: fixed; bottom: 1.2rem; right: 1.2rem; z-index: 120; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: var(--ink); color: #fff; border-radius: 9px; padding: .6rem .9rem; font-size: .86rem; box-shadow: var(--shadow-lg); display: flex; gap: .5rem; align-items: center; animation: toast-in .18s ease; max-width: 360px; }
.toast.error { background: #7f1d1d; }
.toast.success { background: #14532d; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- pagination ---------- */
.pagination { display: flex; gap: .3rem; align-items: center; margin-top: 1rem; flex-wrap: wrap; }
.pagination a, .pagination span { display: inline-grid; place-items: center; min-width: 32px; height: 32px; padding: 0 .5rem; border: 1px solid var(--line); border-radius: 7px; font-size: .84rem; color: var(--ink-2); background: #fff; }
.pagination a:hover { text-decoration: none; border-color: var(--line-2); }
.pagination .active { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 650; }
.pagination .ellipsis { border: 0; background: none; }

/* ---------- filters bar ---------- */
.filters { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; padding: .6rem .8rem; background: #fafbfd; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .9rem; }
.filters .input { width: auto; min-width: 130px; padding: .34rem .55rem; font-size: .84rem; }
.filters label { font-size: .78rem; color: var(--ink-3); }
.saved-views { display: flex; gap: .35rem; align-items: center; }
.saved-views .badge { cursor: pointer; }
.saved-views .badge.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- misc ---------- */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--ink-3); }
.empty-state .icon { opacity: .4; margin-bottom: .6rem; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: .4rem .8rem; font-size: .88rem; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-weight: 520; word-break: break-word; }
@media (max-width: 640px) { .kv { grid-template-columns: 1fr; } .kv dt { margin-top: .4rem; } }
.avatar-row { display: flex; }
.avatar-row .avatar { width: 26px; height: 26px; font-size: .7rem; border: 2px solid #fff; margin-left: -7px; background: var(--brand); color: #fff; }
.avatar-row .avatar:first-child { margin-left: 0; }
.progress { height: 7px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--brand); border-radius: 999px; }
.chart-svg { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: .5rem; font-size: .78rem; color: var(--ink-2); }
.chart-legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .3rem; vertical-align: -1px; }
.divider { height: 1px; background: var(--line); margin: 1rem 0; }
.detail-head { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; }
.detail-head .dh-avatar { width: 46px; height: 46px; border-radius: 12px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 1.1rem; }
.detail-head h1 { margin: 0; }
.dh-sub { color: var(--ink-3); font-size: .9rem; display: flex; gap: .8rem; flex-wrap: wrap; }
.actions-row { display: flex; gap: .45rem; flex-wrap: wrap; margin-bottom: 1rem; }
.stat-strip { display: flex; gap: 1.4rem; flex-wrap: wrap; padding: .7rem 1rem; background: var(--brand-50); border-radius: 8px; margin-bottom: 1rem; }
.stat-strip .ss { font-size: .8rem; color: var(--ink-2); }
.stat-strip .ss b { display: block; font-size: 1.05rem; color: var(--ink); }
.login-fail { animation: shake .3s ease; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.demo-hint { margin-top: 1rem; font-size: .78rem; color: var(--ink-3); background: var(--bg); border-radius: 8px; padding: .6rem .8rem; line-height: 1.5; }

/* ---------- auth ---------- */
.auth-body { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, var(--brand) 0%, #0e1c2e 60%); padding: 1.2rem; }
.auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: 14px; padding: 1.8rem; box-shadow: var(--shadow-lg); }
.auth-brand { text-align: center; margin-bottom: 1.2rem; }
.auth-logo { width: 46px; height: 46px; margin: 0 auto .7rem; border-radius: 12px; background: var(--brand); color: #fff; display: grid; place-items: center; }
.auth-brand h1 { font-size: 1.25rem; margin-bottom: .2rem; }
.auth-card .form-grid { margin-bottom: 1rem; }
.mfa-code { letter-spacing: .4em; font-size: 1.3rem; text-align: center; font-variant-numeric: tabular-nums; }
.recovery-list { font-family: ui-monospace, monospace; background: var(--bg); border-radius: 8px; padding: .8rem; font-size: .8rem; line-height: 1.9; word-break: break-all; }
.qr-box { display: grid; place-items: center; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: .8rem; margin-bottom: .8rem; }
.qr-box svg { max-width: 190px; }
.sesh-table td, .sesh-table th { font-size: .82rem; }
.device-cur { color: var(--ok); font-weight: 700; }
