/* Black & white. Everything visual lives here. */
:root {
  --ink: #0a0a0a;
  --ink-2: #404040;
  --muted: #737373;
  --faint: #a3a3a3;
  --line: #e5e5e5;
  --line-2: #d4d4d4;
  --wash: #fafafa;
  --wash-2: #f4f4f4;
  --bg: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  font-synthesis: none;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 "Inter", -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  font-feature-settings: "cv11", "ss01", "tnum";
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; line-height: 1.2; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
p { margin: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.mono { font-family: "JetBrains Mono", ui-monospace, Menlo, monospace; font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.92);
  backdrop-filter: saturate(180%) blur(12px); border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 0 24px; height: 60px;
  display: flex; align-items: center; gap: 28px;
}
.brand { font-weight: 800; letter-spacing: -0.03em; font-size: 18px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 550; font-size: 14px;
  white-space: nowrap;
}
.nav a:hover { color: var(--ink); background: var(--wash-2); text-decoration: none; }
.nav a.on { color: var(--ink); background: var(--wash-2); }
.nav .count {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px;
  background: var(--ink); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--ink); color: #fff;
  display: grid; place-items: center; font-size: 12px; font-weight: 700; letter-spacing: .02em;
  border: 0; cursor: pointer; font-family: inherit;
}
.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: 42px; min-width: 220px; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 6px; display: none;
}
.menu.open .menu-pop { display: block; }
.menu-pop .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu-pop a, .menu-pop button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px;
  background: none; border: 0; font: inherit; font-size: 14px; color: var(--ink); cursor: pointer;
}
.menu-pop a:hover, .menu-pop button:hover { background: var(--wash-2); text-decoration: none; }

