/* ==========================================================================
   Receipt Rabbit — shared design system
   Used by index.html (the app) and project.html (project dashboard).
   Palette + tokens from DESIGN_SPRINT.md. System fonts only, no build step.
   ========================================================================== */

:root {
  /* Palette (DESIGN_SPRINT.md) */
  --brand: #4f46e5;
  --brand-2: #7c3aed;
  --brand-soft: #eef2ff;
  --accent: #10b981;
  --accent-soft: #d1fae5;
  --warn: #f59e0b;
  --warn-soft: #fef3c7;
  --danger: #ef4444;
  --danger-soft: #fee2e2;

  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #94a3b8;
  --line: #e2e8f0;
  --line-2: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --bg: #f9fafb;

  /* Text-on-wash colours (readable in both themes) */
  --brand-ink: #4338ca;
  --accent-ink: #047857;
  --warn-ink: #b45309;
  --danger-ink: #b91c1c;
  --hint: #64748b;            /* --ink-3 is too faint for body-size text */

  --grad: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);

  /* Radius */
  --r-xs: 8px;
  --r-sm: 10px;
  --r-md: 12px;
  --r: 14px;
  --r-lg: 20px;

  /* Shadows — use sparingly */
  --shadow-sm: 0 1px 2px rgba(15,23,42,.04), 0 1px 3px rgba(15,23,42,.06);
  --shadow:    0 4px 12px rgba(15,23,42,.07), 0 2px 4px rgba(15,23,42,.04);
  --shadow-lg: 0 16px 40px rgba(15,23,42,.14), 0 4px 10px rgba(15,23,42,.06);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;

  --ease: cubic-bezier(.2,.7,.3,1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f1f5f9;
    --ink-2: #cbd5e1;
    --ink-3: #64748b;
    --line: #1e293b;
    --line-2: #172033;
    --surface: #0f172a;
    --surface-2: #1e293b;
    --bg: #020617;
    --brand-soft: #1e1b4b;
    --accent-soft: #064e3b;
    --warn-soft: #78350f;
    --danger-soft: #7f1d1d;

    --brand-ink: #a5b4fc;
    --accent-ink: #6ee7b7;
    --warn-ink: #fcd34d;
    --danger-ink: #fca5a5;
    --hint: #94a3b8;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow:    0 4px 14px rgba(0,0,0,.45);
    --shadow-lg: 0 18px 44px rgba(0,0,0,.6);
  }
}

/* ==========================================================================
   Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  min-height: 100dvh;
}
button, input, textarea, select { font: inherit; color: inherit; }
/* Native-feeling touch: no 300ms double-tap zoom delay, no grey tap flash */
a, button, input, select, textarea, label { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
p { margin: 0; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.hint { color: var(--hint); font-size: 13px; }
.skip-link {
  position: fixed; left: 12px; top: 12px; z-index: 300;
  padding: 10px 16px; border-radius: var(--r-sm);
  background: var(--brand); color: #fff; font-weight: 600;
  transform: translateY(-160%);
  transition: transform .15s var(--ease);
}
.skip-link:focus-visible { transform: none; text-decoration: none; }
.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;
}
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 6px;
}
[hidden] { display: none !important; }

.icon {
  width: 20px; height: 20px;
  flex-shrink: 0;
  fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
}
.icon.sm { width: 16px; height: 16px; }
.icon.lg { width: 24px; height: 24px; }

/* ==========================================================================
   Brand
   ========================================================================== */
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 17px; letter-spacing: -0.2px;
  color: var(--ink);
}
.brand:hover { text-decoration: none; }
.brand small {
  display: block;
  font-weight: 500; font-size: 11.5px; letter-spacing: 0;
  color: var(--hint);
}
.logo {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--grad);
  display: grid; place-items: center;
  box-shadow: 0 2px 6px rgba(79,70,229,.35);
  flex-shrink: 0;
}
.logo svg { width: 26px; height: 26px; margin-top: 1px; }
.logo.sm { width: 30px; height: 30px; border-radius: 9px; }
.logo.sm svg { width: 22px; height: 22px; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font-weight: 600; font-size: 14.5px;
  white-space: nowrap;
  text-decoration: none !important;
  transition: background .14s var(--ease), border-color .14s var(--ease),
              color .14s var(--ease), transform .14s var(--ease), box-shadow .14s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(.98); }

.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: var(--brand-2); box-shadow: var(--shadow); }

.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--ink-3); }

.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }

.btn-soft { background: var(--brand-soft); color: var(--brand-ink); }
.btn-soft:hover:not(:disabled) { filter: brightness(.97); }

.btn-danger { background: transparent; color: var(--danger-ink); border-color: var(--danger-soft); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }

