:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #1d1d1b;
  --muted: #6b6a66;
  --line: #e4e2dc;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #e6efeb;
  --warn: #9a5b13;
  --warn-soft: #fbf0e1;
  --err: #a33a2a;
  --err-soft: #fbe7e3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161716; --panel: #1f201f; --ink: #ecebe7; --muted: #a09e98; --line: #33342f;
    --accent: #7fb8a4; --accent-ink: #10201a; --accent-soft: #23332d;
    --warn: #e0a65c; --warn-soft: #3a2d1a; --err: #ef8c7a; --err-soft: #3d221d;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); display: flex; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 4px; }

/* layout */
.sidebar { width: 210px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { font-weight: 700; font-size: 15px; padding: 4px 10px 18px; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.nav a { display: flex; justify-content: space-between; padding: 8px 10px; border-radius: 8px; color: var(--ink); margin-bottom: 2px; }
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .badge { background: var(--accent); color: var(--accent-ink); border-radius: 99px; padding: 0 7px; font-size: 11px; line-height: 18px; }
.sidebar .foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 0 10px; }
main { flex: 1; padding: 22px 28px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.topbar .spacer { flex: 1; }
.topbar form.search input { width: 260px; }

.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: repeat(3, 1fr); }
.side { grid-template-columns: 340px 1fr; align-items: start; }
@media (max-width: 1000px) { .g2, .g3, .side { grid-template-columns: 1fr; } .sidebar { display: none; } }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

/* forms */
input, select, textarea { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: auto; }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 4px 14px 4px 0; color: var(--ink); font-size: 13px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.btn, button { font: inherit; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover, button:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary, button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger, button.danger { color: var(--err); }
.btn.sm, button.sm { padding: 3px 8px; font-size: 12px; }
button.link { border: none; background: none; padding: 0; color: var(--accent); }
form.inline { display: inline; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.pill.customer, .pill.won { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.opportunity, .pill.proposal, .pill.negotiation { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.lost { background: var(--err-soft); color: var(--err); border-color: transparent; }
.chip { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); margin: 2px 4px 0 0; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: var(--accent-soft); color: var(--accent); word-break: break-word; }
.flash.err { background: var(--err-soft); color: var(--err); }

/* key/value list */
dl.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 12px; padding-top: 2px; }
dl.kv dd { margin: 0; word-break: break-word; }

/* timeline */
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { display: grid; grid-template-columns: 30px 1fr; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.tl li:last-child { border-bottom: none; }
.tl .ico { width: 30px; height: 30px; border-radius: 99px; background: var(--bg); display: grid; place-items: center; font-size: 14px; }
.tl .head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.tl .head .when { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.tl .body { margin-top: 6px; white-space: pre-wrap; font-size: 13px; color: var(--ink); max-height: 9.5em; overflow: hidden; position: relative; }
.tl details[open] .body { max-height: none; }
.tl details summary { cursor: pointer; font-size: 12px; color: var(--muted); margin-top: 4px; list-style: none; }
.tl .md { white-space: normal; }
.tl .md h1, .tl .md h2, .tl .md h3 { font-size: 13px; text-transform: none; letter-spacing: 0; color: var(--ink); margin: 10px 0 4px; }
.tl .md ul { margin: 4px 0; padding-left: 18px; }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button, .tabs a { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 5px 10px; font-size: 13px; color: var(--ink); }
.tabs .on { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }

/* kanban */
.board { display: grid; grid-template-columns: repeat(6, minmax(200px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 300px; display: flex; flex-direction: column; }
.col.drop { outline: 2px dashed var(--accent); }
.col header { display: flex; justify-content: space-between; align-items: baseline; padding: 2px 4px 10px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.col header b { font-size: 13px; }
.col header span { font-size: 12px; color: var(--muted); }
.dealcard { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: grab; }
.dealcard:active { cursor: grabbing; }
.dealcard a { color: var(--ink); font-weight: 600; }
.dealcard .meta { font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; justify-content: space-between; gap: 6px; }

.task { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: none; }
.task .done { text-decoration: line-through; color: var(--muted); }
.task .due.late { color: var(--err); font-weight: 600; }
.check { width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--muted); background: none; padding: 0; display: grid; place-items: center; font-size: 12px; flex-shrink: 0; margin-top: 1px; }
.check.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 99px; background: var(--muted); margin-right: 6px; }
.status-dot.ok { background: #3a9a6a; }
.status-dot.err { background: var(--err); }
.integration { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: start; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.login { max-width: 340px; margin: 12vh auto; }
.taskadd { flex-wrap: wrap; }
.taskadd input[name=title] { flex: 1 1 100%; }
.taskadd input[type=date] { flex: 1 1 140px; }
.taskadd button { flex: 0 0 auto; }
