:root {
  --nav: #213343;
  --nav-hover: #2e475d;
  --nav-text: #cbd6e2;
  --bg: #f5f8fa;
  --surface: #ffffff;
  --border: #dfe3eb;
  --border-strong: #cbd6e2;
  --text: #33475b;
  --text-muted: #516f90;
  --text-soft: #7c98b6;
  --accent: #ff5c35;
  --accent-hover: #ff7a59;
  --link: #0091ae;
  --teal-bg: #e5f5f8;
  --success: #00a4bd;
  --won: #00bda5;
  --lost: #f2545b;
  --warn: #f5c26b;
  --shadow: 0 1px 24px 0 rgba(0, 0, 0, .08);
  --radius: 4px;
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Lexend Deca", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text); background: var(--bg); line-height: 1.45;
}
a { color: var(--link); text-decoration: none; font-weight: 500; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; color: var(--text); }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Layout ---------- */
.shell { display: flex; height: 100vh; }
.sidebar {
  width: 216px; flex-shrink: 0; background: var(--nav); color: var(--nav-text);
  display: flex; flex-direction: column; padding: 12px 8px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 8px 10px 20px; color: #fff; font-weight: 600; font-size: 16px; }
.brand img { width: 28px; height: 28px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 6px;
  color: var(--nav-text); font-weight: 400; margin-bottom: 2px;
}
.nav-item:hover { background: var(--nav-hover); text-decoration: none; color: #fff; }
.nav-item.active { background: var(--nav-hover); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-sep { height: 1px; background: rgba(255,255,255,.08); margin: 10px 4px; }
.sidebar .spacer { flex: 1; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 56px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 24px; flex-shrink: 0;
}
.search { position: relative; flex: 1; max-width: 520px; }
.search input {
  width: 100%; padding: 8px 12px 8px 36px; border: 1px solid var(--border-strong); border-radius: 18px;
  background: var(--bg); outline: none;
}
.search input:focus { border-color: var(--link); background: #fff; box-shadow: 0 0 0 3px rgba(0,145,174,.15); }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; color: var(--text-soft); }
.search-results {
  position: absolute; top: 42px; left: 0; right: 0; background: #fff; border: 1px solid var(--border);
  border-radius: 6px; box-shadow: var(--shadow); z-index: 50; max-height: 420px; overflow: auto;
}
.search-results a { display: flex; gap: 12px; align-items: center; padding: 9px 14px; color: var(--text); font-weight: 400; }
.search-results a:hover, .search-results a.sel { background: var(--teal-bg); text-decoration: none; }
.search-results .type { font-size: 11px; text-transform: uppercase; color: var(--text-soft); width: 82px; flex-shrink: 0; }
.search-results .empty { padding: 14px; color: var(--text-soft); }
.topbar .user { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--text-muted); }
.content { flex: 1; overflow: auto; }
.page { padding: 24px 32px 48px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .count { color: var(--text-soft); font-size: 13px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 3px; cursor: pointer;
  border: 1px solid var(--border-strong); background: #fff; color: var(--text); font-weight: 500; font-size: 13px;
  white-space: nowrap;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.secondary { border-color: var(--accent); color: var(--accent); }
.btn.secondary:hover { background: #fff1ee; }
.btn.danger { color: var(--lost); border-color: var(--lost); }
.btn.danger:hover { background: #fdeced; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--link); padding: 6px 8px; }
.btn.ghost:hover { background: var(--teal-bg); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn svg { width: 15px; height: 15px; }
.input, select.input, textarea.input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 3px; background: #f5f8fa; outline: none;
}
.input:focus { border-color: var(--link); background: #fff; box-shadow: 0 0 0 3px rgba(0,145,174,.15); }
textarea.input { min-height: 90px; resize: vertical; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; }
label.field > span .req { color: var(--lost); }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 3px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 6px 12px; cursor: pointer; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--border-strong); }
.seg button.on { background: var(--teal-bg); color: var(--link); font-weight: 600; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-body { padding: 16px 18px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 16px; }
.kpi { padding: 16px 18px; }
.kpi .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 26px; font-weight: 600; margin-top: 4px; }
.kpi .sub { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.dash-grid { grid-template-columns: 2fr 1fr; }
@media (max-width: 1100px) { .dash-grid { grid-template-columns: 1fr; } }

/* ---------- Charts ---------- */
.funnel-row { display: grid; grid-template-columns: 150px 1fr 110px; gap: 12px; align-items: center; margin-bottom: 10px; font-size: 13px; }
.funnel-row .bar { height: 22px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.funnel-row .bar > div { height: 100%; border-radius: 3px; min-width: 2px; }
.funnel-row .num { text-align: right; font-variant-numeric: tabular-nums; }
.bars { display: flex; align-items: flex-end; gap: 14px; height: 160px; padding-top: 10px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bars .col .b { width: 100%; max-width: 48px; background: var(--won); border-radius: 3px 3px 0 0; min-height: 2px; }
.bars .col .m { font-size: 11px; color: var(--text-soft); margin-top: 6px; }
.bars .col .v { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; white-space: nowrap; }

/* ---------- Tables ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; padding: 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.toolbar .input { width: auto; min-width: 160px; }
.toolbar .search-in { min-width: 260px; }
.table-wrap { overflow: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  background: var(--bg); text-align: left; font-weight: 600; font-size: 12px; text-transform: uppercase;
  letter-spacing: .03em; color: var(--text); padding: 10px 14px; border-bottom: 1px solid var(--border-strong);
  border-right: 1px solid var(--border); white-space: nowrap; cursor: pointer; user-select: none; position: sticky; top: 0;
}
table.data th:last-child { border-right: 0; }
table.data th .arrow { color: var(--link); margin-left: 4px; }
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
table.data tbody tr:hover { background: #fafcfd; }
.empty-state { padding: 56px 20px; text-align: center; color: var(--text-muted); }
.empty-state h3 { margin-bottom: 6px; }
.name-cell { display: flex; align-items: center; gap: 10px; }

/* ---------- Avatars & tags ---------- */
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; color: #fff; flex-shrink: 0; background: var(--text-soft);
}
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }
.avatar.square { border-radius: 6px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 3px; font-size: 12px; font-weight: 500; background: var(--bg); border: 1px solid var(--border); }
.tag.new { background: #eaf0f6; } .tag.qualified { background: #e5f5f8; border-color: #b0e1ea; }
.tag.proposal { background: #fef8f0; border-color: #fae0b5; } .tag.negotiation { background: #fff1ee; border-color: #ffc6b6; }
.tag.won { background: #e5f8f6; border-color: #7fded2; color: #00806f; } .tag.lost { background: #fdeced; border-color: #f8a9ad; color: #c2333a; }
.tag.planned { background: #eaf0f6; } .tag.in_progress { background: #e5f5f8; border-color: #b0e1ea; }
.tag.on_hold { background: #fef8f0; border-color: #fae0b5; } .tag.done { background: #e5f8f6; border-color: #7fded2; color: #00806f; }
.tag.cancelled { background: #fdeced; border-color: #f8a9ad; color: #c2333a; }
.tag.high { color: #c2333a; } .tag.low { color: var(--text-soft); }
.progress { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; width: 90px; display: inline-block; vertical-align: middle; }
.progress > div { height: 100%; background: var(--success); }

/* ---------- Board ---------- */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; min-height: calc(100vh - 200px); }
.board-col { width: 272px; flex-shrink: 0; background: #eaf0f6; border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 190px); }
.board-col-head { padding: 12px 14px 8px; }
.board-col-head .t { display: flex; justify-content: space-between; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.board-col-head .t .n { background: #fff; border-radius: 10px; padding: 0 8px; font-weight: 500; }
.board-col-head .s { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.board-col-body { padding: 6px 8px 10px; overflow-y: auto; flex: 1; min-height: 80px; }
.board-col.drag-over { background: #d6e4ef; outline: 2px dashed var(--link); outline-offset: -4px; }
.deal-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 8px;
  cursor: grab; box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.deal-card:hover { border-color: var(--border-strong); box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.deal-card.dragging { opacity: .5; }
.deal-card .n { font-weight: 600; color: var(--link); margin-bottom: 4px; display: block; }
.deal-card .meta { font-size: 12px; color: var(--text-muted); display: flex; flex-direction: column; gap: 2px; }
.deal-card .foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 12px; }
.board-col-foot { border-top: 1px solid var(--border-strong); padding: 8px 14px; font-size: 12px; color: var(--text-muted); }

/* ---------- Record page ---------- */
.record { display: grid; grid-template-columns: 320px 1fr 320px; height: calc(100vh - 56px); }
@media (max-width: 1200px) {
  .record { grid-template-columns: 300px 1fr; height: auto; min-height: calc(100vh - 56px); }
  .record .left, .record .center { overflow: visible; }
  .record .right { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--border); overflow: visible; }
}
.record .left, .record .right { background: #fff; overflow-y: auto; }
.record .left { border-right: 1px solid var(--border); }
.record .right { border-left: 1px solid var(--border); }
.record .center { overflow-y: auto; padding: 20px 24px; }
.rec-top { padding: 16px 20px 18px; border-bottom: 1px solid var(--border); }
.rec-top .back { font-size: 13px; display: inline-block; margin-bottom: 14px; }
.rec-ident { display: flex; gap: 14px; align-items: center; }
.rec-ident h1 { font-size: 20px; word-break: break-word; }
.rec-ident .sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.quick-actions { display: flex; justify-content: space-between; margin-top: 18px; }
.qa { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--text); background: none; border: 0; cursor: pointer; }
.qa span.i { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border-strong); display: flex; align-items: center; justify-content: center; background: var(--bg); }
.qa:hover span.i { border-color: var(--link); color: var(--link); background: var(--teal-bg); }
.qa svg { width: 15px; height: 15px; }
.section { border-bottom: 1px solid var(--border); }
.section-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; font-weight: 600; cursor: pointer; user-select: none; }
.section-head .chev { transition: transform .15s; color: var(--text-soft); }
.section.collapsed .section-head .chev { transform: rotate(-90deg); }
.section.collapsed .section-body { display: none; }
.section-body { padding: 0 20px 16px; }
.prop { padding: 6px 8px; margin: 0 -8px 4px; border-radius: 3px; cursor: pointer; border: 1px solid transparent; }
.prop:hover { border-color: var(--border-strong); }
.prop .k { font-size: 12px; color: var(--text-muted); }
.prop .v { min-height: 20px; word-break: break-word; white-space: pre-wrap; }
.prop .v.empty { color: var(--text-soft); }
.prop.editing { cursor: default; border-color: transparent; }
.prop.editing .input { margin-top: 3px; }
.assoc-item { display: flex; gap: 10px; align-items: center; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; }
.assoc-item .info { min-width: 0; flex: 1; }
.assoc-item .info a { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.assoc-item .info .s { font-size: 12px; color: var(--text-muted); }
.muted { color: var(--text-muted); }
.soft { color: var(--text-soft); font-size: 12px; }

.stage-track { display: flex; margin-bottom: 18px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.stage-track button {
  flex: 1; border: 0; padding: 10px 6px; font-size: 12px; cursor: pointer; background: #fff; color: var(--text-muted);
  border-right: 1px solid var(--border); font-weight: 500;
}
.stage-track button:last-child { border-right: 0; }
.stage-track button.past { background: #e5f5f8; color: var(--link); }
.stage-track button.cur { background: var(--link); color: #fff; }
.stage-track button.cur.won { background: var(--won); } .stage-track button.cur.lost { background: var(--lost); }
.stage-track button:hover:not(.cur) { background: var(--bg); }

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 16px; }
.tabs button { background: none; border: 0; padding: 10px 14px; cursor: pointer; font-weight: 500; color: var(--text-muted); margin-bottom: -2px; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--text); border-bottom-color: var(--text); }
.composer { padding: 14px; margin-bottom: 20px; }
.composer .row { display: flex; gap: 10px; margin-top: 10px; align-items: center; }
.timeline-month { font-size: 12px; font-weight: 600; text-transform: uppercase; color: var(--text-muted); margin: 18px 0 8px; letter-spacing: .04em; }
.act { display: flex; gap: 12px; padding: 14px 16px; margin-bottom: 10px; }
.act .ic { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: var(--bg); color: var(--text-muted); }
.act .ic svg { width: 15px; height: 15px; }
.act .ic.note { background: #fef8f0; color: #b8860b; } .act .ic.call { background: #e5f5f8; color: var(--link); }
.act .ic.email { background: #eaf0f6; color: #425b76; } .act .ic.meeting { background: #f2eef9; color: #6a4fa3; }
.act .ic.task { background: #e5f8f6; color: #00806f; }
.act .body { flex: 1; min-width: 0; }
.act .head { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.act .head .who { color: var(--text-muted); }
.act .txt { margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
.act.system { padding: 8px 16px; background: transparent; border: 0; font-size: 12px; color: var(--text-muted); }
.act.system .ic { width: 22px; height: 22px; background: transparent; }
.act .del { visibility: hidden; }
.act:hover .del { visibility: visible; }
.task-done .txt, .task-done .subj { text-decoration: line-through; color: var(--text-soft); }
.check { width: 18px; height: 18px; accent-color: var(--won); cursor: pointer; }

/* ---------- Slide-over panel ---------- */
.overlay { position: fixed; inset: 0; background: rgba(33,51,67,.45); z-index: 100; display: flex; justify-content: flex-end; animation: fade .15s; }
.panel { width: 460px; max-width: 100%; height: 100%; background: #fff; display: flex; flex-direction: column; animation: slide .2s ease-out; }
.panel-head { background: var(--nav); color: #fff; padding: 18px 22px; display: flex; justify-content: space-between; align-items: center; }
.panel-head h2 { color: #fff; }
.panel-head button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; line-height: 1; }
.panel-body { flex: 1; overflow-y: auto; padding: 22px; }
.panel-foot { border-top: 1px solid var(--border); padding: 14px 22px; display: flex; gap: 8px; }
.modal { margin: auto; width: 420px; max-width: calc(100% - 32px); background: #fff; border-radius: 6px; overflow: hidden; animation: fade .15s; }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--nav); padding: 16px; }
.auth .box { background: #fff; border-radius: 8px; padding: 36px; width: 400px; max-width: 100%; box-shadow: var(--shadow); }
.auth .brand { color: var(--text); padding: 0 0 22px; justify-content: center; font-size: 20px; }
.auth p { color: var(--text-muted); margin: 0 0 20px; text-align: center; }
.auth .btn { width: 100%; justify-content: center; padding: 10px; }
.error { color: var(--lost); font-size: 13px; margin-bottom: 12px; min-height: 18px; }

/* ---------- Misc ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--nav); color: #fff;
  padding: 10px 18px; border-radius: 4px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 200; font-size: 13px;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: var(--lost); }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { padding: 10px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: flex-start; }
.list-plain li:last-child { border-bottom: 0; }
.overdue { color: var(--lost); font-weight: 500; }
.loading { padding: 40px; text-align: center; color: var(--text-soft); }

@media (max-width: 760px) {
  .sidebar { width: 60px; padding: 12px 6px; }
  .sidebar .lbl, .brand span { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .page { padding: 16px; }
  .record { grid-template-columns: 1fr; height: auto; }
  .record .left { border-right: 0; }
  .topbar { padding: 0 12px; }
  .topbar .user .nm { display: none; }
}