/* ---------- page ---------- */
.page { max-width: 1180px; margin: 0 auto; padding: 32px 24px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head p { margin-top: 6px; }
.stack > * + * { margin-top: 16px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.grid-cols { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 16px; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--ink);
  background: var(--ink); color: #fff; font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; white-space: nowrap; transition: opacity .15s, background .15s;
}
.btn:hover { opacity: .85; text-decoration: none; }
.btn:disabled { opacity: .3; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line-2); }
.btn.ghost:hover { background: var(--wash-2); opacity: 1; }
.btn.plain { background: none; border-color: transparent; color: var(--muted); padding: 0 8px; }
.btn.plain:hover { color: var(--ink); opacity: 1; }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.danger { background: #fff; color: var(--ink); border-color: var(--line-2); }

label.lbl { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink-2); }
.req::after { content: " *"; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], input[type=url], input[type=search], select, textarea {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 8px;
  background: #fff; color: var(--ink); font: inherit; font-size: 15px; outline: none;
  transition: border-color .15s, box-shadow .15s; appearance: none; -webkit-appearance: none;
}
textarea { height: auto; min-height: 88px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px;
}
input:focus, select:focus, textarea:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(0,0,0,.08); }
.field { margin-bottom: 16px; }
.field.err input, .field.err select, .field.err textarea { border-color: var(--ink); border-width: 2px; }
.err-msg { font-size: 12px; font-weight: 600; margin-top: 4px; }
.err-msg::before { content: "! "; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.checkbox { display: flex; gap: 8px; align-items: center; font-size: 14px; margin-bottom: 10px; }
.checkbox input { width: 16px; height: 16px; accent-color: #000; }

/* ---------- cards ---------- */
.card { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card-body { padding: 20px; }
.card.inverse { background: var(--ink); color: #fff; border-color: var(--ink); }
.card.inverse .muted { color: #a3a3a3; }
.card.inverse .btn { background: #fff; color: var(--ink); border-color: #fff; }
.card.inverse .btn.ghost { background: transparent; color: #fff; border-color: #525252; }
.card.inverse label.lbl { color: #e5e5e5; }
.card.inverse input, .card.inverse select, .card.inverse textarea { border-color: #404040; background-color: #171717; color: #fff; }
.card.inverse input:focus, .card.inverse select:focus, .card.inverse textarea:focus { border-color: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.15); }
.card.inverse select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); }
.card.inverse input[type=date]::-webkit-calendar-picker-indicator,
.card.inverse input[type=datetime-local]::-webkit-calendar-picker-indicator { filter: invert(1); }

/* ---------- flash ---------- */
.flashes { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 50; display: grid; gap: 8px; width: min(520px, calc(100% - 32px)); }
.flash {
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.2); display: flex; justify-content: space-between; gap: 12px;
  animation: rise .25s ease-out;
}
.flash.error { background: #fff; color: var(--ink); border: 2px solid var(--ink); }
.flash button { background: none; border: 0; color: inherit; cursor: pointer; font-size: 18px; line-height: 1; opacity: .6; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

/* ---------- pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px;
  border-radius: 12px; font-size: 12px; font-weight: 600; white-space: nowrap;
  border: 1px solid var(--line-2); color: var(--ink-2); background: #fff;
}
.pill.solid { background: var(--ink); color: #fff; border-color: var(--ink); }
.pill.soft { background: var(--wash-2); border-color: transparent; }
.pill.dashed { border-style: dashed; color: var(--muted); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; }
.due-over { font-weight: 700; }
.due-over::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ink); margin-right: 6px; vertical-align: 1px; }

/* ---------- stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; margin-bottom: 28px; }
.stat { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat .k { font-size: 13px; color: var(--muted); font-weight: 550; }
.stat .v { font-size: 28px; font-weight: 700; letter-spacing: -0.03em; margin-top: 4px; line-height: 1.1; }
.stat .s { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat.dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.stat.dark .k, .stat.dark .s { color: #a3a3a3; }

/* ---------- ticket list ---------- */
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 28px 0 10px; }
.section-title h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.section-title .muted { font-size: 13px; }
.tickets { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.ticket {
  display: grid; grid-template-columns: minmax(0, 1fr) 150px 140px 20px; gap: 16px; align-items: center;
  padding: 14px 20px; border-top: 1px solid var(--line); transition: background .1s;
}
.ticket:first-child { border-top: 0; }
.ticket:hover { background: var(--wash); text-decoration: none; }
.ticket .co { font-weight: 650; font-size: 15px; }
.ticket .sub { font-size: 13px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticket .when { font-size: 13px; text-align: right; }
.ticket .chev { color: var(--faint); }
.tickets.over { border-color: var(--ink); border-width: 1.5px; }

.empty { border: 1px dashed var(--line-2); border-radius: var(--radius); padding: 48px 24px; text-align: center; }
.empty h2 { margin-bottom: 6px; }

/* ---------- tabs & filter row ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 10px 12px; font-size: 14px; font-weight: 550; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--ink); }
.tabs .c { color: var(--faint); font-weight: 500; margin-left: 4px; }
.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filters input[type=search] { max-width: 320px; }
.filters select { width: auto; min-width: 170px; }

/* ---------- table ---------- */
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--wash); white-space: nowrap; }
table.t td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr:hover { background: var(--wash); }
table.t .co { font-weight: 650; }
table.t th.right, table.t td.right { text-align: right; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }
table.t tr[data-href] { cursor: pointer; }

/* ---------- deal page ---------- */
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.deal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.deal-head .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; font-size: 14px; color: var(--muted); }
.stepper { display: grid; grid-template-columns: repeat(7, minmax(0,1fr)); gap: 4px; margin-bottom: 28px; }
.step { position: relative; }
.step .bar { height: 4px; border-radius: 2px; background: var(--line); }
.step.done .bar { background: var(--ink); }
.step.now .bar { background: var(--ink); }
.step .nm { font-size: 12px; margin-top: 8px; color: var(--faint); font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step.done .nm { color: var(--muted); }
.step.now .nm { color: var(--ink); font-weight: 700; }
.step .who { font-size: 11px; color: var(--faint); }
.closed-banner { border: 1.5px dashed var(--ink); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 24px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.action-card .card-body { padding: 20px; }
.action-card h2 { font-size: 18px; }
.action-list { display: grid; gap: 8px; margin-top: 16px; }
.action-toggle { width: 100%; }
.action-form { margin-top: 16px; padding-top: 16px; border-top: 1px solid #262626; }
.blocked { font-size: 13px; color: #a3a3a3; margin-top: 6px; }
.secondary-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.kv { display: grid; grid-template-columns: 1fr; }
.kv .row { display: grid; grid-template-columns: 170px minmax(0,1fr); gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px; }
.kv .row:first-child { border-top: 0; }
.kv .row .k { color: var(--muted); }
.kv .row .v { white-space: pre-wrap; word-break: break-word; }
details.group { border-top: 1px solid var(--line); }
details.group:first-of-type { border-top: 0; }
details.group > summary { list-style: none; cursor: pointer; padding: 14px 20px; display: flex; justify-content: space-between; align-items: center; font-weight: 650; font-size: 14px; }
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary::after { content: "+"; color: var(--muted); font-weight: 400; font-size: 18px; }
details.group[open] > summary::after { content: "–"; }
details.group .kv { padding: 0 20px 12px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 28px minmax(0,1fr); gap: 12px; padding: 14px 0; border-top: 1px solid var(--line); }
.timeline li:first-child { border-top: 0; }
.tl-icon { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line-2); display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--ink-2); background: #fff; }
.tl-icon.solid { background: var(--ink); color: #fff; border-color: var(--ink); }
.tl-head { font-size: 13px; color: var(--muted); }
.tl-head b { color: var(--ink); font-weight: 650; }
.tl-body { margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
.tl-next { margin-top: 6px; font-size: 13px; display: inline-flex; gap: 6px; align-items: center; padding: 3px 8px; background: var(--wash-2); border-radius: 6px; }

.pay-sum { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 16px; }
.pay-sum > div { background: #fff; padding: 10px 12px; }
.pay-sum .k { font-size: 12px; color: var(--muted); }
.pay-sum .v { font-weight: 700; font-size: 16px; }

.log-form { display: grid; gap: 10px; }
.log-row { display: grid; grid-template-columns: 140px 1fr 160px; gap: 10px; }
.kinds { display: flex; gap: 6px; flex-wrap: wrap; }
.kinds input { display: none; }
.kinds label { padding: 5px 12px; border: 1px solid var(--line-2); border-radius: 16px; font-size: 13px; cursor: pointer; font-weight: 550; }
.kinds input:checked + label { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- dashboard ---------- */
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 110px minmax(0,1fr) 110px; gap: 12px; align-items: center; font-size: 14px; }
.bar-track { height: 12px; position: relative; display: block; }
.bar-fill { height: 100%; background: var(--ink); border-radius: 0 4px 4px 0; min-width: 2px; transition: opacity .15s; }
.bar-fill.light { background: #a3a3a3; }
.bar-row:hover .bar-fill { opacity: .8; }
.bar-val { font-size: 13px; font-weight: 600; text-align: right; }
.bar-val .muted { font-weight: 450; }
.bar-inline-label { position: absolute; left: calc(var(--w) + 8px); top: 50%; transform: translateY(-50%); font-size: 13px; font-weight: 650; }

/* ---------- login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.auth-box { width: 100%; max-width: 380px; }
.auth-brand { text-align: center; margin-bottom: 32px; }
.auth-brand h1 { font-size: 34px; font-weight: 800; letter-spacing: -0.04em; }
.auth-brand p { color: var(--muted); margin-top: 6px; font-size: 15px; }
.auth-card { border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.auth-error { border: 2px solid var(--ink); border-radius: 8px; padding: 10px 12px; font-size: 14px; margin-bottom: 16px; font-weight: 550; }
.auth-foot { text-align: center; font-size: 13px; color: var(--muted); margin-top: 20px; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-2 > aside { order: -1; }
  .stats { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-cols { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar-inner { padding: 0 16px; gap: 12px; height: 56px; }
  .brand { font-size: 16px; }
  .nav { position: fixed; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,.96); backdrop-filter: blur(12px); border-top: 1px solid var(--line); gap: 0; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); z-index: 30; }
  .nav a { flex: 1; text-align: center; padding: 8px 4px; font-size: 13px; }
  .topbar-inner { justify-content: space-between; }
  .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; background: #fff; }
  .nav { backdrop-filter: none; }
  .flashes { bottom: 80px; }
  .hide-sm { display: none !important; }
  .page { padding: 20px 16px 80px; }
  h1 { font-size: 22px; }
  .ticket { grid-template-columns: minmax(0,1fr) auto; gap: 4px 12px; padding: 12px 16px; }
  .ticket .stage-col { grid-column: 1; grid-row: 2; }
  .ticket .when { grid-column: 2; grid-row: 1 / 3; }
  .ticket .chev { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .kv .row { grid-template-columns: 1fr; gap: 2px; }
  .stepper { grid-template-columns: repeat(7, minmax(0,1fr)); gap: 3px; }
  .step .nm, .step .who { display: none; }
  .log-row { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 84px minmax(0,1fr) 80px; gap: 8px; font-size: 13px; }
  .stat .v { font-size: 22px; }
  table.t.cards thead { display: none; }
  table.t.cards, table.t.cards tbody, table.t.cards tr, table.t.cards td { display: block; width: 100%; }
  table.t.cards tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }
  table.t.cards td { padding: 2px 0; border: 0; }
  table.t.cards td, table.t.cards td.right { text-align: left; }
  table.t.cards td[data-l] { display: inline-block; width: auto; margin-right: 14px; font-size: 13px; }
  table.t.cards td[data-l]::before { content: attr(data-l) " · "; color: var(--muted); font-size: 12px; }
}
