/* ─────────────────────────────────────────────────────────────────
   BUKMAK — design tokens + base styles
   ───────────────────────────────────────────────────────────────── */

:root {
  /* Type */
  --font-sans: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-serif: "Instrument Serif", "Newsreader", ui-serif, Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* Accent — overridden by JS */
  --accent: #2f5d3f;
  --accent-ink: #ffffff;
  --accent-soft: color-mix(in oklab, var(--accent) 14%, transparent);
  --accent-line: color-mix(in oklab, var(--accent) 32%, transparent);

  /* Density — overridden by JS */
  --row-h: 52px;
  --pad-y: 14px;

  /* Radii */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;

  /* Light theme (default) */
  --bg: #f6f3eb;
  --surface: #fbf9f3;
  --surface-2: #f0ebdc;
  --ink: #15140f;
  --ink-2: #4a4640;
  --muted: #7a756c;
  --hairline: #e3dcc8;
  --border: #d8cfb6;
  --selected: color-mix(in oklab, var(--accent) 9%, transparent);
  --hover: rgba(0, 0, 0, 0.035);
  --danger: #a33a2a;
  --shadow-sm: 0 1px 0 rgba(20, 18, 12, 0.04);
  --shadow-md: 0 8px 30px rgba(20, 18, 12, 0.08), 0 2px 6px rgba(20, 18, 12, 0.04);
  --shadow-lg: 0 24px 64px rgba(20, 18, 12, 0.12), 0 6px 16px rgba(20, 18, 12, 0.06);
}

[data-theme="dark"] {
  --bg: #131210;
  --surface: #1c1a16;
  --surface-2: #24211c;
  --ink: #f1ece0;
  --ink-2: #b5ad9d;
  --muted: #837e74;
  --hairline: #2b2823;
  --border: #38332b;
  --selected: color-mix(in oklab, var(--accent) 22%, transparent);
  --hover: rgba(255, 255, 255, 0.04);
  --danger: #e67c6c;
  --shadow-sm: 0 1px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.5), 0 6px 16px rgba(0, 0, 0, 0.3);
}

/* Density variants */
[data-density="compact"] { --row-h: 40px; --pad-y: 10px; }
[data-density="regular"] { --row-h: 52px; --pad-y: 14px; }
[data-density="comfy"]   { --row-h: 64px; --pad-y: 18px; }

/* ───── Reset ───── */
* { box-sizing: border-box; }
html, body, #root { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11";
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }
::selection { background: var(--accent-soft); color: var(--ink); }

/* ───── Typography utilities ───── */
.serif-italic { font-family: var(--font-serif); font-style: italic; font-weight: 400; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ───── Buttons ───── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.005em;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(0.5px); }

.btn-ghost { color: var(--ink-2); }
.btn-ghost:hover { color: var(--ink); }

.btn-outline {
  border-color: var(--border);
  background: var(--surface);
}
.btn-outline:hover { background: var(--surface-2); border-color: var(--ink-2); }

.btn-primary {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.btn-primary:hover { background: color-mix(in oklab, var(--ink) 88%, var(--accent)); }

.btn-accent {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn-accent:hover { background: color-mix(in oklab, var(--accent) 88%, black); }

.btn-lg { height: 48px; padding: 0 22px; font-size: 15px; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 28px; }

/* ───── Inputs ───── */
.input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
  outline: none;
}
.input::placeholder { color: var(--muted); }
.input:hover { border-color: var(--ink-2); }
.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}

/* ───── Pills / chips ───── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: -0.005em;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 120ms ease;
  white-space: nowrap;
}
.chip:hover { background: var(--hover); color: var(--ink); }
.chip.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-line);
}
[data-theme="dark"] .chip.active { color: color-mix(in oklab, var(--accent) 60%, white); }

.chip-count {
  font-size: 10px;
  opacity: 0.55;
  margin-left: 2px;
}

/* ───── Cards / sections ───── */
.surface {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
}

/* ───── Common app shell ───── */
.shell-bg-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  background-image:
    radial-gradient(circle at 20% 30%, color-mix(in oklab, var(--accent) 4%, transparent) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, color-mix(in oklab, var(--ink) 3%, transparent) 0%, transparent 50%);
  mix-blend-mode: multiply;
}
[data-theme="dark"] .shell-bg-grain { mix-blend-mode: screen; opacity: 0.4; }

/* ───── Brand mark ───── */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.brand-mark {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.brand-mark svg { width: 100%; height: 100%; display: block; }
.brand-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.14em;
  white-space: nowrap;
}
.brand-name .dot {
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  margin: 0 1px 3px 0;
  vertical-align: middle;
}

/* Toast */
.toast-wrap {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: var(--r-sm);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: toast-in 200ms ease;
  pointer-events: auto;
}
.toast.error { background: var(--danger); color: white; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 18, 12, 0.4);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fade-in 160ms ease;
}
[data-theme="dark"] .modal-backdrop { background: rgba(0, 0, 0, 0.55); }
.modal {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  animation: modal-in 200ms cubic-bezier(.2,.9,.3,1.2);
}
.modal-hd {
  padding: 20px 24px 4px;
}
.modal-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}
.modal-sub {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}
.modal-body { padding: 16px 24px; }
.modal-ft {
  padding: 16px 24px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--ink-2);
  border: 2px solid transparent;
  background-clip: padding-box;
}

/* Focus ring */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:focus-visible, a:focus-visible {
  outline-offset: 3px;
}

/* Faint divider */
.hr {
  height: 1px;
  background: var(--hairline);
  border: 0;
  width: 100%;
}

/* Floating theme toggle (visible on landing/account/privacy) */
.float-theme {
  position: fixed;
  top: 16px;
  right: 24px;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--hairline);
  color: var(--ink-2);
  display: grid; place-items: center;
  z-index: 60;
  box-shadow: var(--shadow-sm);
  transition: all 160ms ease;
}
.float-theme:hover {
  color: var(--ink);
  border-color: var(--ink-2);
  transform: rotate(15deg);
}
/* On account/privacy pages where there's already a "Back" button top-right, shift theme to bottom-right */
.float-theme.lifted { top: auto; bottom: 24px; right: 24px; }
/* On spaces page, bottom-right so it doesn't collide */
.float-theme.spaces { top: auto; bottom: 72px; right: 24px; }

@media (max-width: 760px) {
  .float-theme { top: 12px; right: 12px; }
  .float-theme.lifted { top: auto; bottom: 16px; right: 16px; }
}

/* Hide some elements on small screens */
@media (max-width: 560px) {
  .hide-sm { display: none; }
}
