/* Kohinga — shared design tokens & components */

:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --ink: #14141a;
  --ink-2: #2a2a32;
  --muted: #6b6b73;
  --subtle: #9a9aa1;
  --line: #e7e6e0;
  --line-soft: #efeee9;
  --row-hover: #fafaf7;
  --pos: #0f7a4d;
  --pos-soft: #e6f1ea;
  --neg: #b03b2c;
  --neg-soft: #f6e6e3;
}

html, body { background: var(--bg); }
body {
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.num     { font-variant-numeric: tabular-nums; }
.display { letter-spacing: -0.025em; font-weight: 500; }
.eyebrow { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }

.ink     { color: var(--ink); }
.ink-2   { color: var(--ink-2); }
.muted   { color: var(--muted); }
.subtle  { color: var(--subtle); }
.pos     { color: var(--pos); }
.neg     { color: var(--neg); }

.card     { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.hairline { border-color: var(--line); }
.rule     { height: 1px; background: var(--line); }

/* Hero pill */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--pos-soft); color: var(--pos);
  font-size: 12px; font-weight: 500;
}
.pill-neg   { background: var(--neg-soft); color: var(--neg); }
.pill-arrow {
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 6px solid currentColor;
}
.pill-arrow-down {
  border-top: 6px solid currentColor;
  border-bottom: 0;
}

/* Bars */
.bar-track { background: var(--line-soft); height: 6px; border-radius: 999px; overflow: hidden; }
.bar-fill  { height: 100%; border-radius: 999px; background: var(--ink); }

