/* ============================================================
   Pantria Design System
   Source of truth for colors, type, spacing, components.
   Adapted from the Pantria Design System bundle (Claude Design).
   ============================================================ */

/* ---- Fonts ---------------------------------------------------- */

@font-face {
  font-family: "DM Sans";
  src: url("/assets/DMSans-Regular-35e4cf28.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "DM Sans";
  src: url("/assets/DMSans-Medium-35e4cf28.woff2") format("woff2");
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "DM Sans";
  src: url("/assets/DMSans-SemiBold-35e4cf28.woff2") format("woff2");
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "DM Sans";
  src: url("/assets/DMSans-Bold-35e4cf28.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}

/* ---- Tokens (light, default) ---------------------------------- */

:root {
  /* Brand palette (raw) */
  --terracotta-50:  #faf1ec;
  --terracotta-100: #f3ddd0;
  --terracotta-200: #ecc4ae;
  --terracotta-300: #dfa07e;
  --terracotta-400: #d28461;
  --terracotta-500: #c97455;  /* primary */
  --terracotta-600: #b25f44;
  --terracotta-700: #8e4a35;
  --terracotta-800: #6a3826;
  --terracotta-900: #432114;

  --clay-50:  #fdfcfa;
  --clay-100: #f8f4ed;
  --clay-200: #f3ebe0;
  --clay-300: #e8dcc9;
  --clay-400: #cdbda4;
  --clay-500: #a89779;
  --clay-600: #7d6e54;
  --clay-700: #574a35;
  --clay-800: #3a3022;
  --clay-900: #2b2419;

  --olive-50:  #f1f3ec;
  --olive-100: #e1e6d4;
  --olive-200: #c8d2b1;
  --olive-300: #aebb8d;
  --olive-400: #94a26f;
  --olive-500: #7a8a6b;
  --olive-600: #5e6c4f;
  --olive-700: #46523c;
  --olive-800: #2f372a;
  --olive-900: #1c2118;

  --tomato-500: #c14a3a;
  --honey-500:  #d99c3d;
  --basil-500:  #6b8e4e;
  --slate-500:  #6b7280;

  /* Semantic surfaces & ink */
  --bg:           var(--clay-50);
  --bg-raised:    #ffffff;
  --bg-sunken:    var(--clay-100);
  --bg-panel:     var(--clay-200);
  --bg-inverse:   var(--clay-900);

  --fg-1: var(--clay-900);
  --fg-2: var(--clay-700);
  --fg-3: var(--clay-600);
  --fg-4: var(--clay-500);
  --fg-on-accent: #ffffff;
  --fg-on-inverse: var(--clay-100);

  --border-subtle:  var(--clay-300);
  --border-default: var(--clay-400);
  --border-strong:  var(--clay-700);
  --border-accent:  var(--terracotta-500);

  /* Interactive accent */
  --accent:            var(--terracotta-500);
  --accent-hover:      var(--terracotta-600);
  --accent-press:      var(--terracotta-700);
  --accent-soft:       var(--terracotta-50);
  --accent-soft-hover: var(--terracotta-100);
  --accent-soft-text:  var(--terracotta-700);

  --secondary:        var(--olive-500);
  --secondary-hover:  var(--olive-600);
  --secondary-soft:   var(--olive-50);
  --secondary-soft-text: var(--olive-700);

  /* Status */
  --success:      var(--basil-500);
  --success-soft: #eaf1de;
  --warning:      var(--honey-500);
  --warning-soft: #fbf1d9;
  --danger:       var(--tomato-500);
  --danger-soft:  #f7e1dc;
  --info:         var(--slate-500);
  --info-soft:    #eef0f3;

  /* Spacing (4px base) */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-7: 32px; --sp-8: 40px;
  --sp-9: 56px; --sp-10: 72px; --sp-11: 96px;

  /* Radii */
  --radius-xs:  4px; --radius-sm:  6px; --radius-md: 10px;
  --radius-lg: 12px; --radius-xl: 16px; --radius-2xl: 24px;
  --radius-pill: 999px;

  /* Shadows (warm-tinted) */
  --shadow-xs: 0 1px 1px rgba(67, 33, 20, 0.04);
  --shadow-sm: 0 1px 2px rgba(67, 33, 20, 0.05), 0 1px 1px rgba(67, 33, 20, 0.03);
  --shadow-md: 0 4px 8px -2px rgba(67, 33, 20, 0.06), 0 2px 4px -1px rgba(67, 33, 20, 0.04);
  --shadow-lg: 0 12px 24px -8px rgba(67, 33, 20, 0.10), 0 4px 8px -2px rgba(67, 33, 20, 0.05);
  --ring-focus: 0 0 0 3px rgba(201, 116, 85, 0.25);

  /* Type */
  --font-sans: "DM Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --fs-xs:   12px; --fs-sm:   13px; --fs-base: 15px; --fs-md:   16px;
  --fs-lg:   18px; --fs-xl:   22px; --fs-2xl:  28px; --fs-3xl:  36px;
  --fs-4xl:  48px;

  --lh-tight:   1.15; --lh-snug:    1.3;
  --lh-normal:  1.5;  --lh-relaxed: 1.65;

  --tracking-tight: -0.02em;
  --tracking-snug:  -0.01em;
  --tracking-wide:   0.04em;

  /* Motion */
  --ease-out:    cubic-bezier(0.22, 1, 0.36, 1);
  --dur-fast: 120ms; --dur-base: 200ms; --dur-slow: 320ms;
}

/* ---- Tokens (dark) -------------------------------------------- */

:root[data-theme="dark"] {
  --bg:           #181410;
  --bg-raised:    #221d17;
  --bg-sunken:    #100d0a;
  --bg-panel:     #2a241d;
  --bg-inverse:   var(--clay-100);

  --fg-1: #f1ece2;
  --fg-2: #cbc1ad;
  --fg-3: #9b9079;
  --fg-4: #6e6553;
  --fg-on-accent: #1b1410;
  --fg-on-inverse: var(--clay-900);

  --border-subtle:  #2e2820;
  --border-default: #3d362c;
  --border-strong:  #5b5240;
  --border-accent:  var(--terracotta-400);

  --accent:            var(--terracotta-400);
  --accent-hover:      var(--terracotta-300);
  --accent-press:      var(--terracotta-500);
  --accent-soft:       #2d211a;
  --accent-soft-hover: #3a2a21;
  --accent-soft-text:  var(--terracotta-200);

  --secondary:        var(--olive-300);
  --secondary-hover:  var(--olive-200);
  --secondary-soft:   #232a1d;
  --secondary-soft-text: var(--olive-100);

  --success-soft: #1f2a1a;
  --warning-soft: #2c2415;
  --danger-soft:  #2c1a17;
  --info-soft:    #1f242c;

  --shadow-xs: 0 1px 1px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 8px -2px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 12px 24px -8px rgba(0, 0, 0, 0.55);
  --ring-focus: 0 0 0 3px rgba(210, 132, 97, 0.35);
}

/* ---- Base ----------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--fg-1);
  background: var(--bg);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5 { color: var(--fg-1); margin: 0 0 var(--sp-4); font-weight: 600; }
h1 { font-size: var(--fs-3xl); line-height: var(--lh-tight); letter-spacing: var(--tracking-tight); }
h2 { font-size: var(--fs-2xl); line-height: var(--lh-tight); letter-spacing: var(--tracking-tight); }
h3 { font-size: var(--fs-xl);  line-height: var(--lh-snug); letter-spacing: var(--tracking-snug); }
h4 { font-size: var(--fs-lg);  line-height: var(--lh-snug); }
h5 { font-size: var(--fs-md);  line-height: var(--lh-snug); }

p { margin: 0 0 var(--sp-4); color: var(--fg-2); line-height: var(--lh-relaxed); }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

small, .caption { font-size: var(--fs-xs); color: var(--fg-3); }
.eyebrow {
  font-size: var(--fs-xs); font-weight: 500; letter-spacing: var(--tracking-wide);
  text-transform: uppercase; color: var(--fg-3);
}
code, .mono { font-family: var(--font-mono); font-size: 0.92em; }

hr { border: 0; border-top: 1px solid var(--border-subtle); margin: var(--sp-6) 0; }

/* ---- Layout primitives --------------------------------------- */

main { max-width: 1080px; margin: var(--sp-6) auto var(--sp-9); padding: 0 var(--sp-5); }

.grid {
  display: grid; gap: var(--sp-5);
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

/* ---- App header / nav ---------------------------------------- */

.app-header {
  display: flex; align-items: center; gap: var(--sp-5);
  padding: var(--sp-3) var(--sp-6);
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}
.app-header .brand {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  font-weight: 700; color: var(--accent); text-decoration: none;
  letter-spacing: var(--tracking-snug);
  font-size: var(--fs-md);
}
.app-header .brand img { width: 22px; height: 22px; }
.app-header .nav-link {
  color: var(--fg-2); text-decoration: none; font-weight: 500;
  font-size: var(--fs-sm);
  padding: var(--sp-1) var(--sp-2); border-radius: var(--radius-sm);
  transition: color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.app-header .nav-link:hover { color: var(--fg-1); background: var(--bg-sunken); text-decoration: none; }
.app-header .nav-spacer { flex: 1 1 auto; }
.app-header .user-email { color: var(--fg-3); font-size: var(--fs-sm); }
.app-header .locale {
  color: var(--fg-3); font-size: var(--fs-xs);
  display: inline-flex; gap: var(--sp-2); align-items: center;
}
.app-header .locale a { color: var(--fg-3); font-weight: 500; }
.app-header .locale a.active { color: var(--accent); font-weight: 700; }

/* ---- Card ---------------------------------------------------- */

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  margin-bottom: var(--sp-5);
  box-shadow: var(--shadow-sm);
}
.card-elev { box-shadow: var(--shadow-md); border-color: transparent; }
.card-flat { box-shadow: none; background: var(--bg-sunken); }
.card-warn { border-color: var(--warning); background: var(--warning-soft); }

/* ---- Buttons ------------------------------------------------- */

.btn {
  font-family: var(--font-sans); font-size: var(--fs-sm); font-weight: 500;
  padding: 9px 16px; border-radius: var(--radius-md);
  border: 1px solid transparent; cursor: pointer;
  display: inline-flex; align-items: center; gap: var(--sp-2);
  background: var(--accent); color: var(--fg-on-accent);
  text-decoration: none; line-height: 1.2;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.btn:hover  { background: var(--accent-hover); color: var(--fg-on-accent); text-decoration: none; }
.btn:active { background: var(--accent-press); }
.btn:focus-visible { outline: none; box-shadow: var(--ring-focus); }

.btn.secondary, .btn-secondary {
  background: var(--bg-raised); color: var(--fg-1); border-color: var(--border-subtle);
}
.btn.secondary:hover, .btn-secondary:hover { background: var(--bg-sunken); color: var(--fg-1); }

.btn.tertiary, .btn-tertiary {
  background: transparent; color: var(--fg-2); border-color: transparent;
}
.btn.tertiary:hover, .btn-tertiary:hover { background: var(--bg-panel); color: var(--fg-1); }

.btn.soft, .btn-soft {
  background: var(--accent-soft); color: var(--accent-soft-text);
}
.btn.soft:hover, .btn-soft:hover { background: var(--accent-soft-hover); color: var(--accent-soft-text); }

.btn.warn, .btn-danger {
  background: var(--danger); color: #fff;
}
.btn.warn:hover, .btn-danger:hover { background: var(--terracotta-700); }

.btn[disabled], .btn.disabled {
  background: var(--bg-panel); color: var(--fg-4);
  cursor: not-allowed; box-shadow: none;
}

.btn-sm { padding: 6px 12px; font-size: var(--fs-sm); border-radius: var(--radius-sm); }
.btn-lg { padding: 12px 20px; font-size: var(--fs-base); border-radius: var(--radius-lg); }

button.btn, input[type="submit"].btn, input[type="button"].btn { font: inherit; font-weight: 500; }

/* button_to renders a tiny <form> wrapper -- keep it inline so buttons sit
   alongside links/buttons without breaking flow. */
form.button_to { display: inline-block; margin: 0; }

/* ---- Form controls ------------------------------------------- */

input, select, textarea {
  font-family: var(--font-sans); font-size: var(--fs-sm);
  padding: 9px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-raised);
  color: var(--fg-1);
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
input::placeholder, textarea::placeholder { color: var(--fg-4); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring-focus);
}
input[type="file"] { padding: 6px 8px; }
input[disabled], select[disabled], textarea[disabled] {
  background: var(--bg-sunken); color: var(--fg-4); cursor: not-allowed;
}
label { font-size: var(--fs-xs); color: var(--fg-2); font-weight: 500; }

/* ---- Tables -------------------------------------------------- */

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: var(--fs-xs); font-weight: 500;
  letter-spacing: var(--tracking-wide); text-transform: uppercase;
  color: var(--fg-3);
  padding: var(--sp-3) var(--sp-3);
  border-bottom: 1px solid var(--border-subtle);
}
tbody td {
  padding: var(--sp-3); border-bottom: 1px solid var(--border-subtle);
  font-size: var(--fs-sm); color: var(--fg-1);
}
tbody tr:hover td { background: var(--bg-sunken); }

/* ---- Pills, chips, badges ------------------------------------ */

.pill, .chip {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  font-size: var(--fs-xs); font-weight: 500;
  padding: 3px var(--sp-3); border-radius: var(--radius-pill);
  background: var(--bg-panel); color: var(--fg-2);
  border: 1px solid transparent;
}
.pill.warn, .chip.warn  { background: var(--warning-soft); color: var(--clay-700); }
.pill.success, .chip.success { background: var(--success-soft); color: var(--olive-800); }
.pill.danger, .chip.danger { background: var(--danger-soft); color: var(--terracotta-800); }
.pill.info, .chip.info { background: var(--info-soft); color: var(--clay-800); }

.chip-active   { background: var(--accent); color: var(--fg-on-accent); }
.chip-soft     { background: var(--accent-soft); color: var(--accent-soft-text); }
.chip-olive    { background: var(--olive-100); color: var(--olive-700); }

/* Collapsible category sections on /offers. We swap the browser's
   default disclosure triangle for a custom chevron span that rotates
   to indicate state, so the heading row stays clean and on-brand. */
.offer-category > summary { user-select: none; }
.offer-category > summary::-webkit-details-marker { display: none; }
.offer-category > summary .offer-category__chevron {
  display: inline-block;
  transition: transform .15s ease;
  color: var(--clay-600, #6b6b6b);
}
.offer-category:not([open]) > summary .offer-category__chevron {
  transform: rotate(-90deg);
}

/* Watchlist match on /offers — soft terracotta tint + accent border so
   matched offers stand out without screaming. The pill in the top-right
   corner repeats the signal redundantly (color blindness, scanning). */
.offer-card--watched {
  border-left: 4px solid var(--terracotta-500);
  background: linear-gradient(90deg, var(--terracotta-50), transparent 55%);
  position: relative;
}
.offer-card__watched-pill {
  position: absolute;
  top: var(--sp-2);
  right: var(--sp-2);
  background: var(--terracotta-500);
  color: white;
  font-size: var(--fs-xs);
}

.badge {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  font-size: 11px; font-weight: 500;
  padding: 3px var(--sp-2); border-radius: var(--radius-pill);
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; }

/* ---- Flash --------------------------------------------------- */

.flash {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-5);
  border: 1px solid transparent;
  font-size: var(--fs-sm);
}
.flash.notice { background: var(--success-soft); color: var(--olive-800); border-color: var(--olive-200); }
.flash.alert  { background: var(--danger-soft);  color: var(--terracotta-800); border-color: var(--terracotta-200); }

/* ---- Misc ---------------------------------------------------- */

.scanner-video {
  width: 100%; max-width: 480px;
  border-radius: var(--radius-lg);
  background: #000;
  display: block;
}

/* ---- Receipt confirm: per-line cards instead of a wide table ---------- */
.receipt-line__head {
  display: flex; gap: var(--sp-3); align-items: flex-start; justify-content: space-between;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: var(--sp-2); margin-bottom: var(--sp-3);
}
.receipt-line__ocr {
  font-size: var(--fs-xs); color: var(--fg-3);
  white-space: pre-wrap; word-break: break-word;
  flex: 1 1 60%;
}
.receipt-line__totals {
  display: flex; gap: var(--sp-2); align-items: baseline; white-space: nowrap;
}
.receipt-line__grid {
  display: grid; gap: var(--sp-3);
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  align-items: end;
}
.receipt-line__field {
  display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0;
}
.receipt-line__field > label {
  font-size: var(--fs-xs); color: var(--fg-3);
}
.receipt-line__field > select,
.receipt-line__field > input[type="number"],
.receipt-line__field > input[type="date"] {
  width: 100%;
}
.receipt-line__field--wide {
  grid-column: span 2;
}
@media (max-width: 640px) {
  .receipt-line__field--wide { grid-column: auto; }
}

details > summary {
  cursor: pointer; font-weight: 500; color: var(--fg-2);
  padding: var(--sp-2) 0;
}
details[open] > summary { color: var(--fg-1); }

pre {
  background: var(--bg-sunken); padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-md); overflow-x: auto;
  font-size: var(--fs-xs); color: var(--fg-2);
}

/* ---- Responsive --------------------------------------------- */

@media (max-width: 640px) {
  .app-header { padding: var(--sp-3); gap: var(--sp-3); }
  .app-header .nav-spacer { display: none; }
  main { padding: 0 var(--sp-3); }
}
