/*
 * Material 3 Expressive, hand-built for the web.
 * Colour roles (--md-sys-color-*) are generated at runtime from a seed
 * colour by theme.js; the values below are the fallback "Walnut" light scheme.
 */
:root {
  --md-sys-color-primary: #7a5230;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #ffdcc0;
  --md-sys-color-on-primary-container: #5f3c1b;
  --md-sys-color-secondary: #725a46;
  --md-sys-color-on-secondary: #ffffff;
  --md-sys-color-secondary-container: #fddcc4;
  --md-sys-color-on-secondary-container: #594330;
  --md-sys-color-tertiary: #5a6237;
  --md-sys-color-on-tertiary: #ffffff;
  --md-sys-color-tertiary-container: #dfe8b0;
  --md-sys-color-on-tertiary-container: #424a22;
  --md-sys-color-error: #ba1a1a;
  --md-sys-color-on-error: #ffffff;
  --md-sys-color-error-container: #ffdad6;
  --md-sys-color-on-error-container: #93000a;
  --md-sys-color-surface: #fff8f5;
  --md-sys-color-on-surface: #221a14;
  --md-sys-color-surface-variant: #f2dfd3;
  --md-sys-color-on-surface-variant: #51443b;
  --md-sys-color-surface-container-lowest: #ffffff;
  --md-sys-color-surface-container-low: #fff1e8;
  --md-sys-color-surface-container: #faebe1;
  --md-sys-color-surface-container-high: #f4e5db;
  --md-sys-color-surface-container-highest: #eee0d6;
  --md-sys-color-surface-dim: #e6d7cd;
  --md-sys-color-surface-bright: #fff8f5;
  --md-sys-color-outline: #84746a;
  --md-sys-color-outline-variant: #d6c3b6;
  --md-sys-color-inverse-surface: #382e28;
  --md-sys-color-inverse-on-surface: #fdeee4;
  --md-sys-color-inverse-primary: #f1bb8d;
  --md-sys-color-scrim: #000000;
  --md-sys-color-shadow: #000000;

  /* Shape scale (M3 Expressive adds the "increased" steps). */
  --shape-xs: 4px;
  --shape-sm: 8px;
  --shape-md: 12px;
  --shape-lg: 16px;
  --shape-lg-inc: 20px;
  --shape-xl: 28px;
  --shape-xl-inc: 32px;
  --shape-2xl: 48px;
  --shape-full: 9999px;

  /* Motion: expressive springs approximated with overshooting curves. */
  --motion-spatial-fast: 350ms cubic-bezier(0.42, 1.67, 0.21, 0.9);
  --motion-spatial: 500ms cubic-bezier(0.38, 1.21, 0.22, 1);
  --motion-effects-fast: 150ms cubic-bezier(0.31, 0.94, 0.34, 1);
  --motion-effects: 200ms cubic-bezier(0.34, 0.8, 0.34, 1);

  --font-brand: "Google Sans Flex", "Google Sans", "Roboto Flex", Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-plain: "Roboto Flex", Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Roboto Mono", ui-monospace, "Cascadia Mono", Menlo, monospace;

  --elev-1: 0 1px 2px rgb(0 0 0 / 0.3), 0 1px 3px 1px rgb(0 0 0 / 0.15);
  --elev-2: 0 1px 2px rgb(0 0 0 / 0.3), 0 2px 6px 2px rgb(0 0 0 / 0.15);
  --elev-3: 0 4px 8px 3px rgb(0 0 0 / 0.15), 0 1px 3px rgb(0 0 0 / 0.3);

  color-scheme: light;
}
:root[data-mode="dark"] { color-scheme: dark; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-plain);
  font-size: 1rem;
  line-height: 1.5rem;
  letter-spacing: 0.03125rem;
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface);
  -webkit-font-smoothing: antialiased;
}
@media (prefers-reduced-motion: reduce) {
  :root { --motion-spatial-fast: 1ms linear; --motion-spatial: 1ms linear; --motion-effects-fast: 1ms linear; --motion-effects: 1ms linear; }
}

