/* ============================================================
   kasirin — shared design system
   Warm cream + deep emerald + marigold. Light & dark.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=JetBrains+Mono:wght@500;700&display=swap');

:root {
  color-scheme: light;

  /* type */
  --font-ui: 'Plus Jakarta Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  /* brand */
  --brand-50:  #E9F7F1;
  --brand-100: #C8EBDD;
  --brand-200: #9BDCC5;
  --brand-300: #63C6A7;
  --brand-400: #2FAE8A;
  --brand-500: #0F8A63;
  --brand-600: #0B7A5A;
  --brand-700: #0A5C46;
  --brand-800: #074636;
  --brand-900: #053229;

  --accent-100: #FFF1D6;
  --accent-300: #FFD98A;
  --accent-400: #FFC53D;
  --accent-500: #F5A623;
  --accent-700: #A86400;

  --danger-50: #FDECEC;
  --danger-500: #D64545;
  --danger-700: #A32B2B;
  --ok-500: #17936C;
  --info-500: #2E6FD9;

  /* surfaces (light) */
  --bg: #F7F5EF;
  --bg-grad: radial-gradient(1200px 520px at 88% -12%, #E4F4EC 0%, rgba(228,244,236,0) 62%),
             radial-gradient(900px 420px at -8% 8%, #FDF2DC 0%, rgba(253,242,220,0) 58%);
  --surface: #FFFFFF;
  --surface-2: #FBFAF6;
  --surface-3: #F2F1EA;
  --line: #E6E3D9;
  --line-strong: #D5D1C4;
  --ink: #10231C;
  --ink-2: #37473F;
  --muted: #5F7168;
  --muted-2: #8C9A92;
  --on-brand: #FFFFFF;

  /* elevation */
  --shadow-sm: 0 1px 2px rgba(16,35,28,.06), 0 1px 3px rgba(16,35,28,.04);
  --shadow-md: 0 6px 20px -6px rgba(16,35,28,.16), 0 2px 6px rgba(16,35,28,.05);
  --shadow-lg: 0 24px 60px -22px rgba(16,35,28,.30), 0 6px 18px -8px rgba(16,35,28,.12);
  --shadow-brand: 0 12px 28px -12px rgba(11,122,90,.55);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-pill: 999px;

  --ring: 0 0 0 3px rgba(15,138,99,.28);
  --ease: cubic-bezier(.22,.61,.36,1);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #08120F;
  --bg-grad: radial-gradient(1100px 480px at 88% -14%, #10352A 0%, rgba(16,53,42,0) 60%),
             radial-gradient(800px 400px at -6% 6%, #2B2415 0%, rgba(43,36,21,0) 55%);
  --surface: #101E19;
  --surface-2: #14251F;
  --surface-3: #1A2E27;
  --line: #22362E;
  --line-strong: #2E463C;
  --ink: #EAF4EF;
  --ink-2: #CBDBD3;
  --muted: #92A79D;
  --muted-2: #7A9187;
  --brand-50: #0C2B22;
  --brand-100: #123D30;
  --brand-500: #2FAE8A;
  --brand-600: #35BF98;
  --on-brand: #04140F;
  --danger-50: #331B1B;
  --accent-100: #2E2513;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 8px 24px -8px rgba(0,0,0,.55);
  --shadow-lg: 0 30px 70px -24px rgba(0,0,0,.7);
  --ring: 0 0 0 3px rgba(47,174,138,.35);
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
a { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.15; letter-spacing: -.02em; font-weight: 800; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }
::selection { background: var(--brand-200); color: var(--brand-900); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; top: -60px; left: 12px; z-index: 200;
  background: var(--brand-600); color: var(--on-brand); padding: 10px 16px;
  border-radius: var(--r-md); font-weight: 700; transition: top .2s var(--ease);
}
.skip-link:focus { top: 12px; }

/* ---------- type helpers ---------- */
.h1 { font-size: clamp(2.1rem, 5vw, 3.5rem); letter-spacing: -.035em; text-wrap: balance; }
.h2 { font-size: clamp(1.55rem, 3.2vw, 2.3rem); letter-spacing: -.03em; text-wrap: balance; }
.h3 { font-size: 1.15rem; letter-spacing: -.015em; }
.lead { font-size: clamp(1rem, 1.35vw, 1.13rem); color: var(--muted); line-height: 1.65; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: .74rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase;
  color: var(--brand-600);
}
.eyebrow::before {
  content: ''; width: 18px; height: 2px; border-radius: 2px; background: currentColor; opacity: .55;
}
.muted { color: var(--muted); }
.tiny { font-size: .8rem; }
.small { font-size: .875rem; }
.bold { font-weight: 700; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- layout helpers ---------- */
.wrap { width: min(1180px, calc(100% - 40px)); margin-inline: auto; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 10px; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack > * + * { margin-top: var(--gap, 16px); }
.hidden { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--ink);
  --btn-border: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; min-height: 42px;
  font-size: .92rem; font-weight: 700; letter-spacing: -.01em;
  color: var(--btn-fg); background: var(--btn-bg);
  border: 1px solid var(--btn-border); border-radius: var(--r-md);
  transition: transform .12s var(--ease), box-shadow .18s var(--ease),
              background-color .18s var(--ease), border-color .18s var(--ease);
  white-space: nowrap; text-decoration: none;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0) scale(.985); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn svg { width: 18px; height: 18px; flex: none; }

.btn-primary {
  --btn-bg: linear-gradient(180deg, var(--brand-500), var(--brand-600));
  --btn-fg: var(--on-brand);
  --btn-border: transparent;
  box-shadow: var(--shadow-brand);
}
.btn-primary:hover { box-shadow: 0 16px 32px -14px rgba(11,122,90,.7); }
.btn-accent {
  --btn-bg: linear-gradient(180deg, var(--accent-400), var(--accent-500));
  --btn-fg: #2A1B00; --btn-border: transparent;
  box-shadow: 0 12px 26px -12px rgba(245,166,35,.65);
}
.btn-ghost { --btn-bg: transparent; --btn-border: transparent; --btn-fg: var(--ink-2); }
.btn-ghost:hover { --btn-bg: var(--surface-3); box-shadow: none; }
.btn-soft { --btn-bg: var(--brand-50); --btn-fg: var(--brand-700); --btn-border: var(--brand-100); }
[data-theme="dark"] .btn-soft { --btn-fg: var(--brand-300); }
.btn-danger { --btn-bg: var(--danger-50); --btn-fg: var(--danger-700); --btn-border: transparent; }
[data-theme="dark"] .btn-danger { --btn-fg: #FF9A9A; }
.btn-lg { padding: 14px 22px; min-height: 52px; font-size: 1rem; border-radius: var(--r-lg); }
.btn-sm { padding: 7px 12px; min-height: 34px; font-size: .82rem; border-radius: var(--r-sm); }
.btn-icon { width: 40px; height: 40px; min-height: 40px; padding: 0; border-radius: var(--r-md); }
.btn-block { width: 100%; }

/* ---------- inputs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label {
  font-size: .78rem; font-weight: 700; letter-spacing: .02em;
  color: var(--muted); text-transform: uppercase;
}
.input, .select, .textarea {
  width: 100%; padding: 11px 13px; min-height: 44px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease);
  font-size: .95rem;
}
.input::placeholder, .textarea::placeholder { color: var(--muted-2); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand-500); box-shadow: var(--ring);
}
.textarea { min-height: 84px; resize: vertical; line-height: 1.55; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236A7C73' stroke-width='2.4' stroke-linecap='round'><path d='m6 9 6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 38px;
}
.input-affix { position: relative; }
.input-affix .prefix {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-weight: 700; font-size: .9rem; pointer-events: none;
}
.input-affix .input { padding-left: 40px; }
.help { font-size: .78rem; color: var(--muted); }

/* switch */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 44px; height: 26px; border-radius: var(--r-pill);
  background: var(--line-strong); position: relative; transition: background .2s var(--ease);
  flex: none;
}
.switch .track::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: transform .2s var(--ease);
}
.switch input:checked + .track { background: var(--brand-500); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { box-shadow: var(--ring); }

/* segmented */
.segment {
  display: inline-flex; padding: 4px; gap: 3px;
  background: var(--surface-3); border-radius: var(--r-pill);
  border: 1px solid var(--line);
}
.segment button {
  padding: 7px 14px; border-radius: var(--r-pill);
  font-size: .84rem; font-weight: 700; color: var(--muted);
  transition: all .16s var(--ease);
}
.segment button[aria-pressed="true"] {
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm);
}

/* chips */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: var(--r-pill);
  background: var(--surface); border: 1px solid var(--line-strong);
  font-size: .84rem; font-weight: 600; color: var(--ink-2);
  transition: all .16s var(--ease); white-space: nowrap;
}
.chip:hover { border-color: var(--brand-400); color: var(--brand-700); }
.chip[aria-pressed="true"] {
  background: var(--brand-600); border-color: var(--brand-600); color: var(--on-brand);
}
.chip .count { font-size: .74rem; opacity: .72; font-variant-numeric: tabular-nums; }

/* badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: var(--r-pill);
  font-size: .72rem; font-weight: 800; letter-spacing: .01em;
  background: var(--surface-3); color: var(--muted);
}
.badge.ok { background: var(--brand-50); color: var(--brand-700); }
.badge.warn { background: var(--accent-100); color: var(--accent-700); }
.badge.danger { background: var(--danger-50); color: var(--danger-700); }
[data-theme="dark"] .badge.ok { color: var(--brand-300); }
[data-theme="dark"] .badge.warn { color: var(--accent-300); }
[data-theme="dark"] .badge.danger { color: #FF9A9A; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 18px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.card-head h3 { font-size: 1rem; letter-spacing: -.015em; }

/* tables */
.table-wrap { width: 100%; overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.tbl th {
  text-align: left; font-size: .72rem; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted); font-weight: 800; padding: 10px 14px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tbody tr:hover { background: var(--surface-2); }

/* modal */
.modal-root { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 16px; }
.modal-root[hidden] { display: none; }
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(8,22,17,.46);
  backdrop-filter: blur(3px); animation: fade .18s var(--ease);
}
.modal {
  position: relative; width: min(560px, 100%); max-height: min(90vh, 900px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-xl); box-shadow: var(--shadow-lg);
  animation: pop .22s var(--ease); overflow: hidden;
}
.modal.wide { width: min(760px, 100%); }
.modal.narrow { width: min(430px, 100%); }
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
  padding: 20px 20px 14px;
}
.modal-head h2 { font-size: 1.15rem; letter-spacing: -.02em; }
.modal-head p { color: var(--muted); font-size: .86rem; margin-top: 4px; }
.modal-body { padding: 0 20px 8px; overflow: auto; }
.modal-foot {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 16px 20px 20px; border-top: 1px solid var(--line); margin-top: auto;
  background: var(--surface);
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* toast */
.toast-host {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 120; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: min(440px, calc(100% - 24px));
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: var(--r-md);
  background: #10231C; color: #F2FBF6; font-size: .88rem; font-weight: 600;
  box-shadow: var(--shadow-lg); animation: toastIn .24s var(--ease);
  width: 100%;
}
.toast.ok { background: #0A5C46; }
.toast.err { background: #8F2B2B; }
.toast button {
  margin-left: auto; color: #fff; font-weight: 800; font-size: .8rem;
  text-decoration: underline; text-underline-offset: 2px; padding: 2px 4px;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } }

/* empty state */
.empty {
  display: grid; place-items: center; gap: 10px;
  padding: 44px 22px; text-align: center; color: var(--muted);
}
.empty .ic {
  width: 54px; height: 54px; border-radius: 18px; display: grid; place-items: center;
  background: var(--surface-3); color: var(--muted);
}
.empty h4 { font-size: 1rem; color: var(--ink); }
.empty p { font-size: .88rem; max-width: 34ch; }

/* misc */
.divider { height: 1px; background: var(--line); border: 0; margin: 0; }
.scroll-y { overflow-y: auto; }
.skeleton {
  background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3));
  background-size: 200% 100%; animation: sk 1.2s linear infinite; border-radius: 8px;
}
@keyframes sk { to { background-position: -200% 0; } }
.kbd {
  font-family: var(--font-mono); font-size: .7rem; font-weight: 700;
  padding: 2px 6px; border-radius: 6px; border: 1px solid var(--line-strong);
  background: var(--surface-3); color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  html { scroll-behavior: auto; }
}
