:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --line: #dfe3ea;
  --line-strong: #c6ccd8;
  --ink: #171b22;
  --ink-2: #5b6472;
  --ink-3: #8b94a3;
  --accent: #1d4ed8;
  --accent-soft: #e8eeff;
  --amber: #b45309;
  --amber-soft: #fdf0dc;
  --green: #15803d;
  --green-soft: #e3f4e9;
  --red: #b91c1c;
  --red-soft: #fbe9e9;
  --purple: #6d28d9;
  --purple-soft: #f0e9fd;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e232c;
    --line: #262c37;
    --line-strong: #39414f;
    --ink: #e8eaee;
    --ink-2: #a3abb9;
    --ink-3: #79818f;
    --accent: #6b93ff;
    --accent-soft: #1b2540;
    --amber: #f0a04a;
    --amber-soft: #33260f;
    --green: #58c98a;
    --green-soft: #10281a;
    --red: #f08585;
    --red-soft: #331616;
    --purple: #b191f5;
    --purple-soft: #241a3b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

/* ------------------------------------------------------------------ shell */

.app { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 16px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 9px; padding: 4px 8px 18px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: var(--amber); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.brand-name { font-weight: 650; font-size: 14px; line-height: 1.1; }
.brand-sub { color: var(--ink-3); font-size: 11px; }

.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 10px; border-radius: 7px; color: var(--ink-2);
  font-weight: 500; font-size: 13px;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-count {
  font-size: 11px; font-weight: 600; background: var(--surface-2);
  color: var(--ink-2); padding: 0 6px; border-radius: 9px; min-width: 20px; text-align: center;
}
.nav a.active .nav-count { background: var(--accent); color: #fff; }
.nav-count.alert { background: var(--red); color: #fff; }
.nav-section { color: var(--ink-3); font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .07em; font-weight: 700; padding: 16px 10px 5px; }

.sidebar-foot { margin-top: 20px; padding: 10px; border-top: 1px solid var(--line); color: var(--ink-3); font-size: 12px; }

.main { min-width: 0; padding: 20px 24px 60px; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 16px;
}
.page-head p { margin: 3px 0 0; color: var(--ink-2); font-size: 13px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* --------------------------------------------------------------- controls */

.btn {
  appearance: none; border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink); border-radius: 7px; padding: 6px 11px; font-size: 13px;
  font-weight: 550; cursor: pointer; font-family: inherit; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); border-color: var(--line-strong); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  font-family: inherit; font-size: 13px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 7px; padding: 6px 9px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 70px; resize: vertical; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; }

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }
.grid > .card + .card, .grid > * > .card:first-child { margin-top: 0; }
.card-head {
  padding: 11px 14px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.card-body { padding: 14px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); gap: 14px; align-items: start; }

/* ------------------------------------------------------------------ stats */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 11px 13px; box-shadow: var(--shadow);
}
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 650; }
.stat-value { font-size: 24px; font-weight: 660; letter-spacing: -0.02em; margin-top: 2px; }
.stat-note { font-size: 12px; color: var(--ink-2); }
.stat.alert .stat-value { color: var(--red); }
.stat.good .stat-value { color: var(--green); }

/* ----------------------------------------------------------------- table */

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-3); font-weight: 650; padding: 8px 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

/* ---------------------------------------------------------------- badges */

.badge {
  display: inline-block; padding: 1px 7px; border-radius: 20px; font-size: 11.5px;
  font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--ink-2);
}
.badge.blue { background: var(--accent-soft); color: var(--accent); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.purple { background: var(--purple-soft); color: var(--purple); }

.ref { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.empty { padding: 26px 14px; text-align: center; color: var(--ink-3); font-size: 13px; }

/* ----------------------------------------------------------------- board */

.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.board-col { flex: 0 0 268px; background: var(--surface-2); border-radius: var(--radius); padding: 9px; }
.board-col-head { display: flex; justify-content: space-between; align-items: baseline; padding: 2px 4px 9px; }
.board-col-head .t { font-weight: 650; font-size: 13px; }
.board-col-head .v { font-size: 11.5px; color: var(--ink-3); }
.board-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 10px; margin-bottom: 8px; cursor: pointer; box-shadow: var(--shadow);
}
.board-card:hover { border-color: var(--line-strong); }
.board-card .top { display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }
.board-card .who { font-weight: 600; font-size: 13px; }
.board-card .meta { color: var(--ink-2); font-size: 12px; margin-top: 3px; }
.board-card .action {
  margin-top: 7px; padding-top: 7px; border-top: 1px dashed var(--line);
  font-size: 11.5px; display: flex; gap: 5px; align-items: flex-start;
}
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; margin-top: 4px; }
.dot.now { background: var(--red); }
.dot.today { background: var(--amber); }
.dot.soon { background: var(--ink-3); }

