:root {
  --ink: #16212b;
  --muted: #64707d;
  --line: #e3e7eb;
  --bg: #f5f7f9;
  --card: #ffffff;
  --brand: #0f5c4d;
  --brand-soft: #e6f2ef;
  --amber: #b26b00;
  --amber-soft: #fff4e0;
  --red: #b3261e;
  --red-soft: #fdecea;
  --blue: #1f5fa8;
  --blue-soft: #e8f0fb;
  --green: #1d7a3a;
  --green-soft: #e7f5ec;
  --radius: 10px;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); font-size: 14px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--red); font-size: 13px; min-height: 18px; margin: 8px 0; }
h1, h2, h3 { margin: 0; }
h2 { font-size: 20px; }
h3 { font-size: 14px; margin-bottom: 10px; }
a { color: var(--brand); }

input, select, textarea {
  width: 100%; padding: 8px 10px; font: inherit; border: 1px solid #cfd6dc; border-radius: 7px; background: #fff; color: var(--ink);
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }

button { font: inherit; border-radius: 7px; border: 1px solid #cfd6dc; background: #fff; color: var(--ink); padding: 7px 14px; cursor: pointer; }
button:hover { background: #f0f3f5; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { background: #0b4a3e; }
button.danger { color: var(--red); border-color: #e9b9b5; }
button.link { border: none; background: none; color: var(--brand); padding: 0; }
button.wide { width: 100%; margin-top: 10px; padding: 10px; }
button:disabled { opacity: .5; cursor: default; }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #0f5c4d, #0a3d33); }
.login-card { background: #fff; padding: 32px; border-radius: 14px; width: 340px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card h1 { margin-top: 12px; font-size: 22px; }
.brand-mark { width: 44px; height: 44px; border-radius: 11px; background: var(--brand); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 22px; }
.brand-mark.small { width: 28px; height: 28px; font-size: 15px; border-radius: 7px; margin-right: 8px; }

/* Shell */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: #0d2b25; color: #d7e6e2; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; font-weight: 700; font-size: 16px; color: #fff; padding: 18px 18px 22px; }
nav a { display: block; padding: 9px 18px; color: #c4d8d3; text-decoration: none; border-left: 3px solid transparent; }
nav a:hover { background: rgba(255,255,255,.05); color: #fff; }
nav a.active { background: rgba(255,255,255,.08); color: #fff; border-left-color: #5fd1b5; }
.sidebar-foot { margin-top: auto; padding: 16px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.sidebar-foot .link { color: #8fd9c6; margin-top: 6px; }
.view { flex: 1; padding: 24px 28px 60px; min-width: 0; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; min-width: 180px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 14px; }
.grid.tiles { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .grid.two { grid-template-columns: 1fr; } }
.tile { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; cursor: default; }
.tile .n { font-size: 26px; font-weight: 700; margin-top: 4px; }
.tile.warn .n { color: var(--amber); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); }
td { padding: 9px 8px; border-bottom: 1px solid #eef1f3; vertical-align: top; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8fafb; }

.bar { height: 7px; background: #edf0f2; border-radius: 4px; overflow: hidden; min-width: 80px; }
.bar > span { display: block; height: 100%; background: var(--brand); }
.bar.full > span { background: var(--red); }

/* Board */
.board { display: grid; grid-template-columns: repeat(var(--cols), minmax(230px, 1fr)); gap: 12px; overflow-x: auto; align-items: start; }
.column { background: #eaeef1; border-radius: var(--radius); padding: 10px; min-height: 200px; }
.column-head { display: flex; justify-content: space-between; font-weight: 600; font-size: 13px; padding: 2px 4px 10px; }
.lead-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; }
.lead-card:hover { border-color: #b9c4cc; box-shadow: 0 2px 6px rgba(0,0,0,.05); }
.lead-card .top { display: flex; justify-content: space-between; gap: 6px; }
.lead-card .name { font-weight: 600; }
.lead-card .meta { color: var(--muted); font-size: 12px; margin-top: 4px; line-height: 1.5; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }

.pill { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 99px; background: #eef1f3; color: var(--muted); white-space: nowrap; }
.pill.brand { background: var(--brand-soft); color: var(--brand); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.pill.green { background: var(--green-soft); color: var(--green); }

/* Drawer */
.backdrop { position: fixed; inset: 0; background: rgba(13, 30, 26, .35); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100%); background: var(--bg); z-index: 21; overflow-y: auto; box-shadow: -10px 0 30px rgba(0,0,0,.15); }
.drawer-head { position: sticky; top: 0; background: #fff; border-bottom: 1px solid var(--line); padding: 16px 20px; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; z-index: 1; }
.drawer-body { padding: 16px 20px 40px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.thread { max-height: 340px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 4px 0 10px; }
.msg { max-width: 78%; padding: 7px 10px; border-radius: 9px; font-size: 13px; line-height: 1.4; white-space: pre-wrap; word-wrap: break-word; }
.msg.in { background: #fff; border: 1px solid var(--line); align-self: flex-start; }
.msg.out { background: #dcf3e6; align-self: flex-end; }
.msg .when { font-size: 10.5px; color: var(--muted); margin-top: 3px; }
.composer { display: flex; gap: 8px; }
.composer input { flex: 1; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid #eef1f3; font-size: 13px; }
.timeline .when { color: var(--muted); font-size: 11.5px; }

/* Modal */
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(620px, 94vw); max-height: 90vh; overflow-y: auto; background: #fff; border-radius: 12px; z-index: 31; padding: 20px 22px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
#modalBackdrop { z-index: 30; }
.spec-grid { display: grid; grid-template-columns: 1fr 110px; gap: 6px 12px; align-items: center; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 50; font-size: 13px; max-width: 90vw; }
.toast.bad { background: var(--red); }

.scheme { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
.scheme .head { display: flex; justify-content: space-between; gap: 8px; }
ol.compact, ul.compact { margin: 4px 0 0; padding-left: 18px; }
code { background: #eef1f3; padding: 1px 5px; border-radius: 4px; font-size: 12px; word-break: break-all; }
