:root {
  --bg: #0a0a0a;
  --surface: #111111;
  --surface-2: #171717;
  --line: #242424;
  --line-strong: #3a3a3a;
  --text: #f2f2f2;
  --text-2: #a3a3a3;
  --text-3: #6b6b6b;
  --invert-bg: #f2f2f2;
  --invert-text: #0a0a0a;
  --warn: #e5e5e5;
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-2); }
p { margin: 0; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.mono { font-family: var(--mono); font-size: 12.5px; letter-spacing: 0.02em; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

.wordmark {
  font-weight: 600;
  letter-spacing: 0.42em;
  font-size: 26px;
  padding-left: 0.42em; /* optically center the tracked letters */
}
.wordmark-sm { font-size: 15px; padding-left: 0; }

/* ---------- Login ---------- */
.login {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.login-form { width: 100%; max-width: 320px; display: grid; gap: 14px; }
.login-form .wordmark { text-align: center; }
.login-sub { text-align: center; color: var(--text-3); font-size: 12px; letter-spacing: 0.2em; text-transform: uppercase; margin: -6px 0 18px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 216px 1fr; min-height: 100%; }
.sidebar {
  border-right: 1px solid var(--line);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .wordmark { padding: 0 10px; }
.nav { display: grid; gap: 1px; }
.nav a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-decoration: none;
  color: var(--text-2);
  padding: 7px 10px;
  border-radius: var(--radius);
}
.nav a:hover { color: var(--text); background: var(--surface); }
.nav a.active { color: var(--text); background: var(--surface-2); }
.count { font-size: 11.5px; font-variant-numeric: tabular-nums; color: var(--invert-text); background: var(--invert-bg); border-radius: 9px; padding: 0 6px; line-height: 18px; min-width: 18px; text-align: center; }
.count:empty { display: none; }
.sidebar-foot { margin-top: auto; padding: 0 10px; display: flex; justify-content: space-between; align-items: center; font-size: 13px; }

.view { padding: 28px 36px 64px; min-width: 0; max-width: 1280px; }
.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: 4px; }
.section { margin-top: 36px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); }
.stat { padding: 14px 16px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat-value { font-size: 24px; font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat-label { color: var(--text-3); font-size: 12px; margin-top: 2px; }

/* ---------- Tables ---------- */
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--text-3);
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface); }
td.actions { text-align: right; white-space: nowrap; }
td.actions > * + * { margin-left: 6px; }
.empty { padding: 22px 14px; color: var(--text-3); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---------- Tags ---------- */
.tag {
  display: inline-block;
  font-size: 11.5px;
  line-height: 18px;
  padding: 0 7px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  color: var(--text-2);
  white-space: nowrap;
}
.tag-solid { background: var(--invert-bg); border-color: var(--invert-bg); color: var(--invert-text); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); margin-right: 7px; vertical-align: 1px; }
.dot.on { background: var(--text); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12); }
.dot.ring { background: transparent; border: 1.5px solid var(--text); }
.overdue { color: var(--text); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Forms ---------- */
.field { display: grid; gap: 6px; }
.field > span { font-size: 12px; color: var(--text-2); }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 8px 10px;
  width: 100%;
  min-width: 0;
}
textarea { resize: vertical; min-height: 72px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--text-2); }
input[type="checkbox"] { width: auto; accent-color: #f2f2f2; }
select { appearance: none; padding-right: 28px; background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%); background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .span-2 { grid-column: span 2; }
.form-error { color: var(--text); font-size: 13px; min-height: 0; }
.form-error:not(:empty) { padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface-2); }
.days { display: flex; gap: 4px; flex-wrap: wrap; }
.days label { display: inline-flex; align-items: center; gap: 5px; padding: 5px 9px; border: 1px solid var(--line-strong); border-radius: var(--radius); font-size: 12.5px; cursor: pointer; }
.inline-form { display: flex; gap: 6px; align-items: center; }
.inline-form input, .inline-form select { width: auto; flex: 1; min-width: 150px; padding: 6px 9px; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type="search"] { max-width: 340px; }
.toolbar select { width: auto; }
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.segmented button { font: inherit; font-size: 13px; background: none; border: 0; color: var(--text-2); padding: 6px 12px; cursor: pointer; border-right: 1px solid var(--line-strong); }
.segmented button:last-child { border-right: 0; }
.segmented button.on { background: var(--invert-bg); color: var(--invert-text); }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 7px 13px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--text-2); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--invert-bg); color: var(--invert-text); border-color: var(--invert-bg); }
.btn-primary:hover { background: #ffffff; border-color: #ffffff; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-block { width: 100%; padding: 10px; }
.btn-text { font: inherit; background: none; border: 0; color: var(--text-2); cursor: pointer; padding: 0; }
.btn-text:hover { color: var(--text); }
.back { display: inline-block; color: var(--text-2); text-decoration: none; font-size: 13px; margin-bottom: 14px; }
.back:hover { color: var(--text); }

/* ---------- Client detail ---------- */
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; align-content: start; }
.panel h3 { font-size: 13px; font-weight: 500; color: var(--text-2); }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.note { border-top: 1px solid var(--line); padding: 10px 0; white-space: pre-wrap; }
.note:first-child { border-top: 0; padding-top: 0; }

/* ---------- Modal ---------- */
.modal {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 22px;
}
.modal::backdrop { background: rgba(0, 0, 0, 0.66); }
.modal h1 { font-size: 18px; margin-bottom: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  background: var(--invert-bg);
  color: var(--invert-text);
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Small screens ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 14px 16px; gap: 12px; }
  .sidebar .wordmark { padding: 0; }
  .nav { display: flex; overflow-x: auto; gap: 4px; }
  .nav a { white-space: nowrap; gap: 6px; }
  .sidebar-foot { padding: 0; }
  .view { padding: 20px 16px 48px; }
  .detail-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .stat { border-right: 0; border-bottom: 1px solid var(--line); }
}