/* ---------- typography ---------- */
.display-l { font: 400 3.5625rem/4rem var(--font-brand); letter-spacing: -0.016rem; }
.display-m { font: 400 2.8125rem/3.25rem var(--font-brand); }
.display-s { font: 400 2.25rem/2.75rem var(--font-brand); }
.headline-l { font: 400 2rem/2.5rem var(--font-brand); }
.headline-m { font: 400 1.75rem/2.25rem var(--font-brand); }
.headline-s { font: 400 1.5rem/2rem var(--font-brand); }
.title-l { font: 400 1.375rem/1.75rem var(--font-brand); }
.title-m { font: 500 1rem/1.5rem var(--font-plain); letter-spacing: 0.009rem; }
.title-s { font: 500 0.875rem/1.25rem var(--font-plain); letter-spacing: 0.006rem; }
.body-l { font: 400 1rem/1.5rem var(--font-plain); }
.body-m { font: 400 0.875rem/1.25rem var(--font-plain); letter-spacing: 0.016rem; }
.body-s { font: 400 0.75rem/1rem var(--font-plain); letter-spacing: 0.025rem; }
.label-l { font: 500 0.875rem/1.25rem var(--font-plain); letter-spacing: 0.006rem; }
.label-m { font: 500 0.75rem/1rem var(--font-plain); letter-spacing: 0.031rem; }
.label-s { font: 500 0.6875rem/1rem var(--font-plain); letter-spacing: 0.031rem; }
/* Expressive emphasis: heavier weight for key moments. */
.emph { font-weight: 700 !important; }
h1, h2, h3, h4 { margin: 0; font-weight: inherit; }
.muted { color: var(--md-sys-color-on-surface-variant); }

/* ---------- icons ---------- */
.icon { width: 24px; height: 24px; fill: currentColor; flex: none; vertical-align: middle; }
.icon.sm { width: 18px; height: 18px; }
.icon.lg { width: 32px; height: 32px; }

/* ---------- state layer (hover / focus / press) ---------- */
.sl { position: relative; overflow: hidden; isolation: isolate; }
.sl::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: currentColor; opacity: 0; transition: opacity var(--motion-effects-fast);
}
.sl:hover::after { opacity: 0.08; }
.sl:focus-visible::after, .sl:active::after { opacity: 0.1; }
:focus-visible { outline: 3px solid var(--md-sys-color-secondary); outline-offset: 2px; }

/* ---------- buttons (shape morphs from round to square-ish on press) ---------- */
.btn {
  --btn-bg: var(--md-sys-color-primary);
  --btn-fg: var(--md-sys-color-on-primary);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 24px; border: none; border-radius: var(--shape-full);
  background: var(--btn-bg); color: var(--btn-fg);
  font: 500 0.875rem/1.25rem var(--font-plain); letter-spacing: 0.006rem; text-align: center; max-width: 100%;
  cursor: pointer; text-decoration: none; user-select: none; padding-block: 8px;
  transition: border-radius var(--motion-spatial-fast), box-shadow var(--motion-effects), background var(--motion-effects);
}
.btn .icon { width: 20px; height: 20px; margin-inline-start: -8px; }
.btn:active:not(:disabled) { border-radius: var(--shape-md); }
.btn.lg { min-height: 56px; padding: 0 32px; font-size: 1rem; border-radius: var(--shape-full); }
.btn.lg:active:not(:disabled) { border-radius: var(--shape-lg); }
.btn.sm { min-height: 32px; padding: 0 16px; }
.btn.tonal { --btn-bg: var(--md-sys-color-secondary-container); --btn-fg: var(--md-sys-color-on-secondary-container); }
.btn.tertiary { --btn-bg: var(--md-sys-color-tertiary-container); --btn-fg: var(--md-sys-color-on-tertiary-container); }
.btn.danger { --btn-bg: var(--md-sys-color-error); --btn-fg: var(--md-sys-color-on-error); }
.btn.elevated { --btn-bg: var(--md-sys-color-surface-container-low); --btn-fg: var(--md-sys-color-primary); box-shadow: var(--elev-1); }
.btn.outlined { --btn-bg: transparent; --btn-fg: var(--md-sys-color-on-surface-variant); border: 1px solid var(--md-sys-color-outline-variant); }
.btn.text { --btn-bg: transparent; --btn-fg: var(--md-sys-color-primary); padding: 0 12px; }
.btn.text.danger { --btn-fg: var(--md-sys-color-error); }
.btn:disabled { --btn-bg: color-mix(in srgb, var(--md-sys-color-on-surface) 10%, transparent); --btn-fg: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent); cursor: default; box-shadow: none; }
.btn.outlined:disabled, .btn.text:disabled { --btn-bg: transparent; }