/* --------------------------------------------------------------- planner */

.planner { overflow-x: auto; }
.planner table { border-collapse: separate; border-spacing: 0; min-width: 900px; }
.planner th, .planner td { border-bottom: 1px solid var(--line); padding: 0; }
.planner th.asset, .planner td.asset {
  position: sticky; left: 0; background: var(--surface); z-index: 2;
  padding: 6px 10px; border-right: 1px solid var(--line); min-width: 176px;
}
.planner th.day { width: 30px; font-size: 10px; text-align: center; padding: 4px 0; color: var(--ink-3); }
.planner th.day.we { background: var(--surface-2); }
.planner th.day.today { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.planner td.cell { height: 34px; border-right: 1px solid var(--line); position: relative; }
.planner td.cell.we { background: var(--surface-2); }
.planner td.cell.today { box-shadow: inset 2px 0 0 var(--accent); }
.pblock {
  /* A block overflows the cell it starts in, so it has to sit above the
     backgrounds of the cells that follow it. */
  position: absolute; z-index: 1; inset: 4px 1px; border-radius: 5px; font-size: 11px;
  padding: 1px 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  cursor: pointer; font-weight: 550; line-height: 24px;
}
.pblock.on_hire { background: var(--green-soft); color: var(--green); border: 1px solid currentColor; }
.pblock.confirmed { background: var(--accent-soft); color: var(--accent); border: 1px solid currentColor; }
.pblock.provisional { background: var(--amber-soft); color: var(--amber); border: 1px dashed currentColor; }
.pblock.service { background: var(--red-soft); color: var(--red); border: 1px solid currentColor; }
.pblock.overdue {
  background: repeating-linear-gradient(45deg, var(--amber-soft), var(--amber-soft) 5px, transparent 5px, transparent 10px);
  color: var(--amber); border: 1px solid currentColor;
}
.planner .asset .a { font-weight: 600; font-size: 12.5px; }
.planner .asset .c { color: var(--ink-3); font-size: 11px; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-top: 10px; }
.legend span { display: flex; align-items: center; gap: 5px; }
.swatch { width: 11px; height: 11px; border-radius: 3px; border: 1px solid currentColor; }

/* ---------------------------------------------------------------- detail */

.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.kv { display: grid; grid-template-columns: 128px 1fr; gap: 5px 10px; font-size: 13px; }
.kv dt { color: var(--ink-3); font-size: 12px; }
.kv dd { margin: 0; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 9px 0 9px 18px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before {
  content: ''; position: absolute; left: -5px; top: 14px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--line-strong);
}
.timeline li.call_out::before, .timeline li.call_in::before { background: var(--green); }
.timeline li.email::before, .timeline li.whatsapp::before { background: var(--accent); }
.timeline li .t { font-weight: 600; font-size: 13px; }
.timeline li .m { color: var(--ink-3); font-size: 11.5px; }
.timeline li .b { color: var(--ink-2); font-size: 12.5px; margin-top: 2px; white-space: pre-wrap; }

.action-list { list-style: none; margin: 0; padding: 0; }
.action-list li { display: flex; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.action-list li:last-child { border-bottom: none; }
.action-list li:hover { background: var(--surface-2); }
.action-list .what { font-weight: 600; font-size: 13px; }
.action-list .why { color: var(--ink-2); font-size: 12px; }
.action-list .who { color: var(--ink-3); font-size: 11.5px; font-family: var(--mono); }

/* ---------------------------------------------------------------- modal */

.modal-bg {
  position: fixed; inset: 0; background: rgba(9, 12, 18, .5); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 12px; width: 100%; max-width: 620px;
  box-shadow: 0 18px 40px rgba(9, 12, 18, .28); border: 1px solid var(--line);
}
.modal.wide { max-width: 880px; }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.close { background: none; border: none; font-size: 20px; color: var(--ink-3); cursor: pointer; line-height: 1; }

/* ---------------------------------------------------------------- login */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 360px; }
.login .brand { justify-content: center; padding-bottom: 22px; }
.login .card-body { padding: 20px; }
.error { color: var(--red); font-size: 12.5px; margin-top: 8px; }
.hint { color: var(--ink-3); font-size: 12px; margin-top: 12px; text-align: center; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 8px;
  font-size: 13px; z-index: 100; box-shadow: 0 8px 20px rgba(0, 0, 0, .25);
}
.toast.err { background: var(--red); color: #fff; }

.bar { height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--accent); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--line); }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav-section { display: none; }
  .main { padding: 16px 14px 50px; }
  .split { grid-template-columns: 1fr; }
  .field-row, .field-row-3 { grid-template-columns: 1fr; }
}
