:root {
  --bg: #F5F1E8;
  --surface: #FFFDF8;
  --surface-2: #FBF7EF;
  --line: #E3DBCB;
  --line-strong: #CFC4AE;
  --ink: #2A2826;
  --ink-2: #4A4642;
  --muted: #7A736A;
  --red: #CA1623;
  --orange: #F15A22;
  --amber: #F99B1C;
  --charcoal: #3F3F3F;

  --st-not_started: #9A938A;
  --st-in_progress: #2D63C8;
  --st-waiting: #C98A12;
  --st-blocked: #CA1623;
  --st-on_hold: #8C8174;
  --st-done: #2E8B57;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(42, 40, 38, .06), 0 4px 14px rgba(42, 40, 38, .05);
  --font-head: 'Archivo Black', 'Arial Black', sans-serif;
  --font-body: 'IBM Plex Sans', system-ui, -apple-system, Segoe UI, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--red); }
.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  padding: 0 20px; height: 56px;
  background: var(--charcoal); color: #fff;
}
.brand-mark {
  font-family: var(--font-head); font-size: 18px; letter-spacing: .5px; white-space: nowrap;
}
.brand-mark span { color: var(--amber); margin: 0 2px; }
.topbar .brand-mark { color: #fff; }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  color: #D9D4CB; text-decoration: none; padding: 7px 12px; border-radius: 7px; white-space: nowrap; font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a.active { background: #fff; color: var(--charcoal); }
.topbar .spacer { flex: 1; }
.me { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.me button { background: none; border: 1px solid rgba(255,255,255,.25); color: #fff; border-radius: 7px; padding: 5px 10px; cursor: pointer; }
.me button:hover { background: rgba(255,255,255,.1); }

/* ---------- layout ---------- */
.page { max-width: 1240px; margin: 0 auto; padding: 22px 20px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-family: var(--font-head); font-size: 26px; margin: 0; letter-spacing: .2px; }
.page-head p { margin: 4px 0 0; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; font-weight: 500; text-decoration: none; color: var(--ink);
}
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: #B1121E; }
.btn.danger { color: var(--red); border-color: #E7B7BB; }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.wide { width: 100%; padding: 11px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.filters {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.filters input[type=search] { flex: 1 1 200px; min-width: 160px; }
.filters .sep { width: 1px; height: 22px; background: var(--line); margin: 0 2px; }
input[type=text], input[type=email], input[type=search], input[type=number], input[type=date], select, textarea {
  background: #fff; border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 10px; outline: none; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(202,22,35,.12); }
textarea { resize: vertical; min-height: 70px; width: 100%; }
.chip-toggle {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: #fff; cursor: pointer; user-select: none; font-size: 13px;
}
.chip-toggle.on { background: var(--charcoal); border-color: var(--charcoal); color: #fff; }
.chip-toggle .av { width: 18px; height: 18px; font-size: 9.5px; }

/* ---------- pills / avatars ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent;
}
.status { background: color-mix(in srgb, var(--c) 13%, white); color: color-mix(in srgb, var(--c) 85%, black); }
.status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.status.on_hold::before { background: transparent; border: 1.5px dashed var(--c); width: 5px; height: 5px; }
.prio { font-family: var(--font-mono); font-size: 11px; padding: 1px 7px; }
.prio.P1 { background: var(--red); color: #fff; }
.prio.P2 { border-color: var(--orange); color: #B53E10; }
.prio.P3 { border-color: var(--line-strong); color: var(--muted); }
.decision { background: #FFF1D6; color: #8A5A00; border-color: #F3D18B; }
.waiting-chip { background: var(--surface-2); color: var(--ink-2); border-color: var(--line); font-weight: 500; }
.av {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 24px; height: 24px; border-radius: 50%; background: var(--c, #888); color: #fff;
  font-size: 10.5px; font-weight: 700; letter-spacing: .3px;
}
.av.none { background: transparent; border: 1.5px dashed var(--line-strong); color: var(--muted); }

/* ---------- board ---------- */
.ws { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; box-shadow: var(--shadow); overflow: hidden; }
.ws-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer;
  border-bottom: 1px solid var(--line); background: linear-gradient(var(--surface), var(--surface-2));
}
.ws.collapsed .ws-head { border-bottom: 0; }
.ws.collapsed .ws-body { display: none; }
.ws-head h2 { margin: 0; font-family: var(--font-head); font-size: 15.5px; letter-spacing: .2px; }
.ws-head .caret { transition: transform .15s; color: var(--muted); font-size: 11px; }
.ws.collapsed .caret { transform: rotate(-90deg); }
.brand-tag { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; background: #fff; }
.ws-stats { margin-left: auto; display: flex; gap: 14px; align-items: center; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.ws-stats b { color: var(--ink); font-family: var(--font-mono); font-weight: 600; }
.ws-desc { padding: 8px 14px 0; color: var(--muted); font-size: 12.5px; }

.row {
  display: grid; grid-template-columns: 120px 34px 1fr auto 52px 28px; gap: 12px; align-items: center;
  padding: 9px 14px; border-top: 1px solid var(--line); cursor: pointer;
}
.ws-body .row:first-child { border-top: 0; }
.row:hover { background: #FFF8EC; }
.row.done .title { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line-strong); }
.row .c-title { min-width: 0; }
.row .title { font-weight: 500; }
.row .sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .tags { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.row .hrs { font-family: var(--font-mono); font-size: 12.5px; text-align: right; color: var(--ink-2); }
.row .hrs.zero { color: var(--line-strong); }
.empty { padding: 18px 14px; color: var(--muted); }
.add-row { padding: 8px 14px; border-top: 1px dashed var(--line); }
.add-row button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 0; }
.add-row button:hover { color: var(--red); }

/* ---------- drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(30,28,26,.35); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 41;
  background: var(--surface); box-shadow: -10px 0 30px rgba(0,0,0,.15); display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.drawer-head .x { margin-left: auto; background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.drawer-body { padding: 16px 18px 24px; overflow-y: auto; flex: 1; }
.drawer-foot { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-2); }
.drawer-foot .spacer { flex: 1; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select { width: 100%; }
.field.title-field input { font-size: 17px; font-weight: 600; padding: 9px 11px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 12px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin: 4px 0 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--red); }
.section-label { font-family: var(--font-head); font-size: 13px; margin: 20px 0 8px; letter-spacing: .2px; }
.note-form { display: flex; gap: 8px; margin-bottom: 12px; }
.note-form textarea { min-height: 40px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.timeline li:first-child { border-top: 0; }
.timeline .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.timeline .note-text { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; margin-top: 4px; }
.meta-line { color: var(--muted); font-size: 12px; margin-bottom: 14px; }

/* ---------- summary ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.kpi .n { font-family: var(--font-head); font-size: 28px; line-height: 1.1; }
.kpi .l { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.kpi.accent { border-color: var(--red); }
.kpi.accent .n { color: var(--red); }
.cards2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0; }
.card h3 { font-family: var(--font-head); font-size: 15px; margin: 0 0 12px; letter-spacing: .2px; }
.card h3 small { font-family: var(--font-body); font-weight: 500; color: var(--muted); font-size: 12px; margin-left: 6px; letter-spacing: 0; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 92px; gap: 10px; align-items: center; margin: 8px 0; }
.bar-row .who { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.bar { height: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--c, var(--charcoal)); border-radius: 999px; }
.bar-row .v { font-family: var(--font-mono); font-size: 12.5px; text-align: right; white-space: nowrap; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line-strong); }
table.t td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t td.n, table.t th.n { text-align: right; font-family: var(--font-mono); }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #FFF8EC; }
.list-item { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-top: 1px solid var(--line); cursor: pointer; }
.list-item:first-of-type { border-top: 0; }
.list-item:hover .li-title { color: var(--red); }
.li-title { font-weight: 500; }
.li-sub { color: var(--muted); font-size: 12.5px; }
.feed-item { font-size: 13px; padding: 7px 0; border-top: 1px solid var(--line); }
.feed-item:first-of-type { border-top: 0; }

/* ---------- map ---------- */
.map-brand { margin-bottom: 22px; }
.map-brand > h2 {
  font-family: var(--font-head); font-size: 14px; letter-spacing: 1px; text-transform: uppercase;
  display: flex; align-items: center; gap: 10px; margin: 0 0 10px;
}
.map-brand > h2::after { content: ''; flex: 1; height: 2px; background: var(--line-strong); }
.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.map-ws { background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--red); border-radius: 8px; padding: 12px; break-inside: avoid; }
.map-ws h3 { margin: 0 0 2px; font-size: 14.5px; font-family: var(--font-head); letter-spacing: .2px; }
.map-ws .ms { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.map-ws ul { list-style: none; margin: 0; padding: 0; }
.map-ws li { display: flex; gap: 7px; align-items: flex-start; font-size: 12.5px; padding: 3px 0; cursor: pointer; }
.map-ws li:hover { color: var(--red); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; margin-top: 5px; }
.dot.on_hold { background: transparent; border: 1.5px dashed var(--c); }
.map-ws li .ini { margin-left: auto; font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); }
.map-ws li .flag { color: #B07400; font-weight: 700; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--ink-2); margin-bottom: 16px; align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- admin ---------- */
.admin-table input[type=text], .admin-table input[type=email], .admin-table select { width: 100%; }
.admin-table td.drag {
  cursor: grab; touch-action: none; user-select: none; color: var(--muted);
  font-size: 18px; line-height: 1; width: 30px; text-align: center; vertical-align: middle;
}
.admin-table td.drag:hover { color: var(--red); }
.admin-table td.rank { width: 30px; color: var(--muted); vertical-align: middle; }
.admin-table tr.dragging td { background: #FFF1D6; }
.admin-table tr.dragging td.drag { cursor: grabbing; color: var(--red); }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* ---------- login ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--charcoal); }
.login-card { width: min(380px, 100%); background: var(--surface); border-radius: 14px; padding: 28px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login-card .brand-mark { color: var(--charcoal); font-size: 22px; margin-bottom: 18px; }
.login-card h1 { font-family: var(--font-head); font-size: 22px; margin: 0 0 6px; }
.login-card p { margin: 0 0 18px; }
.login-card input { width: 100%; margin-bottom: 12px; padding: 10px 12px; }
.login-card .msg { margin-top: 12px; font-size: 13px; }

/* ---------- toast ---------- */
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--charcoal); color: #fff; padding: 9px 16px; border-radius: 8px; z-index: 60; box-shadow: var(--shadow); font-size: 13px; }
.toast.err { background: var(--red); }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .cards2 { grid-template-columns: 1fr; }
  .row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
  .row .c-title { order: -2; flex: 1 1 100%; }
  .row .c-av { order: -1; }
  .row .tags { justify-content: flex-start; }
  .row .hrs { text-align: left; }
  .ws-stats .hide-sm { display: none; }
  .me .name { display: none; }
}
@media (max-width: 560px) {
  .topbar { padding: 0 12px; gap: 10px; }
  .page { padding: 16px 12px 60px; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .bar-row { grid-template-columns: 84px 1fr 86px; }
  .topbar .brand-mark { display: none; }
  .me button { padding: 4px 8px; }
}

/* ---------- print (Map view => one-page PDF) ---------- */
@media print {
  @page { size: landscape; margin: 10mm; }
  body { background: #fff; font-size: 10.5px; }
  .topbar, .no-print, .filters { display: none !important; }
  .page { max-width: none; padding: 0; }
  .page-head h1 { font-size: 18px; }
  .map-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .map-ws { padding: 7px; box-shadow: none; }
  .map-ws li { font-size: 9.5px; padding: 1px 0; }
  .map-brand { margin-bottom: 10px; }
  .kpi, .card, .ws { box-shadow: none; }
}
