:root {
  --brand: #1f3d2b;
  --brand-2: #2f5d43;
  --brand-soft: #e8efe9;
  --bg: #f5f6f4;
  --card: #ffffff;
  --text: #1c1f1d;
  --muted: #6a716c;
  --line: #e1e4e0;
  --red: #b42318;
  --red-soft: #fdecea;
  --amber: #9a6100;
  --amber-soft: #fff4db;
  --green: #1d7a3e;
  --green-soft: #e4f4e9;
  --blue: #1f5fa8;
  --blue-soft: #e7f0fb;
  --radius: 10px;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0 0 12px; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
h3 { font-size: 0.95rem; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
small, .muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--brand); color: #fff; display: flex; align-items: center;
  gap: 4px; padding: 0 12px; height: 52px; }
.topbar .brand { font-weight: 800; letter-spacing: .04em; margin-right: 12px; color: #fff; }
.topbar nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.topbar nav::-webkit-scrollbar { display: none; }
.topbar nav a { color: #d9e6dc; padding: 8px 10px; border-radius: 8px; white-space: nowrap; font-size: .92rem; }
.topbar nav a.active, .topbar nav a:hover { background: rgba(255,255,255,.14); color: #fff; text-decoration: none; }
.topbar .right { display: flex; align-items: center; gap: 8px; }
.bell { position: relative; color: #fff; padding: 6px 8px; border-radius: 8px; }
.bell .count { position: absolute; top: 0; right: 0; background: #e5484d; color: #fff; border-radius: 9px; font-size: .7rem;
  padding: 1px 5px; font-weight: 700; }
.userchip { color: #d9e6dc; font-size: .85rem; cursor: pointer; }
main { max-width: 1280px; margin: 0 auto; padding: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.grid { display: grid; gap: 12px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.lead-layout { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 14px; align-items: start; }
@media (max-width: 900px) {
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lead-layout { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
  main { padding: 10px; }
  .topbar .userchip { display: none; }
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card + .card { margin-top: 12px; }
.grid > .card + .card, .kanban .card + .card { margin-top: 0; }
.stat { display: block; color: inherit; }
.stat:hover { text-decoration: none; border-color: var(--brand-2); }
.stat .n { font-size: 1.7rem; font-weight: 700; }
.stat .l { color: var(--muted); font-size: .85rem; }
.stat.alert .n { color: var(--red); }
.stat.warn .n { color: var(--amber); }

/* Forms */
label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input, select, textarea { width: 100%; padding: 9px 10px; border: 1px solid #cfd4cf; border-radius: 8px; font: inherit; background: #fff; color: var(--text); }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc3a8; border-color: var(--brand-2); }
input[type=checkbox] { width: auto; margin-right: 6px; transform: scale(1.15); }
.check { display: flex; align-items: center; font-size: .92rem; color: var(--text); font-weight: 500; margin: 4px 0; }
.field { margin-bottom: 10px; }
.req::after { content: " *"; color: var(--red); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; border-radius: 8px;
  border: 1px solid var(--brand); background: var(--brand); color: #fff; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--brand-2); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--brand); }
.btn.secondary:hover { background: var(--brand-soft); }
.btn.danger { background: var(--red); border-color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand-2); padding: 6px 8px; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btnbar { display: flex; gap: 8px; flex-wrap: wrap; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.quick button { border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 3px 10px; font-size: .8rem; cursor: pointer; }
.quick button:hover { background: var(--brand-soft); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: #fafbfa; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f7faf8; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: .75rem; font-weight: 600; background: #eef0ee; color: #3d4540; white-space: nowrap; }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.notice { padding: 10px 12px; border-radius: 8px; background: var(--amber-soft); color: #5c3b00; font-size: .9rem; margin-bottom: 10px; }
.notice.red { background: var(--red-soft); color: var(--red); }
.notice.blue { background: var(--blue-soft); color: #173f6e; }
.notice.green { background: var(--green-soft); color: #145c2e; }

/* Tabs */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs a { padding: 6px 12px; border-radius: 16px; background: #fff; border: 1px solid var(--line); color: var(--text); font-size: .88rem; }
.tabs a.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.tabs a:hover { text-decoration: none; }

/* Stage bar */
.stagebar { display: flex; gap: 4px; flex-wrap: wrap; }
.stagebar button { border: 1px solid var(--line); background: #fff; padding: 6px 10px; border-radius: 6px; font: inherit; font-size: .82rem; cursor: pointer; }
.stagebar button.done { background: var(--brand-soft); border-color: #c5d8ca; color: var(--brand); }
.stagebar button.current { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 700; }
.stagebar button.won { border-color: #9fd3b1; color: var(--green); }
.stagebar button.lost { border-color: #f1b3ad; color: var(--red); }
.stagebar button.current.won { background: var(--green); border-color: var(--green); color: #fff; }
.stagebar button.current.lost { background: var(--red); border-color: var(--red); color: #fff; }

/* Kanban */
.kanban { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 10px; align-items: flex-start; }
.kcol { min-width: 250px; width: 250px; background: #eceeeb; border-radius: var(--radius); padding: 8px; flex-shrink: 0; }
.kcol.drop { outline: 2px dashed var(--brand-2); }
.kcol h4 { margin: 2px 4px 8px; font-size: .85rem; display: flex; justify-content: space-between; }
.kcard { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; cursor: grab; font-size: .86rem; }
.kcard:hover { border-color: var(--brand-2); }
.kcard .t { font-weight: 600; }
.kcard .m { color: var(--muted); font-size: .78rem; margin-top: 3px; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: .9rem; }
.timeline li .meta { color: var(--muted); font-size: .78rem; }
.timeline li.system { color: var(--muted); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 4px 10px; font-size: .9rem; }
.kv div:nth-child(odd) { color: var(--muted); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(20,30,24,.45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 520px; padding: 18px; box-shadow: 0 12px 40px rgba(0,0,0,.2); }
.modal.wide { max-width: 860px; }
.modal h2 { margin-bottom: 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #1c1f1d; color: #fff; padding: 10px 16px;
  border-radius: 8px; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.err { background: var(--red); }

.login { max-width: 380px; margin: 12vh auto; }
.login .brandmark { font-size: 1.8rem; font-weight: 800; color: var(--brand); letter-spacing: .05em; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.picker-results { max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: 4px; }
.picker-results div { padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--line); font-size: .88rem; }
.picker-results div:hover { background: var(--brand-soft); }
pre.json { background: #f4f5f3; padding: 10px; border-radius: 8px; overflow: auto; font-size: .78rem; max-height: 340px; }

/* Mobile list cards */
@media (max-width: 700px) {
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { background: #fff; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; padding: 6px 8px; }
  table.responsive td { border: none; padding: 3px 0; text-align: left !important; }
  table.responsive td[data-l]::before { content: attr(data-l) ": "; color: var(--muted); font-size: .8rem; }
}