/* Category dots */
.dot { width: 8px; height: 8px; border-radius: 999px; display: inline-block; flex: none; }
.c-food      { background: #b9522a; }
.c-transport { background: #2f5fbf; }
.c-entertain { background: #6f3fb8; }
.c-health    { background: #2f7a3e; }
.c-digital   { background: #0e7a8a; }
.c-donate    { background: #b03470; }
.c-shop      { background: #b07a14; }
.c-uncat     { background: #6b6b73; }
.c-pos       { background: var(--pos); }

/* Brand + nav */
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--ink); color: var(--bg);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}
.nav-link       { color: var(--muted); font-size: 13px; }
.nav-link:hover { color: var(--ink); }
.nav-active     { color: var(--ink); font-weight: 500; }

/* Row */
.row:hover { background: var(--row-hover); }

/* ---- Form components ---- */

/* Filter chips */
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 12px; border-radius: 999px;
  font-size: 13px; color: var(--muted);
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer; user-select: none;
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.chip:hover { color: var(--ink); border-color: #d6d5cd; }
.chip-active {
  color: var(--bg); background: var(--ink); border-color: var(--ink);
}
.chip-count {
  font-size: 11px; padding: 1px 6px; border-radius: 999px;
  background: var(--line-soft); color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.chip-active .chip-count {
  background: rgba(255,255,255,0.14); color: rgba(255,255,255,0.72);
}

/* Search input */
.input {
  width: 100%;
  padding: 9px 14px 9px 36px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface);
  font-size: 14px; color: var(--ink);
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.input:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(20,20,26,0.06); }
.input::placeholder { color: var(--subtle); }

.input-wrap { position: relative; }
.input-wrap > svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--subtle); pointer-events: none;
}

/* Status tag */
.tag {
  display: inline-flex; align-items: center;
  font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 4px; font-weight: 500;
  white-space: nowrap;
}
.tag-taxable  { background: var(--pos-soft); color: var(--pos); }
.tag-excluded { background: var(--line-soft); color: var(--muted); }

/* Switch */
.switch {
  position: relative; width: 30px; height: 18px;
  background: #d8d7d0; border-radius: 999px;
  cursor: pointer; transition: background 0.15s ease;
  flex: none;
}
.switch::after {
  content: ''; position: absolute;
  width: 14px; height: 14px; border-radius: 999px;
  background: #fff; top: 2px; left: 2px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.18);
  transition: transform 0.15s ease;
}
.switch-on { background: var(--ink); }
.switch-on::after { transform: translateX(12px); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 999px;
  font-size: 13px; font-weight: 500;
  background: var(--ink); color: var(--bg);
  border: 1px solid var(--ink);
  cursor: pointer; user-select: none;
  transition: opacity 0.12s ease, background 0.12s ease;
}
.btn:hover { opacity: 0.9; }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn-ghost {
  background: transparent; color: var(--ink);
  border: 1px solid var(--line);
}
.btn-ghost:hover { background: var(--row-hover); border-color: #d6d5cd; }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }

/* Edit affordance (pencil) */
.edit-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 5px;
  color: var(--subtle); background: transparent;
  border: 0; cursor: pointer; flex: none;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}
.row:hover .edit-btn,
.edit-btn:focus-visible { opacity: 1; }
.edit-btn:hover { color: var(--ink); background: var(--line-soft); }

/* Stacked composition bar */
.stack-bar {
  display: flex; gap: 2px;
  width: 100%; height: 32px;
  border-radius: 8px; overflow: hidden;
  background: var(--line-soft);
}
.stack-seg {
  height: 100%; min-width: 2px;
  transition: opacity 0.12s ease;
}
.stack-bar:hover .stack-seg { opacity: 0.55; }
.stack-bar .stack-seg:hover { opacity: 1; }

/* Sparkline */
.spark { color: var(--ink); display: block; }
.spark .spark-line { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.spark .spark-fill { fill: currentColor; fill-opacity: 0.07; stroke: none; }

/* Empty state */
.empty {
  text-align: center;
  padding: 28px 16px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
}
.empty-title { color: var(--ink); font-size: 14px; font-weight: 500; margin-bottom: 4px; }
.empty-body { font-size: 13px; max-width: 38ch; margin: 0 auto 14px; line-height: 1.45; }

/* Dialog */
dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  max-width: 480px; width: calc(100% - 32px);
  box-shadow: 0 24px 64px rgba(20,20,26,0.18);
}
dialog::backdrop {
  background: rgba(20,20,26,0.36);
  backdrop-filter: blur(2px);
}
.dlg-head { padding: 20px 22px 14px; }
.dlg-title { font-size: 15px; font-weight: 500; }
.dlg-sub { font-size: 13px; color: var(--muted); margin-top: 4px; line-height: 1.5; }
.dlg-search { padding: 0 22px 12px; }
.dlg-body { padding: 0 14px 6px; max-height: 320px; overflow-y: auto; }
.dlg-foot {
  padding: 14px 22px 18px;
  display: flex; gap: 8px; justify-content: flex-end;
  border-top: 1px solid var(--line); margin-top: 8px;
}

/* Checkbox */
.check {
  width: 16px; height: 16px; border-radius: 4px;
  border: 1.5px solid #c9c8c1;
  background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center;
  flex: none;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.check svg { opacity: 0; color: var(--bg); }
.check-on { background: var(--ink); border-color: var(--ink); }
.check-on svg { opacity: 1; }

.src-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 8px; border-radius: 8px;
  cursor: pointer; user-select: none;
}
.src-row:hover { background: var(--row-hover); }

/* Category edit affordance + popover */
.cat-edit {
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer; user-select: none;
  border-radius: 4px; padding: 1px 4px; margin: -1px -4px;
  transition: background 0.12s ease;
}
.cat-edit:hover    { background: var(--line-soft); }
.cat-edit:hover .cat-caret { opacity: 1; }
.cat-caret { opacity: 0; transition: opacity 0.12s ease; color: var(--subtle); flex: none; }

.cat-pop {
  position: absolute; z-index: 100;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 16px 40px rgba(20,20,26,0.18);
  padding: 6px; min-width: 220px;
  animation: pop-in 0.12s ease;
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.cat-pop ul { display: flex; flex-direction: column; gap: 1px; }
.cat-pop li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  font-size: 13px; cursor: pointer; user-select: none;
}
.cat-pop li:hover { background: var(--row-hover); }
.cat-pop li[aria-selected="true"] { background: var(--line-soft); font-weight: 500; }
.cat-pop li[aria-selected="true"] .cat-pop-check { opacity: 1; }
.cat-pop-check { margin-left: auto; opacity: 0; color: var(--ink); flex: none; }

/* Buttons (sync) */
.btn-icon {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px;
  font-size: 12.5px; color: var(--muted);
  border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; user-select: none;
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.btn-icon:hover    { color: var(--ink); border-color: #d6d5cd; }
.btn-icon:disabled { opacity: 0.55; cursor: default; }
.btn-icon svg { flex: none; transition: transform 0.4s ease; }
.btn-icon.is-syncing svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Dialog centering — Chromium/Firefox both honour explicit margin auto. */
dialog[open] { margin: auto; }

/* Login page */
.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 1fr auto;
  padding: 24px;
}
.login-card {
  align-self: center;
  justify-self: center;
  width: 100%; max-width: 420px;
  padding: 40px 36px 36px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 64px rgba(20,20,26,0.06);
}
.login-brand {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 36px;
}
.login-eyebrow { margin-bottom: 12px; }
.login-title {
  font-size: 22px; font-weight: 500; letter-spacing: -0.01em;
  margin-bottom: 6px;
}
.login-sub { color: var(--muted); font-size: 14px; margin-bottom: 28px; }
.code-row {
  display: flex; align-items: center; gap: 8px;
  justify-content: center;
  margin-bottom: 18px;
}
.code-row.shake { animation: shake 0.32s ease; }
.code-row.submitting .code-box { opacity: 0.55; }
.code-row.success  .code-box { border-color: var(--pos); color: var(--pos); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.code-box {
  width: 44px; height: 56px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface);
  text-align: center;
  font-size: 24px; font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
  -moz-appearance: textfield;
}
.code-box::-webkit-outer-spin-button,
.code-box::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.code-box:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(20,20,26,0.06);
}
.code-sep { color: var(--subtle); font-size: 18px; padding: 0 2px; }
.login-status {
  text-align: center;
  font-size: 13px; color: var(--muted);
  min-height: 18px;
}
.login-status.login-error { color: var(--neg); }
.login-foot {
  text-align: center;
  color: var(--subtle);
  font-size: 11px;
  padding-bottom: 12px;
}

/* Sign-out link */
.signout-link {
  color: var(--subtle);
  font-size: 11px;
  letter-spacing: 0.04em;
  cursor: pointer;
  background: none; border: 0; padding: 0;
  font-family: inherit;
}
.signout-link:hover { color: var(--ink); }

/* Inline-edit state for descriptions */
[data-desc].editing {
  background: #fff;
  box-shadow: 0 0 0 1.5px var(--ink);
  border-radius: 4px;
  padding: 0 4px;
  margin: 0 -4px;
  outline: none;
  white-space: normal;
  cursor: text;
}