.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0;
  border: none; border-radius: var(--shape-full); background: transparent; color: var(--md-sys-color-on-surface-variant);
  cursor: pointer; transition: border-radius var(--motion-spatial-fast), background var(--motion-effects);
}
.icon-btn:active { border-radius: var(--shape-md); }
.icon-btn.filled { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); }
.icon-btn.tonal { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.icon-btn.outlined { border: 1px solid var(--md-sys-color-outline-variant); }
.icon-btn.selected { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); border-radius: var(--shape-md); }
.icon-btn:disabled { color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent); cursor: default; }

.fab {
  display: inline-flex; align-items: center; gap: 12px; min-height: 56px; padding: 0 16px;
  border: none; border-radius: var(--shape-lg); cursor: pointer; box-shadow: var(--elev-3);
  background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container);
  font: 500 1rem/1.5rem var(--font-plain); transition: border-radius var(--motion-spatial-fast);
}
.fab:active { border-radius: var(--shape-xl); }
.fab.extended { padding: 0 20px 0 16px; }
.fab.large { min-height: 96px; padding: 0 28px; border-radius: var(--shape-xl); font-size: 1.375rem; }
.fab.large .icon { width: 36px; height: 36px; }

/* Connected button group (segmented). */
.seg { display: inline-flex; gap: 2px; flex-wrap: wrap; }
.seg > button {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 16px; border: none; cursor: pointer;
  background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container);
  border-radius: var(--shape-sm); font: 500 0.875rem/1.25rem var(--font-plain);
  transition: border-radius var(--motion-spatial-fast), background var(--motion-effects);
}
.seg > button:first-child { border-start-start-radius: var(--shape-full); border-end-start-radius: var(--shape-full); }
.seg > button:last-child { border-start-end-radius: var(--shape-full); border-end-end-radius: var(--shape-full); }
.seg > button[aria-pressed="true"] { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); border-radius: var(--shape-full); }
.seg > button .icon { width: 18px; height: 18px; }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 16px;
  border: 1px solid var(--md-sys-color-outline-variant); border-radius: var(--shape-sm);
  background: transparent; color: var(--md-sys-color-on-surface-variant); cursor: pointer;
  font: 500 0.875rem/1.25rem var(--font-plain); transition: background var(--motion-effects), border-radius var(--motion-spatial-fast);
}
.chip .icon { width: 18px; height: 18px; margin-inline-start: -4px; }
.chip[aria-pressed="true"] { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); border-color: transparent; border-radius: var(--shape-md); }

/* ---------- cards ---------- */
.card { border-radius: var(--shape-lg); padding: 16px; background: var(--md-sys-color-surface-container-highest); }
.card.elevated { background: var(--md-sys-color-surface-container-low); box-shadow: var(--elev-1); }
.card.outlined { background: var(--md-sys-color-surface); border: 1px solid var(--md-sys-color-outline-variant); }
.card.hero { border-radius: var(--shape-xl); padding: 24px; background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }
.card > h2, .card > h3 { margin-bottom: 12px; }

