/* Bakkali Cut design system — every page links this first.
   Light "paper" theme by default (marketing, account, kit).
   [data-theme=editor] on <html> or any wrapper switches to the dark editor theme.
   Mobile first. Touch targets 44px. No build step, no framework. */

/* ---------------------------------------------------------------- tokens */
:root {
  --bg: #F7F6F3;
  --bg2: #EFEDE8;
  --panel: #FFFFFF;
  --panel2: #FAF9F6;
  --line: #E3E0D9;
  --line2: #CFCBC2;
  --ink: #16181C;
  --ink2: #3A3F46;
  --muted: #7C8189;
  --accent: #1F5EFF;
  --accent2: #0E2E8C;
  --accentSoft: #E7EDFF;
  --danger: #C8412F;
  --dangerSoft: #FBE9E6;
  --ok: #1E7F58;
  --okSoft: #E4F4EC;
  --warn: #A9711B;

  --r-xs: 6px;
  --r-sm: 10px;
  --r: 14px;
  --r-lg: 20px;
  --r-pill: 999px;

  --sh-1: 0 1px 2px rgba(20, 22, 26, .05);
  --sh-2: 0 2px 8px rgba(20, 22, 26, .07), 0 1px 2px rgba(20, 22, 26, .05);
  --sh-3: 0 10px 30px rgba(20, 22, 26, .10), 0 2px 8px rgba(20, 22, 26, .06);
  --sh-pop: 0 24px 60px rgba(20, 22, 26, .18);

  --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --tap: 44px;
  --pad: 16px;
  --maxw: 1240px;
}

[data-theme="editor"] {
  --bg: #0E1013;
  --bg2: #16191E;
  --panel: #16191E;
  --panel2: #1D2126;
  --line: #272C33;
  --line2: #363C45;
  --ink: #EDEFF2;
  --ink2: #C2C7CE;
  --muted: #838B95;
  --accent: #5B8CFF;
  --accent2: #A9C2FF;
  --accentSoft: #1B2740;
  --danger: #FF6F5C;
  --dangerSoft: #331B18;
  --ok: #3FCC94;
  --okSoft: #12291F;
  --warn: #E0A84A;
  --sh-1: 0 1px 2px rgba(0, 0, 0, .4);
  --sh-2: 0 2px 10px rgba(0, 0, 0, .45);
  --sh-3: 0 14px 40px rgba(0, 0, 0, .55);
  --sh-pop: 0 24px 70px rgba(0, 0, 0, .65);
  color-scheme: dark;
}

/* ---------------------------------------------------------------- base */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.15; font-weight: 650; letter-spacing: -.015em; }
h1 { font-size: 30px; }
h2 { font-size: 22px; }
h3 { font-size: 17px; }
h4 { font-size: 14px; }
p { margin: 0 0 1em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
small { font-size: 12.5px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
code, kbd, pre { font-family: var(--mono); font-size: .92em; }

img, canvas, svg, video { max-width: 100%; }

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 var(--pad); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.tight { gap: 6px; }
.spacer { flex: 1 1 auto; }
.center { text-align: center; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.upper { text-transform: uppercase; letter-spacing: .12em; font-size: 11.5px; font-weight: 600; }
.nowrap { white-space: nowrap; }
.hide { display: none !important; }

/* ---------------------------------------------------------------- buttons */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--line2);
  border-radius: var(--r-sm);
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-weight: 550;
  font-size: 14.5px;
  cursor: pointer;
  box-shadow: var(--sh-1);
  transition: background .14s ease, border-color .14s ease, transform .06s ease, box-shadow .14s ease, color .14s ease;
  user-select: none;
  text-decoration: none;
}
.btn:hover { background: var(--panel2); border-color: var(--muted); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-disabled { opacity: .5; pointer-events: none; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: var(--sh-2);
}
.btn.primary:hover { background: var(--accent2); border-color: var(--accent2); }
[data-theme="editor"] .btn.primary { color: #0B1020; }

.btn.ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--ink2);
}
.btn.ghost:hover { background: var(--bg2); border-color: transparent; color: var(--ink); }

.btn.danger { color: var(--danger); border-color: var(--line2); }
.btn.danger:hover { background: var(--dangerSoft); border-color: var(--danger); }

.btn.mini {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12.5px;
  border-radius: var(--r-xs);
  box-shadow: none;
}

.btn.block { width: 100%; }
.btn.round { border-radius: var(--r-pill); }

.btn.on, .btn[aria-pressed="true"] {
  background: var(--accentSoft);
  border-color: var(--accent);
  color: var(--accent2);
}
[data-theme="editor"] .btn.on, [data-theme="editor"] .btn[aria-pressed="true"] { color: var(--accent2); }

.btnbar { display: inline-flex; gap: 0; }
.btnbar .btn { border-radius: 0; margin-left: -1px; box-shadow: none; }
.btnbar .btn:first-child { border-radius: var(--r-sm) 0 0 var(--r-sm); margin-left: 0; }
.btnbar .btn:last-child { border-radius: 0 var(--r-sm) var(--r-sm) 0; }

/* ---------------------------------------------------------------- inputs */
input[type="text"], input[type="email"], input[type="number"], input[type="search"],
select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line2);
  border-radius: var(--r-sm);
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  box-shadow: var(--sh-1) inset;
  transition: border-color .14s ease, box-shadow .14s ease;
}
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accentSoft);
}
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
select {
  appearance: none;
  padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
input[type="color"] {
  width: 44px;
  height: 34px;
  min-height: 34px;
  padding: 2px;
  border: 1px solid var(--line2);
  border-radius: var(--r-xs);
  background: var(--panel);
  cursor: pointer;
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: var(--tap);
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--line2);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px;
  margin-top: -8px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--panel);
  box-shadow: var(--sh-1);
}
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line2); }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border: 2px solid var(--panel); border-radius: 50%; background: var(--accent); }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }

