/* ============================================================
   Samvey — base design system
   "Stationery precision": ink on paper, one highlighter.
   ============================================================ */

:root {
  --paper: #FBFAF7;
  --surface: #FFFFFF;
  --ink: #20242C;
  --ink-soft: #3A404B;
  --dim: #646A73;
  --faint: #9AA0A8;
  --line: #E8E6DF;
  --line-strong: #D6D3C9;
  --marker: #F8E971;
  --marker-wash: #FBF3BD;
  --cobalt: #2E5CE6;
  --cobalt-wash: #EDF1FD;
  --good: #1E9E6A;
  --good-wash: #E6F5EE;
  --bad: #D64545;
  --bad-wash: #FBEBEB;
  --warn: #B07D18;
  --warn-wash: #FBF3D9;

  --display: "Avenir Next", Seravek, "Segoe UI", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(32,36,44,.05), 0 4px 16px rgba(32,36,44,.06);
  --shadow-lg: 0 2px 6px rgba(32,36,44,.08), 0 12px 40px rgba(32,36,44,.14);
  --speed: 180ms;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
}
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
a { color: var(--cobalt); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; border-radius: 3px; }

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

/* ---------- typography ---------- */
h1, h2, h3, .display { font-family: var(--display); font-weight: 600; letter-spacing: -0.015em; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.dim { color: var(--dim); }
.faint { color: var(--faint); }
.small { font-size: 13px; }

.kicker {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--dim);
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-weight: 500; font-size: 14px;
  cursor: pointer;
  transition: background var(--speed), border-color var(--speed), transform var(--speed);
  white-space: nowrap;
}
.btn:hover { background: var(--paper); border-color: var(--faint); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: var(--ink-soft); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-wash); border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(32,36,44,.05); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: default; pointer-events: none; }

.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border: none; border-radius: 6px;
  background: transparent; color: var(--dim);
  cursor: pointer; font-size: 15px; line-height: 1;
}
.iconbtn:hover { background: rgba(32,36,44,.07); color: var(--ink); }

/* ---------- inputs ---------- */
.input, .select, .textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--cobalt); outline: none; box-shadow: 0 0 0 3px var(--cobalt-wash); }
.textarea { resize: vertical; min-height: 70px; }
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; font-weight: 500; color: var(--dim); margin-bottom: 5px; }

/* seamless inline editing — inputs that look like text until focused */
.inline-edit {
  width: 100%;
  border: none; background: transparent;
  border-radius: 4px; padding: 2px 4px; margin-left: -4px;
  transition: background var(--speed);
}
.inline-edit:hover { background: rgba(32,36,44,.04); }
.inline-edit:focus { background: var(--surface); outline: none; box-shadow: 0 0 0 2px var(--cobalt-wash), 0 0 0 1px var(--cobalt) inset; }
.inline-edit::placeholder { color: var(--faint); }

/* ---------- toggle switch ---------- */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; user-select: none; }
.switch input { position: absolute; opacity: 0; }
.switch .track {
  width: 34px; height: 20px; border-radius: 10px;
  background: var(--line-strong); transition: background var(--speed);
  flex-shrink: 0; position: relative;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2);
  transition: transform var(--speed);
}
.switch input:checked + .track { background: var(--ink); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { outline: 2px solid var(--cobalt); outline-offset: 2px; }

/* ---------- pills / badges ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 99px;
  font-size: 12px; font-weight: 500;
}
.pill.draft { background: rgba(32,36,44,.07); color: var(--dim); }
.pill.live { background: var(--good-wash); color: var(--good); }
.pill.closed { background: var(--warn-wash); color: var(--warn); }
.pill.live::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--good); }

/* ---------- marker swipe (the signature) ---------- */
.marker-swipe { position: relative; isolation: isolate; }
.marker-swipe::before {
  content: ""; position: absolute; inset: 0;
  background: var(--marker);
  border-radius: inherit;
  transform: scaleX(0); transform-origin: left center;
  z-index: -1;
  transition: transform var(--speed) cubic-bezier(.2,.8,.3,1);
}
.marker-swipe.on::before { transform: scaleX(1); }
@media (prefers-reduced-motion: reduce) { .marker-swipe::before { transition: none; } }

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- app chrome ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px; height: 54px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.topbar .spacer { flex: 1; }

.brand {
  display: inline-flex; align-items: baseline;
  font-family: var(--display); font-weight: 600; font-size: 19px;
  letter-spacing: -0.02em; color: var(--ink); text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand .swash { position: relative; z-index: 0; }
.brand .swash::after {
  content: ""; position: absolute; left: -2px; right: -2px; bottom: 1px;
  height: 7px; background: var(--marker); z-index: -1;
  border-radius: 2px; transform: rotate(-1.2deg);
}

.crumb { color: var(--dim); font-size: 14px; display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.crumb .sep { color: var(--line-strong); }
.crumb .here { color: var(--ink); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }

.tabnav { display: inline-flex; gap: 2px; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.tabnav button {
  border: none; background: transparent; padding: 5px 14px;
  border-radius: 6px; font-size: 13px; font-weight: 500; color: var(--dim); cursor: pointer;
}
.tabnav button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(32,36,44,.12); }

/* ---------- popover / menu ---------- */
.pop {
  position: absolute; z-index: 200;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 220px;
  animation: pop-in 120ms ease-out;
}
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.pop .menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 12px;
  border: none; background: none; text-align: left;
  font-size: 14px; cursor: pointer; color: var(--ink);
}
.pop .menu-item:hover { background: var(--paper); }
.pop .menu-item .mi-icon { width: 22px; text-align: center; flex-shrink: 0; }
.pop .menu-item .mi-sub { font-size: 12px; color: var(--faint); display: block; }
.pop .menu-sep { height: 1px; background: var(--line); margin: 4px 0; }
.pop .menu-head { padding: 8px 12px 4px; font-size: 11px; font-family: var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--faint); }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 500; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--ink); color: #fff;
  padding: 9px 18px; border-radius: 8px;
  font-size: 14px; box-shadow: var(--shadow-lg);
  animation: toast-in 200ms ease-out;
  display: flex; gap: 10px; align-items: center; max-width: 90vw;
}
.toast.warn { background: #7A5A10; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.toast.out { opacity: 0; transition: opacity 300ms; }

/* ---------- tally marks ---------- */
.tally { display: inline-flex; align-items: center; gap: 6px; }
.tally svg { display: block; }
.tally .stroke { stroke: var(--ink-soft); stroke-width: 1.6; stroke-linecap: round; }
.tally .slash { stroke: var(--cobalt); }

/* ---------- misc ---------- */
.empty-state {
  text-align: center; padding: 70px 20px; color: var(--dim);
}
.empty-state h2 { font-size: 20px; margin-bottom: 8px; color: var(--ink); }
.empty-state p { max-width: 400px; margin: 0 auto 18px; }

.banner {
  padding: 10px 16px; border-radius: var(--radius-sm);
  font-size: 13px; margin-bottom: 14px;
  display: flex; gap: 10px; align-items: flex-start;
}
.banner.warn { background: var(--warn-wash); color: var(--warn); }
.banner.bad { background: var(--bad-wash); color: var(--bad); }
.banner.info { background: var(--cobalt-wash); color: var(--cobalt); }

.kbd {
  display: inline-block; padding: 1px 6px;
  border: 1px solid var(--line-strong); border-bottom-width: 2px;
  border-radius: 4px; background: var(--surface);
  font-family: var(--mono); font-size: 11px; color: var(--dim);
}

::selection { background: var(--marker); color: var(--ink); }