.btn-white { background: #fff; color: var(--brand); box-shadow: 0 2px 8px rgba(15,23,42,.18); }
.btn-white:hover:not(:disabled) { background: #f5f3ff; }

.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 13px; border-radius: var(--r-sm); }
@media (pointer: coarse) { .btn-sm { min-height: 44px; } }
.btn-lg { min-height: 52px; padding: 14px 24px; font-size: 16px; border-radius: 14px; }
.btn-block { width: 100%; }
.btn-icon { min-height: 44px; width: 44px; padding: 0; }

/* ==========================================================================
   Surfaces
   ========================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 20px;
}
.card + .card { margin-top: 16px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 14px;
}
.card-head h2, .card-title { font-size: 16px; font-weight: 650; }
.card-head .hint { margin-top: 2px; }

.section-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  margin: 28px 0 12px;
}
.section-head h2 { font-size: 17px; font-weight: 650; }

/* ==========================================================================
   Badges, pills, dots
   ========================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.4;
  background: var(--surface-2); color: var(--ink-2);
  white-space: nowrap;
}
.badge.brand  { background: var(--brand-soft);  color: var(--brand-ink); }
.badge.accent { background: var(--accent-soft); color: var(--accent-ink); }
.badge.warn   { background: var(--warn-soft);   color: var(--warn-ink); }
.badge.danger { background: var(--danger-soft); color: var(--danger-ink); }
.badge.outline { background: transparent; border: 1px solid var(--line); }

.box-badge {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 100%;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  background: var(--brand-soft); color: var(--brand-ink);
  font-size: 13px; font-weight: 600;
}
.box-badge .no {
  display: inline-grid; place-items: center;
  min-width: 26px; height: 22px; padding: 0 6px;
  border-radius: 999px;
  background: var(--brand); color: #fff;
  font-size: 11.5px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap; flex-shrink: 0;
}
.box-badge .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--ink-3); }
.dot.good { background: var(--accent); }
.dot.mid  { background: var(--warn); }
.dot.low  { background: var(--danger); }

.conf {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.conf { color: var(--ink-2); }
.conf.strong.good { color: var(--accent-ink); }
.conf.strong.mid  { color: var(--warn-ink); }
.conf.strong.low  { color: var(--danger-ink); }
.conf .ok { width: 14px; height: 14px; color: var(--accent); stroke-width: 2.6; }

.meter {
  height: 6px; border-radius: 999px;
  background: var(--line-2);
  overflow: hidden;
}
.meter > span {
  display: block; height: 100%; border-radius: inherit;
  background: var(--grad);
  transition: width .5s var(--ease);
}
.meter.good > span { background: var(--accent); }
.meter.mid  > span { background: var(--warn); }
.meter.low  > span { background: var(--danger); }

/* ==========================================================================
   Tabs (segmented + underline)
   ========================================================================== */
.segmented {
  display: inline-flex; gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.segmented button {
  min-height: 38px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  border: 0; border-radius: 9px;
  background: transparent; color: var(--ink-2);
  font-weight: 600; font-size: 13.5px;
}
.segmented button[aria-selected="true"] {
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.tabs {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  min-height: 44px;
  padding: 10px 14px;
  border: 0; background: transparent;
  color: var(--ink-2); font-weight: 600; font-size: 14px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--brand-ink); border-bottom-color: var(--brand); }

/* ==========================================================================
   Forms
   ========================================================================== */
.input, .select, .textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  transition: border-color .14s, box-shadow .14s;
}
.input::placeholder, .textarea::placeholder { color: var(--hint); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent);
}
.select {
  appearance: none; -webkit-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
}
.textarea { resize: vertical; font-family: var(--mono); font-size: 13.5px; line-height: 1.55; }

.input-icon { position: relative; }
.input-icon .icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--hint); pointer-events: none;
}
.input-icon .input { padding-left: 40px; }

/* Switch */
.switch { position: relative; display: inline-block; width: 46px; height: 28px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span {
  position: absolute; inset: 0;
  border-radius: 999px;
  background: var(--line);
  transition: background .16s;
  pointer-events: none;
}
.switch span::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .16s var(--ease);
}
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.switch input:disabled { cursor: not-allowed; }
.switch input:disabled + span { opacity: .5; }

/* ==========================================================================
   Tables
   ========================================================================== */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td {
  text-align: left; vertical-align: top;
  padding: 10px 12px 10px 0;
  border-bottom: 1px solid var(--line-2);
}
.table th {
  font-size: 12px; font-weight: 600; color: var(--hint);
  text-transform: uppercase; letter-spacing: .4px;
  white-space: nowrap;
}
.table tr:last-child td { border-bottom: 0; }
.table td.r, .table th.r { text-align: right; padding-right: 0; }

/* ==========================================================================
   Feedback: empty, skeleton, toast, notice
   ========================================================================== */
.empty {
  text-align: center;
  padding: 40px 20px;
}
.empty-art {
  width: 72px; height: 72px;
  margin: 0 auto 14px;
  border-radius: 22px;
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand-ink);
}
.empty-art .icon { width: 32px; height: 32px; stroke-width: 1.6; }
.empty h2, .empty h3 { font-size: 17px; font-weight: 650; margin-bottom: 6px; }
.empty p { color: var(--ink-2); font-size: 14px; max-width: 360px; margin: 0 auto 18px; }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--line-2) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: 8px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.notice {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 14px;
}
.notice .icon { margin-top: 1px; }
.notice b { display: block; margin-bottom: 2px; }
.notice.warn   { background: var(--warn-soft);   border-color: transparent; color: var(--warn-ink); }
.notice.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger-ink); }
.notice.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); }
.notice.brand  { background: var(--brand-soft);  border-color: transparent; color: var(--brand-ink); }
.notice p { color: inherit; }

.toast-region {
  position: fixed; z-index: 200;
  top: calc(16px + var(--safe-top)); right: 16px;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-radius: var(--r-md);
  background: var(--ink); color: var(--bg);
  box-shadow: var(--shadow-lg);
  font-size: 14px; font-weight: 500;
  max-width: 360px;
  animation: toast-in .22s var(--ease);
  pointer-events: auto;
}
.toast.success { background: #047857; color: #fff; }
.toast.warn    { background: #b45309; color: #fff; }
.toast.error   { background: #b91c1c; color: #fff; }
.toast.out { opacity: 0; transform: translateX(12px); transition: all .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

.fade-in { animation: fade-in .32s var(--ease) both; }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (max-width: 640px) {
  .toast-region { left: 16px; right: 16px; align-items: stretch; }
  .toast { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
