:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #15202e;
  --ink-2: #4a5768;
  --ink-3: #8592a3;
  --line: #e3e8ef;
  --line-2: #eef1f5;
  --brand: #143b6e;
  --brand-2: #1f5aa6;
  --accent: #1f5aa6;
  --accent-soft: #e8f0fb;
  --green: #1d8a5b;
  --green-soft: #e4f5ec;
  --red: #c8423b;
  --red-soft: #fbeceb;
  --amber: #b7791f;
  --amber-soft: #fdf3e1;
  --violet: #6b4fbb;
  --violet-soft: #efebfa;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 32, 46, .06), 0 4px 16px rgba(20, 32, 46, .05);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, "Noto Sans Georgian", sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--brand); color: #dbe6f5; padding: 18px 12px;
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
}
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; color: #fff; }
.logo-mark {
  width: 32px; height: 32px; border-radius: 8px; background: #fff; color: var(--brand);
  display: grid; place-items: center; font-weight: 800; font-size: 17px;
}
.logo-text { font-weight: 750; letter-spacing: .14em; font-size: 15px; }
.logo-sub { font-size: 11px; opacity: .65; letter-spacing: .04em; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: #c9d7ea; font-weight: 500; text-decoration: none;
}
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a.active { background: rgba(255,255,255,.14); color: #fff; }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.nav .badge { margin-left: auto; background: var(--red); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; }
.sidebar-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255,255,255,.12); font-size: 13px; }
.sidebar-foot .who { color: #fff; font-weight: 600; }
.sidebar-foot button { margin-top: 8px; background: none; border: 0; color: #c9d7ea; padding: 0; cursor: pointer; font: inherit; }
.sidebar-foot button:hover { color: #fff; text-decoration: underline; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 28px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.menu-btn { display: none; }
.search-wrap { position: relative; flex: 1; max-width: 520px; }
.search-wrap input { width: 100%; padding-left: 34px; background: var(--bg); border-color: transparent; }
.search-wrap input:focus { background: #fff; }
.search-wrap .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-3); width: 16px; height: 16px; }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); max-height: 420px; overflow: auto; padding: 6px;
}
.search-results .group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); padding: 8px 10px 4px; }
.search-results a { display: block; padding: 7px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; }
.search-results a:hover, .search-results a.sel { background: var(--accent-soft); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }

.page { padding: 24px 28px 48px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { font-size: 13px; color: var(--ink-3); margin-bottom: 6px; }

/* ---------- controls ---------- */
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; outline: none; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(31, 90, 166, .14); }
textarea { resize: vertical; min-height: 80px; }
.btn {
  font: inherit; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 8px;
  white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--line-2); text-decoration: none; }
.btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.primary:hover { background: var(--brand); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--line-2); }
.btn svg { width: 16px; height: 16px; }
.btn:disabled { opacity: .6; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { font: inherit; border: 0; background: none; padding: 7px 12px; cursor: pointer; color: var(--ink-2); }
.seg button.on { background: var(--accent-soft); color: var(--brand-2); font-weight: 600; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters input[type=search] { min-width: 240px; }

/* ---------- cards ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.card-head .actions { margin-left: auto; display: flex; gap: 6px; }
.card-body { padding: 16px 18px; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
.grid.detail { grid-template-columns: 340px minmax(0, 1fr); align-items: start; }
.kpi { padding: 16px 18px; }
.kpi .label { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.kpi.warn .value { color: var(--red); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafbfd; white-space: nowrap; }
td { padding: 10px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f7f9fc; }
tbody tr:last-child td { border-bottom: 0; }
.empty { padding: 36px 18px; text-align: center; color: var(--ink-3); }
.empty .btn { margin-top: 12px; }

/* ---------- pills ---------- */
.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap; text-transform: capitalize; }
.pill.lead { background: #eef1f5; color: #4a5768; }
.pill.prospect, .pill.qualified { background: var(--accent-soft); color: var(--brand-2); }
.pill.customer, .pill.won { background: var(--green-soft); color: var(--green); }
.pill.partner, .pill.negotiation { background: var(--violet-soft); color: var(--violet); }
.pill.proposal { background: var(--amber-soft); color: var(--amber); }
.pill.inactive, .pill.lost { background: var(--red-soft); color: var(--red); }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; flex: none; }
.avatar.lg { width: 52px; height: 52px; font-size: 19px; }
.person { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.tag { display: inline-block; background: var(--line-2); color: var(--ink-2); border-radius: 5px; padding: 1px 7px; font-size: 12px; margin: 0 4px 4px 0; }

/* ---------- detail ---------- */
.info-list { display: grid; grid-template-columns: 110px 1fr; gap: 9px 12px; font-size: 13.5px; }
.info-list dt { color: var(--ink-3); }
.info-list dd { margin: 0; word-break: break-word; }
.detail-title { display: flex; gap: 14px; align-items: center; padding: 18px; border-bottom: 1px solid var(--line-2); }
.notes { white-space: pre-wrap; font-size: 13.5px; color: var(--ink-2); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 0 12px; }
.tabs button { font: inherit; background: none; border: 0; padding: 12px 12px; cursor: pointer; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tabs button.on { color: var(--brand-2); border-color: var(--brand-2); font-weight: 600; }
.tabs .count { color: var(--ink-3); font-weight: 400; margin-left: 3px; }

/* ---------- timeline ---------- */
.composer { padding: 14px 18px; border-bottom: 1px solid var(--line-2); background: #fafbfd; }
.composer .types { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.composer .row { display: flex; gap: 8px; margin-top: 8px; align-items: center; flex-wrap: wrap; }
.composer input[name=subject] { width: 100%; }
.composer textarea { width: 100%; min-height: 60px; margin-top: 8px; }
.timeline { list-style: none; margin: 0; padding: 6px 0; }
.timeline li { display: flex; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line-2); }
.timeline li:last-child { border-bottom: 0; }
.t-icon { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.t-icon svg { width: 15px; height: 15px; }
.t-icon.call { background: var(--green-soft); color: var(--green); }
.t-icon.meeting { background: var(--violet-soft); color: var(--violet); }
.t-icon.email { background: var(--accent-soft); color: var(--brand-2); }
.t-icon.note { background: var(--amber-soft); color: var(--amber); }
.t-icon.task { background: var(--line-2); color: var(--ink-2); }
.t-main { flex: 1; min-width: 0; }
.t-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.t-subject { font-weight: 600; }
.t-meta { font-size: 12px; color: var(--ink-3); }
.t-body { white-space: pre-wrap; color: var(--ink-2); margin-top: 4px; font-size: 13.5px; }
.t-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .1s; }
.timeline li:hover .t-actions { opacity: 1; }
.icon-btn { background: none; border: 0; cursor: pointer; color: var(--ink-3); padding: 4px; border-radius: 6px; display: grid; place-items: center; }
.icon-btn:hover { background: var(--line-2); color: var(--ink); }
.icon-btn svg { width: 15px; height: 15px; }

/* ---------- tasks ---------- */
.task-row { display: flex; align-items: center; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--line-2); }
.task-row:last-child { border-bottom: 0; }
.task-row.done .t-subject { text-decoration: line-through; color: var(--ink-3); }
.check { width: 20px; height: 20px; border-radius: 6px; border: 2px solid #b9c3d0; background: #fff; cursor: pointer; display: grid; place-items: center; flex: none; padding: 0; }
.check:hover { border-color: var(--green); }
.check.on { background: var(--green); border-color: var(--green); color: #fff; }
.check svg { width: 12px; height: 12px; }
.due { font-size: 12px; font-weight: 600; white-space: nowrap; }
.due.overdue { color: var(--red); }
.due.today { color: var(--amber); }
.due.later { color: var(--ink-3); font-weight: 500; }

/* ---------- kanban ---------- */
.board { display: grid; grid-template-columns: repeat(6, minmax(180px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.col { background: #eaeef4; border-radius: var(--radius); display: flex; flex-direction: column; min-height: 200px; }
.col-head { padding: 12px 12px 8px; }
.col-head .name { font-weight: 650; text-transform: capitalize; display: flex; gap: 6px; align-items: center; }
.col-head .sum { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.col-body { padding: 4px 8px 10px; display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 60px; border-radius: 0 0 var(--radius) var(--radius); }
.col-body.over { background: rgba(31, 90, 166, .1); }
.deal-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: grab; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.deal-card:hover { border-color: #c5d2e3; }
.deal-card.dragging { opacity: .5; }
.deal-card .title { font-weight: 600; margin-bottom: 4px; }
.deal-card .value { font-weight: 700; font-variant-numeric: tabular-nums; }
.deal-card .foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; font-size: 12px; color: var(--ink-3); gap: 6px; }
.stage-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------- pipeline bars ---------- */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 100px 1fr 120px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .label { text-transform: capitalize; color: var(--ink-2); }
.bar-track { background: var(--line-2); height: 10px; border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; }
.bar-row .amt { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 25, 40, .45); display: grid; place-items: start center; padding: 6vh 16px; z-index: 100; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 620px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line-2); background: #fafbfd; border-radius: 0 0 12px 12px; }
.modal-foot .left { margin-right: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field label .req { color: var(--red); }
.form-error { color: var(--red); background: var(--red-soft); padding: 8px 12px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; }

/* ---------- toast ---------- */
#toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13.5px; animation: up .2s ease; max-width: 380px; }
.toast.error { background: var(--red); }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--brand) 0%, #0d2748 100%); }
.auth-card { background: #fff; border-radius: 14px; padding: 32px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.auth-card .logo { color: var(--brand); padding: 0 0 20px; }
.auth-card .logo-mark { background: var(--brand); color: #fff; }
.auth-card .logo-sub { color: var(--ink-3); opacity: 1; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card .btn { justify-content: center; padding: 10px; margin-top: 6px; }
.auth-card p { color: var(--ink-2); margin: 0 0 16px; line-height: 1.5; }

.loading { padding: 60px; text-align: center; color: var(--ink-3); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .grid.two, .grid.detail { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; width: 240px; transform: translateX(-100%); transition: transform .2s; }
  .shell.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .menu-btn { display: grid; }
  .topbar { padding: 10px 16px; }
  .page { padding: 18px 16px 40px; }
  .form-grid { grid-template-columns: 1fr; }
  .filters input[type=search] { min-width: 0; flex: 1 1 100%; }
  .hide-sm { display: none; }
  .bar-row { grid-template-columns: 80px 1fr 90px; }
  .t-actions { opacity: 1; }
}