label { font-size: 13px; font-weight: 550; color: var(--ink2); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > .hint { font-size: 12px; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; gap: 10px; margin-bottom: 8px; }
.field.inline > label { flex: 0 0 92px; }
.field.inline > input, .field.inline > select { flex: 1 1 auto; }

.switch { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); cursor: pointer; }
.switch input { margin: 0; }

/* ---------------------------------------------------------------- surfaces */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px;
  box-shadow: var(--sh-1);
}
.card.flat { box-shadow: none; }
.card.pad-lg { padding: 22px; }
.card + .card { margin-top: 12px; }
.card > h3, .card > h4 { margin-top: 0; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); }
.divider { height: 1px; background: var(--line); margin: 14px 0; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: var(--r-pill);
  background: var(--bg2);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 550;
  color: var(--ink2);
}
.tag.ok { background: var(--okSoft); border-color: transparent; color: var(--ok); }
.tag.warn { background: var(--dangerSoft); border-color: transparent; color: var(--danger); }

.grid { display: grid; gap: 14px; }
.grid.g2 { grid-template-columns: 1fr; }
.grid.g3 { grid-template-columns: 1fr; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px var(--pad);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand {
  font-weight: 700;
  letter-spacing: -.02em;
  font-size: 16px;
  color: var(--ink);
}
.topbar .brand:hover { text-decoration: none; }
.topbar .brand, .topbar nav a { white-space: nowrap; }
.topbar > .btn { flex: 0 0 auto; }
.topbar nav {
  display: flex; gap: 2px; align-items: center;
  min-width: 0; overflow-x: auto; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.topbar nav::-webkit-scrollbar { display: none; }
.topbar nav a {
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--ink2);
  font-size: 14px;
  font-weight: 550;
}
@media (max-width: 520px) {
  .topbar { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .topbar nav a { padding: 8px 7px; font-size: 13px; }
}
.topbar nav a:hover { background: var(--bg2); text-decoration: none; color: var(--ink); }
.topbar nav a[aria-current="page"] { background: var(--panel); border: 1px solid var(--line); color: var(--ink); }

/* ---------------------------------------------------------------- toast */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: min(520px, calc(100vw - 24px));
}
.toast {
  pointer-events: auto;
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--r);
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  font-weight: 550;
  box-shadow: var(--sh-3);
  animation: toast-in .18s ease-out;
}
.toast.ok { background: var(--ok); color: #fff; }
.toast.bad { background: var(--danger); color: #fff; }
.toast.out { animation: toast-out .2s ease-in forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ---------------------------------------------------------------- modal */
.modal-host {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  background: rgba(12, 14, 18, .45);
  backdrop-filter: blur(3px);
}
.modal-host[hidden] { display: none; }
.modal {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--sh-pop);
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  animation: sheet-in .2s ease-out;
}
.modal h3 { margin-bottom: 10px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
@keyframes sheet-in { from { transform: translateY(20px); opacity: .6; } to { transform: none; opacity: 1; } }

.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--r);
  background: var(--accentSoft);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--ink);
  font-size: 14px;
}
.banner .btn { margin-left: auto; }

/* ---------------------------------------------------------------- scroll + misc */
.scroll-x {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.scroll-x::-webkit-scrollbar { height: 6px; }
.scroll-x::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 3px; }

.skeleton {
  background: linear-gradient(90deg, var(--bg2) 25%, var(--panel2) 37%, var(--bg2) 63%);
  background-size: 400% 100%;
  animation: sk 1.3s ease infinite;
  border-radius: var(--r-sm);
}
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------------------------------------------------------------- responsive */
@media (min-width: 640px) {
  body { font-size: 15px; }
  h1 { font-size: 36px; }
  .grid.g2 { grid-template-columns: 1fr 1fr; }
  .modal-host { align-items: center; padding: 24px; }
  .modal { border-radius: var(--r-lg); }
}
@media (min-width: 980px) {
  :root { --pad: 24px; }
  h1 { font-size: 42px; }
  .grid.g3 { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@media print {
  .topbar, .btn, .toast-host { display: none !important; }
  body { background: #fff; }
}
