:root {
  --bg: #f6f3ef;
  --panel: #ffffff;
  --ink: #1f1a17;
  --ink-2: #57493f;
  --muted: #8c7d72;
  --line: #e9e1d9;
  --line-2: #f1ebe5;
  --brand: #c2410c;
  --brand-2: #9a3412;
  --brand-soft: #fff1e8;
  --side: #1c1714;
  --side-ink: #d9cfc6;
  --ok: #15803d;
  --ok-soft: #e8f6ec;
  --warn: #b45309;
  --warn-soft: #fef3e2;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --info: #1d4ed8;
  --info-soft: #e8efff;
  --purple: #7e22ce;
  --purple-soft: #f4e9ff;
  --r: 10px;
  --shadow: 0 1px 2px rgba(40, 25, 15, .06), 0 4px 16px rgba(40, 25, 15, .05);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }
.pre { white-space: pre-wrap; word-break: break-word; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff;
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 550; white-space: nowrap; line-height: 1.2;
}
.btn:hover { border-color: #d6c8bb; background: #fdfbf9; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--line-2); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 16px; height: 16px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], input[type=date],
input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(194, 65, 12, .12); }
textarea { resize: vertical; min-height: 70px; }
label.f { display: block; }
label.f > span { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 4px; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.check { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 20px 20px 16px; font-weight: 800; letter-spacing: 1.5px; color: #fff; font-size: 18px; }
.brand span { color: #fb923c; margin-left: 6px; font-weight: 700; letter-spacing: .5px; font-size: 13px; }
.brand small { display: block; font-size: 11px; color: #a8998c; letter-spacing: 0; font-weight: 500; margin-top: 2px; }
.nav { display: flex; flex-direction: column; padding: 4px 10px; gap: 2px; flex: 1; }
.nav a { display: flex; align-items: center; gap: 10px; color: var(--side-ink); padding: 9px 12px; border-radius: 8px; font-weight: 550; }
.nav a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; color: #fff; }
.nav a.on { background: rgba(251, 146, 60, .16); color: #fff; }
.nav a.on svg { color: #fb923c; }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .badge { margin-left: auto; }
.me { padding: 14px 16px; border-top: 1px solid rgba(255, 255, 255, .08); font-size: 13px; }
.me b { color: #fff; display: block; }
.me .row { margin-top: 8px; }
.me a { color: #fdba74; font-size: 12px; cursor: pointer; }
main { min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; padding: 16px 24px; background: var(--bg); position: sticky; top: 0; z-index: 5; border-bottom: 1px solid var(--line); }
.top h1 { font-size: 20px; flex: 1; }
.top .search { max-width: 280px; }
#view { padding: 20px 24px 60px; }

/* ---------- Panels ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.card > .hd { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line-2); }
.card > .hd h3 { font-size: 15px; flex: 1; }
.card > .bd { padding: 14px 16px; }
.card + .card { margin-top: 16px; }
.cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
.cols > div > .card + .card { margin-top: 16px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .l { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.kpi .v { font-size: 26px; font-weight: 750; margin-top: 4px; }
.kpi .s { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.kpi.alert .v { color: var(--bad); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.b-tiem_nang { background: var(--info-soft); color: var(--info); }
.b-dam_phan { background: var(--warn-soft); color: var(--warn); }
.b-bao_gia { background: var(--purple-soft); color: var(--purple); }
.b-chot { background: var(--ok-soft); color: var(--ok); }
.b-cham_lai { background: #eef2f1; color: #3f6158; }
.b-fail { background: var(--bad-soft); color: var(--bad); }
.b-red { background: var(--bad); color: #fff; }
.b-A { background: #fde68a; color: #78350f; }
.b-B { background: #e0e7ff; color: #3730a3; }
.b-C { background: #e7e5e4; color: #44403c; }

/* ---------- Tables ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 650; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fcfaf8; position: sticky; top: 0; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #fdf9f5; }
.tbl .name { font-weight: 600; }
.tbl .sub { color: var(--muted); font-size: 12px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters > * { width: auto; min-width: 140px; }
.filters input[type=search] { min-width: 220px; flex: 1; max-width: 340px; }

/* ---------- Lists ---------- */
.list > .it { display: flex; gap: 10px; align-items: flex-start; padding: 10px 16px; border-bottom: 1px solid var(--line-2); }
.list > .it:last-child { border-bottom: 0; }
.list > .it.click { cursor: pointer; }
.list > .it.click:hover { background: #fdf9f5; }
.risk-ico { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex: none; }
.k-silent { background: var(--bad); }
.k-unanswered { background: #ea580c; }
.k-opening { background: var(--purple); }
.k-untouched { background: #eab308; }
.overdue { color: var(--bad); font-weight: 600; }

/* ---------- Pipeline ---------- */
.board { display: flex; gap: 12px; align-items: flex-start; overflow-x: auto; padding-bottom: 12px; min-height: 60vh; }
.col { background: #efe9e3; border-radius: var(--r); width: 290px; flex: none; display: flex; flex-direction: column; max-height: calc(100vh - 170px); }
.col.side-col { width: 210px; background: #ece8e5; }
.col.side-col.collapsed { width: 120px; }
.col .ch { padding: 12px 12px 8px; }
.col .ch .t { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.col .ch .t .n { background: #fff; border-radius: 99px; padding: 0 8px; font-size: 12px; }
.col .ch .sum { font-size: 13px; color: var(--ink-2); margin-top: 3px; font-weight: 600; }
.col .ch .bar { height: 3px; border-radius: 3px; margin-top: 8px; }
.col .cards { padding: 4px 8px 10px; overflow-y: auto; flex: 1; min-height: 80px; }
.col.over { outline: 2px dashed var(--brand); outline-offset: -2px; background: #f8e7da; }
.kcard { background: #fff; border-radius: 8px; padding: 10px 11px; margin-bottom: 8px; box-shadow: 0 1px 2px rgba(40, 25, 15, .08); cursor: grab; border: 1px solid transparent; }
.kcard:hover { border-color: #e6cdb9; }
.kcard.dragging { opacity: .4; }
.kcard .t { font-weight: 650; line-height: 1.3; }
.kcard .m { font-size: 12px; color: var(--muted); margin-top: 3px; }
.kcard .f { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 12px; flex-wrap: wrap; }
.kcard .val { font-weight: 700; color: var(--ink); }
.av { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: #fed7aa; color: #7c2d12; font-size: 10px; font-weight: 700; margin-left: auto; flex: none; }
.more-btn { width: 100%; margin-top: 4px; }

/* ---------- Drawer & modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(28, 23, 20, .35); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); background: var(--bg); z-index: 41; display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0, 0, 0, .15); animation: slide .18s ease-out; }
@keyframes slide { from { transform: translateX(30px); opacity: .6; } }
.drawer .dh { background: #fff; padding: 16px 20px 0; border-bottom: 1px solid var(--line); }
.drawer .dh h2 { font-size: 20px; }
.drawer .db { overflow-y: auto; padding: 16px 20px 40px; flex: 1; }
.tabs { display: flex; gap: 4px; margin-top: 12px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 12px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--brand); border-color: var(--brand); }
.tabs.boxed { margin: 0 0 16px; border-bottom: 1px solid var(--line); }
.stepper { display: flex; gap: 4px; margin-top: 12px; flex-wrap: wrap; }
.stepper button { flex: 1; min-width: 86px; border: 1px solid var(--line); background: #faf7f4; padding: 7px 6px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.stepper button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.stepper button.past { background: var(--brand-soft); border-color: #fed7aa; color: var(--brand-2); }
.stepper button.lost.on { background: var(--bad); border-color: var(--bad); }
.stepper button.nurture.on { background: #3f6158; border-color: #3f6158; }

.modal-wrap { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: rgba(28, 23, 20, .4); }
.modal { background: #fff; border-radius: 12px; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal.wide { width: min(860px, 100%); }
.modal .mh { padding: 16px 20px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; }
.modal .mh h3 { flex: 1; font-size: 17px; }
.modal .mb { padding: 16px 20px; }
.modal .mf { padding: 12px 20px; border-top: 1px solid var(--line-2); display: flex; gap: 8px; justify-content: flex-end; }

.timeline .ev { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.timeline .ev:last-child { border-bottom: 0; }
.timeline .ico { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 14px; background: var(--line-2); }
.timeline .ico.inbound { background: #ffedd5; }
.timeline .ico.contact { background: var(--ok-soft); }
.timeline .ico.system, .timeline .ico.stage, .timeline .ico.assign { background: #f1f0ee; }
.timeline .meta { font-size: 12px; color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 5px 11px; cursor: pointer; font-size: 13px; font-weight: 550; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }

.osteps { display: flex; align-items: center; gap: 0; margin: 10px 0; }
.osteps .s { flex: 1; text-align: center; font-size: 11px; color: var(--muted); position: relative; padding-top: 22px; }
.osteps .s::before { content: ''; position: absolute; top: 6px; left: 50%; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: var(--line); z-index: 1; }
.osteps .s::after { content: ''; position: absolute; top: 12px; left: -50%; width: 100%; height: 2px; background: var(--line); }
.osteps .s:first-child::after { display: none; }
.osteps .s.done { color: var(--ink); font-weight: 600; }
.osteps .s.done::before, .osteps .s.done::after { background: var(--brand); }

.bars .b { display: grid; grid-template-columns: 150px 1fr 60px; gap: 8px; align-items: center; padding: 5px 0; font-size: 13px; }
.bars .track { background: var(--line-2); border-radius: 4px; height: 10px; overflow: hidden; }
.bars .fill { background: var(--brand); height: 100%; border-radius: 4px; }

.code { background: #1f1a17; color: #fde7d3; padding: 12px 14px; border-radius: 8px; font-family: Consolas, monospace; font-size: 12.5px; overflow-x: auto; white-space: pre; }
.copy-line { display: flex; gap: 6px; }
.copy-line input { font-family: Consolas, monospace; font-size: 12.5px; }
.guide ol { padding-left: 20px; margin: 8px 0; }
.guide li { margin: 4px 0; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.on { background: var(--ok); }
.status-dot.off { background: #d6cfc8; }
.note-box { background: var(--brand-soft); border: 1px solid #fed7aa; border-radius: 8px; padding: 10px 12px; font-size: 13px; }

/* ---------- Toast ---------- */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--side); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); font-weight: 550; max-width: 90vw; }
.toast.err { background: var(--bad); }
.toast.ok { background: var(--ok); }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 20% 10%, #fde3cf 0, transparent 40%), var(--bg); }
.auth .box { background: #fff; padding: 28px; border-radius: 14px; width: min(400px, 100%); box-shadow: 0 10px 40px rgba(60, 30, 10, .12); }
.auth .logo { font-weight: 800; letter-spacing: 1.5px; font-size: 22px; color: var(--brand); }
.auth .logo span { color: var(--ink); font-size: 14px; margin-left: 6px; }
.auth h2 { font-size: 18px; margin: 14px 0 4px; }
.auth form > * + * { margin-top: 12px; }
.auth .btn.primary { width: 100%; justify-content: center; padding: 10px; }
.err-msg { color: var(--bad); font-size: 13px; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .cols { grid-template-columns: 1fr; }
  .grid3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; bottom: 0; top: auto; height: auto; width: 100%; z-index: 30; flex-direction: row; }
  .brand, .me { display: none; }
  .nav { flex-direction: row; padding: 4px; overflow-x: auto; scrollbar-width: none; }
  .nav a { flex-direction: column; gap: 2px; font-size: 10px; padding: 6px 8px; min-width: 64px; text-align: center; }
  .nav .badge { position: absolute; margin: 0 0 0 18px; }
  .nav a { position: relative; }
  #view { padding: 14px 12px 90px; }
  .top { padding: 12px; }
  .top .search { display: none; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .drawer .db { padding: 12px 12px 40px; }
  .filters > * { min-width: 0; flex: 1 1 45%; }
  .bars .b { grid-template-columns: 100px 1fr 50px; }
}