/* ---------- text fields (outlined) ---------- */
.field { position: relative; display: block; margin: 8px 0 4px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 56px; padding: 16px; border-radius: var(--shape-xs);
  border: 1px solid var(--md-sys-color-outline); background: transparent; color: var(--md-sys-color-on-surface);
  font: 400 1rem/1.5rem var(--font-plain); outline: none; transition: border-color var(--motion-effects);
}
.field textarea { min-height: 120px; resize: vertical; font-family: var(--font-mono); font-size: 0.875rem; }
.field select { appearance: none; padding-inline-end: 40px; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 22px) 26px, calc(100% - 17px) 26px; background-size: 5px 5px; background-repeat: no-repeat; }
.field input:hover, .field select:hover, .field textarea:hover { border-color: var(--md-sys-color-on-surface); }
.field input:focus, .field select:focus, .field textarea:focus { border: 2px solid var(--md-sys-color-primary); padding: 15px; }
.field > span {
  position: absolute; inset-inline-start: 12px; top: 16px; padding: 0 4px; pointer-events: none;
  color: var(--md-sys-color-on-surface-variant); background: var(--field-bg, var(--md-sys-color-surface));
  font: 400 1rem/1.5rem var(--font-plain); transition: all var(--motion-effects);
}
.field input:focus + span, .field input:not(:placeholder-shown) + span,
.field select + span, .field textarea + span {
  top: -9px; font-size: 0.75rem; line-height: 1rem;
}
.field input:focus + span, .field textarea:focus + span, .field select:focus + span { color: var(--md-sys-color-primary); }
.field.invalid input { border-color: var(--md-sys-color-error); }
.field.invalid > span, .field-error { color: var(--md-sys-color-error); }
.field-hint { display: block; padding: 4px 16px 0; font-size: 0.75rem; line-height: 1rem; color: var(--md-sys-color-on-surface-variant); }

/* ---------- switch ---------- */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 0; cursor: pointer; }
.switch-row .text { flex: 1; }
input.switch {
  appearance: none; flex: none; position: relative; width: 52px; height: 32px; margin: 0; cursor: pointer;
  border-radius: var(--shape-full); border: 2px solid var(--md-sys-color-outline); background: var(--md-sys-color-surface-container-highest);
  transition: background var(--motion-effects), border-color var(--motion-effects);
}
input.switch::before {
  content: ""; position: absolute; top: 50%; left: 6px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--md-sys-color-outline); transform: translateY(-50%);
  transition: all var(--motion-spatial-fast);
}
input.switch:checked { background: var(--md-sys-color-primary); border-color: var(--md-sys-color-primary); }
input.switch:checked::before { left: 22px; width: 24px; height: 24px; background: var(--md-sys-color-on-primary); }
input.switch:active::before { width: 28px; height: 28px; }
input.switch:disabled { opacity: 0.38; cursor: default; }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.li {
  display: flex; align-items: center; gap: 16px; min-height: 56px; padding: 8px 16px;
  color: inherit; text-decoration: none; border-radius: var(--shape-md);
}
a.li, button.li { cursor: pointer; width: 100%; border: none; background: none; text-align: start; font: inherit; }
.li .grow { flex: 1; min-width: 0; }
.li .grow > * { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li + .li { border-top: 1px solid var(--md-sys-color-outline-variant); }
.avatar {
  display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: var(--shape-full);
  background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container);
  font: 500 1rem/1 var(--font-brand); text-transform: uppercase;
}
.avatar.bot { border-radius: var(--shape-md); background: var(--md-sys-color-tertiary-container); color: var(--md-sys-color-on-tertiary-container); }
.badge {
  display: inline-grid; place-items: center; min-width: 16px; height: 16px; padding: 0 4px; border-radius: var(--shape-full);
  background: var(--md-sys-color-error); color: var(--md-sys-color-on-error); font: 500 0.6875rem/1 var(--font-plain);
}
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: var(--shape-full);
  background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); font: 500 0.75rem/1.25rem var(--font-plain);
}
.pill.primary { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); }
.pill.tertiary { background: var(--md-sys-color-tertiary-container); color: var(--md-sys-color-on-tertiary-container); }
.pill.error { background: var(--md-sys-color-error-container); color: var(--md-sys-color-on-error-container); }

