:root {
  --cabinet: #c5d0dc;
  --desk: #9eafc2;
  --paper: #f3eee4;
  --paper-2: #ebe4d6;
  --ink: #17202b;
  --mute: #5b6776;
  --carbon: #24405c;
  --carbon-2: #1a3148;
  --rule: #c9bda8;
  --unpaid: #b42318;
  --done: #1f5c45;
  --doing: #1a4a86;
  --cancel: #6a7380;
  --gold: #a8843c;
  --mist: #e7edf3;
  --white: #fbf9f3;
  --shadow: 0 18px 40px rgba(23, 32, 43, 0.14);
  --serif: "Noto Serif SC", "Songti SC", serif;
  --sans: "IBM Plex Sans", "Noto Sans SC", sans-serif;
  --mono: "IBM Plex Mono", "SFMono-Regular", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
[hidden] { display: none !important; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--cabinet);
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2 { font-family: var(--serif); margin: 0; letter-spacing: 0.04em; }

.eyebrow {
  margin: 0 0 6px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
}

.btn {
  border: 1px solid var(--carbon);
  background: var(--white);
  padding: 9px 16px;
  border-radius: 2px;
}
.btn.primary {
  background: var(--carbon);
  color: var(--white);
  border-color: var(--carbon);
}
.btn.ghost { background: transparent; border-color: rgba(23,32,43,.25); }
.btn.danger { background: var(--unpaid); color: #fff; border-color: var(--unpaid); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--doing);
  outline-offset: 2px;
}

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
}
.gate-card {
  width: min(440px, 100%);
  background: var(--paper);
  padding: 36px 32px 32px;
  box-shadow: var(--shadow);
  border-top: 8px solid var(--carbon);
  position: relative;
}
.gate-card::before {
  content: "";
  position: absolute;
  inset: 12px auto 12px -8px;
  width: 16px;
  background:
    radial-gradient(circle at 50% 10px, var(--cabinet) 5px, transparent 6px) 0 0 / 16px 22px repeat-y;
}
.gate-copy { color: var(--mute); line-height: 1.6; }
.stack { display: grid; gap: 14px; }
.stack label { display: grid; gap: 6px; font-size: 13px; color: var(--mute); }
.stack input {
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: transparent;
  padding: 8px 0;
}
.sms-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sms-row input { flex: 1; min-width: 0; }
.sms-row .btn { padding: 6px 10px; font-size: 12px; white-space: nowrap; }
.error { color: var(--unpaid); margin: 0; font-size: 13px; }
.gate-switch {
  margin: 16px 0 0;
  text-align: center;
  font-size: 13px;
  color: var(--mute);
}
.gate-switch button {
  border: 0;
  background: none;
  padding: 0;
  color: var(--carbon);
  text-decoration: underline;
}
.stack .agree {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  line-height: 1.5;
}
.stack .agree input {
  margin-top: 3px;
  accent-color: var(--carbon);
  flex: 0 0 auto;
}
.legal-link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--carbon);
  text-decoration: underline;
}
.legal-sheet { max-width: 560px; }
.legal-body {
  font-size: 13px;
  line-height: 1.75;
  color: var(--ink);
}
.legal-body h3 {
  font-family: var(--serif);
  font-size: 15px;
  margin: 16px 0 6px;
}
.legal-body p { margin: 0 0 8px; color: var(--mute); }
.legal-meta { margin-top: 16px; font-size: 12px; letter-spacing: 0.08em; }