/* ---------- dialog ---------- */
dialog.m3 {
  border: none; padding: 24px; max-width: min(560px, calc(100vw - 32px)); width: max-content; min-width: min(312px, calc(100vw - 32px));
  border-radius: var(--shape-xl); background: var(--md-sys-color-surface-container-high); color: var(--md-sys-color-on-surface);
  box-shadow: var(--elev-3);
}
dialog.m3[open] { animation: dlg-in var(--motion-spatial); }
dialog.m3::backdrop { background: rgb(0 0 0 / 0.32); }
dialog.m3 h2 { margin-bottom: 16px; }
dialog.m3 .actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
@keyframes dlg-in { from { opacity: 0; transform: scale(0.9) translateY(12px); } }

/* ---------- snackbar ---------- */
#snackbars { position: fixed; inset-inline: 0; bottom: 16px; z-index: 100; display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.snackbar {
  display: flex; align-items: center; gap: 12px; min-height: 48px; max-width: 560px; padding: 6px 8px 6px 16px; pointer-events: auto;
  border-radius: var(--shape-sm); background: var(--md-sys-color-inverse-surface); color: var(--md-sys-color-inverse-on-surface);
  box-shadow: var(--elev-3); animation: snack-in var(--motion-spatial-fast);
}
.snackbar .btn.text { --btn-fg: var(--md-sys-color-inverse-primary); }
@keyframes snack-in { from { opacity: 0; transform: translateY(24px) scale(0.9); } }
@media (max-width: 599px) { #snackbars { bottom: 96px; } }

/* ---------- navigation ---------- */
.nav-item {
  display: grid; justify-items: center; gap: 4px; padding: 0; border: none; background: none; cursor: pointer;
  color: var(--md-sys-color-on-surface-variant); text-decoration: none; font: 500 0.75rem/1rem var(--font-plain);
}
.nav-item .ind {
  position: relative; display: grid; place-items: center; width: 56px; height: 32px; border-radius: var(--shape-full);
  transition: background var(--motion-effects), width var(--motion-spatial-fast);
}
.nav-item .ind .badge { position: absolute; top: 0; inset-inline-end: 12px; }
.nav-item[aria-current="page"] { color: var(--md-sys-color-on-surface); }
.nav-item[aria-current="page"] .ind { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.nav-item:hover .ind { background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent); }
.nav-item[aria-current="page"]:hover .ind { background: var(--md-sys-color-secondary-container); }

/* ---------- loading indicator (expressive: morphing shape) ---------- */
.loader {
  width: 48px; height: 48px; margin: 32px auto; background: var(--md-sys-color-primary);
  animation: morph 1.4s var(--motion-spatial) infinite;
}
.loader.sm { width: 20px; height: 20px; margin: 0; background: currentColor; }
@keyframes morph {
  0% { border-radius: 50%; transform: rotate(0) scale(0.9); }
  25% { border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%; }
  50% { border-radius: 12px; transform: rotate(180deg) scale(1); }
  75% { border-radius: 70% 30% 50% 50% / 50% 60% 40% 50%; }
  100% { border-radius: 50%; transform: rotate(360deg) scale(0.9); }
}
.progress { position: relative; height: 4px; overflow: hidden; border-radius: var(--shape-full); background: var(--md-sys-color-secondary-container); }
.progress > i { position: absolute; inset: 0; width: 40%; border-radius: inherit; background: var(--md-sys-color-primary); animation: prog 1.5s ease-in-out infinite; }
@keyframes prog { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

/* ---------- tables ---------- */
table.m3 { width: 100%; border-collapse: collapse; font: 400 0.875rem/1.25rem var(--font-plain); }
table.m3 th { text-align: start; font-weight: 500; color: var(--md-sys-color-on-surface-variant); padding: 8px; border-bottom: 1px solid var(--md-sys-color-outline-variant); }
table.m3 td { padding: 10px 8px; border-bottom: 1px solid var(--md-sys-color-outline-variant); }
table.m3 tr.me td { background: color-mix(in srgb, var(--md-sys-color-primary) 10%, transparent); }
table.m3 .num { text-align: end; font-variant-numeric: tabular-nums; }

.divider { height: 1px; margin: 16px 0; background: var(--md-sys-color-outline-variant); border: 0; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: 16px; }
.stack.sm { gap: 8px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