.app {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 10px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.mast {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 0 2px 8px;
  border-bottom: 1px dashed rgba(36,64,92,.35);
  flex: 0 0 auto;
}
.mast h1 { font-size: 22px; }
.mast-note { margin: 0; color: var(--mute); font-size: 13px; line-height: 1.65; }
.mast-actions { display: flex; align-items: center; gap: 10px; }
.who { font-family: var(--mono); font-size: 12px; color: var(--carbon); }
.profile-sheet { width: min(480px, calc(100% - 24px)); max-height: min(92vh, 880px); }
.profile-block {
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px dashed var(--rule);
}
.profile-block:last-child { border: 0; margin: 0; padding: 0; }
.profile-block h3 {
  font-family: var(--serif);
  font-size: 16px;
  margin: 0;
}
.profile-hint { margin: 0; font-size: 13px; color: var(--mute); line-height: 1.6; }
.profile-block.is-danger h3 { color: var(--unpaid); }

.tape {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  flex: 0 0 auto;
}
.stat {
  background: var(--paper);
  padding: 10px 12px 8px;
  box-shadow: 0 6px 0 rgba(36,64,92,.08);
  position: relative;
}
.stat::after {
  content: "";
  position: absolute;
  left: 10px; right: 10px; top: 6px;
  border-top: 2px dotted var(--rule);
}
.stat b {
  display: block;
  font-family: var(--mono);
  font-size: 18px;
  margin-top: 4px;
}
.stat span { font-size: 12px; color: var(--mute); letter-spacing: 0.08em; }
.stat.hot b { color: var(--unpaid); }

.pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0 0 8px;
  flex: 0 0 auto;
}
.kinds { display: flex; }
.kind-tab {
  border: 1px solid var(--carbon);
  background: var(--mist);
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 600;
}
.kind-tab + .kind-tab { border-left: 0; }
.kind-tab.is-on {
  background: var(--carbon);
  color: #fff;
}
.search {
  flex: 1 1 240px;
  min-width: 200px;
  border: 1px solid rgba(36,64,92,.2);
  background: var(--white);
  padding: 10px 12px;
}
.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid rgba(36,64,92,.25);
  background: var(--mist);
  padding: 6px 10px;
  font-size: 13px;
}
.chip.is-on { background: var(--carbon); color: #fff; border-color: var(--carbon); }
.hint { margin: 0; color: var(--mute); font-size: 13px; flex: 1; }

.ledger {
  flex: 1;
  min-height: 0;
  display: flex;
}
.table-wrap {
  flex: 1;
  overflow: auto;
  background: var(--paper);
  width: 100%;
}
.grid-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.grid-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}
.grid-table th {
  text-align: left;
  font-weight: 500;
  color: var(--mute);
  font-size: 11px;
  letter-spacing: 0.08em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper-2);
  white-space: nowrap;
}
.grid-table th.is-sort { cursor: pointer; user-select: none; }
.grid-table th.is-sort:hover { color: var(--ink); }
.grid-table th.is-sorted { color: var(--carbon); font-weight: 600; }
.grid-table td {
  padding: 5px 10px;
  border-bottom: 1px solid rgba(201, 189, 168, 0.45);
  vertical-align: middle;
  white-space: nowrap;
}
.grid-table td.name {
  white-space: normal;
  font-weight: 600;
  min-width: 140px;
}
.grid-table td.work {
  white-space: normal;
  min-width: 140px;
  max-width: 260px;
}
.work-btn {
  border: 0;
  background: transparent;
  padding: 0;
  font: inherit;
  text-align: left;
  color: var(--ink);
}
.work-btn:hover { color: var(--doing); text-decoration: underline; }
.work-btn.is-empty { color: var(--mute); font-weight: 400; }
.work-cell { cursor: pointer; }
.work-link {
  color: var(--doing);
  text-underline-offset: 2px;
}
.work-link:hover { color: var(--carbon); }
.check-empty {
  grid-column: 1 / -1;
  margin: 8px 0;
  color: var(--mute);
}
.check-row.is-view { grid-template-columns: 18px 1fr; }
.check-row.is-done .check-text { color: var(--mute); text-decoration: line-through; }
.check-row.is-done .work-link {
  color: var(--doing);
  text-decoration: underline;
  pointer-events: auto;
}
.check-text { word-break: break-all; }
.now-project {
  grid-column: 1 / -1;
  margin: 0 0 4px;
  font-weight: 600;
}
.check-list {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
}
.check-row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 8px;
  align-items: center;
}
.check-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--done);
}
.check-row input[type="text"] {
  width: 100%;
}
.check-row input[type="text"]:disabled,
.check-row:has(input[type="checkbox"]:checked) input[type="text"] {
  color: var(--mute);
  text-decoration: line-through;
}
.check-add { grid-column: 1 / -1; justify-self: start; }
.check-del { font-size: 20px; padding: 0 4px; }
.grid-table tbody tr.urgent { background: rgba(193, 18, 31, 0.08); }
.flag {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-left: 6px;
  color: #c1121f;
  vertical-align: -2px;
}
.flag svg { width: 14px; height: 14px; display: block; }
.flag.is-late { color: #8a0f16; }
.grid-table td.client {
  white-space: normal;
  color: var(--mute);
  max-width: 220px;
}
.grid-table tbody tr:hover { background: rgba(255,255,255,.45); }
.grid-table .seq {
  font-family: var(--mono);
  color: var(--mute);
  width: 36px;
}
.money { font-family: var(--mono); }
.money.due { color: var(--unpaid); font-weight: 600; }
.money.ok { color: var(--done); }
.row-actions { display: flex; gap: 6px; }
.row-actions .btn { padding: 3px 8px; font-size: 12px; }
.select-mini {
  border: 1px solid rgba(36,64,92,.25);
  background: var(--white);
  padding: 3px 6px;
  font-size: 12px;
  min-width: 96px;
}
.select-mini.date { min-width: 128px; }
.plan-due.overdue { color: var(--unpaid); font-weight: 600; }
.pill {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border: 1px solid currentColor;
  letter-spacing: 0.04em;
}
.pill.doing { color: var(--doing); }
.pill.done { color: var(--done); }
.pill.cancel { color: var(--cancel); }
.pill.unpaid { color: var(--unpaid); }
.pill.partial { color: var(--gold); }
.pill.paid { color: var(--done); }
.pill.none { color: var(--mute); }
.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--mute);
  background: var(--paper);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(23, 32, 43, 0.42);
  display: grid;
  place-items: end center;
  z-index: 20;
}
.overlay.is-center { place-items: center; }
.overlay.is-center .sheet { width: min(640px, calc(100% - 24px)); }
.sheet {
  width: min(720px, 100%);
  max-height: min(92vh, 900px);
  overflow: auto;
  background: var(--paper);
  padding: 22px 22px 28px;
  box-shadow: var(--shadow);
}
.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 10px;
}
.icon-btn {
  border: 0;
  background: transparent;
  font-size: 28px;
  line-height: 1;
  color: var(--mute);
}
.sheet-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.sheet-form label { display: grid; gap: 6px; font-size: 12px; color: var(--mute); }
.sheet-form label.wide { grid-column: 1 / -1; }
.sheet-form input, .sheet-form select, .sheet-form textarea {
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: transparent;
  padding: 8px 0;
}
.sheet-form textarea { min-height: 72px; resize: vertical; }
.sheet-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}

@media (max-width: 900px) {
  .mast { grid-template-columns: 1fr; }
  .tape { grid-template-columns: 1fr 1fr; }
  .sheet-form { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
