*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Skip link */
.skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    z-index: 9999;
    padding: 8px 16px;
    background: var(--primary);
    color: #fff;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}
.skip-link:focus {
    top: 0;
    outline: 3px solid var(--primary-hover);
    outline-offset: 2px;
}

:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-secondary: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --danger-hover: #b91c1c;

    --exp-expired: #dc2626;
    --exp-expired-bg: #fef2f2;
    --exp-warn-3: #ea580c;
    --exp-warn-3-bg: #fff7ed;
    --exp-warn-7: #ca8a04;
    --exp-warn-7-bg: #fefce8;
    --exp-ok: #16a34a;
    --exp-ok-bg: #f0fdf4;
    --exp-none: #6b7280;
    --exp-none-bg: #f9fafb;

    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);

    /* ── Icon size scale ─────────────────────────────────────────
       Canonical SVG icon sizes. Use these tokens (or the matching
       .icon-* utility classes below) rather than hard-coded pixel
       values on SVG width/height. See docs/ux/design-context.md
       for the full scale rationale and adoption guide.

       --icon-xs  14px  Compact / decorative (tight buttons, chips)
       --icon-sm  16px  Inline with body text, back-link chevrons
       --icon-md  20px  Default UI icon (list items, toolbar)
       --icon-lg  24px  Prominent action (menu toggle, stepper +/-)
       --icon-xl  32px  Section header / feature / empty-state glyph
       --icon-2xl 48px  Hero icons (home landing buttons, splash)
       ───────────────────────────────────────────────────────── */
    --icon-xs: 14px;
    --icon-sm: 16px;
    --icon-md: 20px;
    --icon-lg: 24px;
    --icon-xl: 32px;
    --icon-2xl: 48px;
}

/* Icon size utility classes. Apply to an <svg> to size it via the
   canonical scale. Prefer these over inline width/height attributes
   for any SVG whose size is page-structural (not intrinsic art). */
.icon-xs  { width: var(--icon-xs);  height: var(--icon-xs);  flex-shrink: 0; }
.icon-sm  { width: var(--icon-sm);  height: var(--icon-sm);  flex-shrink: 0; }
.icon-md  { width: var(--icon-md);  height: var(--icon-md);  flex-shrink: 0; }
.icon-lg  { width: var(--icon-lg);  height: var(--icon-lg);  flex-shrink: 0; }
.icon-xl  { width: var(--icon-xl);  height: var(--icon-xl);  flex-shrink: 0; }
.icon-2xl { width: var(--icon-2xl); height: var(--icon-2xl); flex-shrink: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 16px;
}

/* Header */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}
.header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
}
.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}
.header-nav-link {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--primary);
    text-decoration: none;
    white-space: nowrap;
}
.header-nav-link:hover, .header-nav-link:active {
    text-decoration: underline;
}
.header-nav-link--cta {
    font-weight: 600;
    background: rgba(37, 99, 235, 0.08);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
}
.header-nav-link--cta:hover, .header-nav-link--cta:active {
    background: rgba(37, 99, 235, 0.14);
}
.header-logo {
    color: inherit;
    text-decoration: none;
}
.header-user {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Mobile header menu toggle */
.header-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    border-radius: var(--radius-sm);
    -webkit-tap-highlight-color: transparent;
}
.header-menu-btn:hover { background: var(--bg); }
.header-menu-btn .icon-close { display: none; }
.header-menu-btn[aria-expanded="true"] .icon-menu { display: none; }
.header-menu-btn[aria-expanded="true"] .icon-close { display: block; }
.header-logout-form { display: inline; }

@media (max-width: 640px) {
    .header .container {
        flex-wrap: wrap;
    }
    .header-menu-btn {
        display: flex;
    }
    .header-right {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding-top: 12px;
        margin-top: 12px;
        border-top: 1px solid var(--border);
    }
    .header-right.open {
        display: flex;
    }
    .header-nav-link {
        display: flex;
        align-items: center;
        min-height: 44px;
        padding: 8px 0;
        font-size: 0.9375rem;
        border-bottom: 1px solid var(--border);
    }
    .header-right .btn {
        justify-content: center;
        min-height: 44px;
        margin-top: 4px;
    }
    .header-right .header-user {
        padding: 10px 0 4px;
        border-top: 1px solid var(--border);
        margin-top: 8px;
        font-size: 0.8125rem;
    }
    .header-logout-form {
        display: block;
        margin-top: 4px;
    }
    .header-logout-form .btn {
        width: 100%;
        justify-content: center;
    }
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
}
.btn:hover, .btn:active { background: var(--bg); border-color: #cbd5e1; }
.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.btn-primary:hover, .btn-primary:active {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}
.btn-danger {
    color: var(--danger);
    border-color: transparent;
    background: transparent;
    padding: 4px 8px;
}
.btn-danger:hover, .btn-danger:active {
    background: var(--exp-expired-bg);
}
.btn-sm { padding: 4px 10px; font-size: 0.75rem; min-height: 44px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text);
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    color: var(--text);
    background: var(--surface);
    transition: border-color 0.15s;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Alert */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    margin-bottom: 16px;
}
.alert-error {
    background: var(--exp-expired-bg);
    color: var(--exp-expired);
    border: 1px solid #fecaca;
}

/* Auth card */
.auth-wrapper {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-md);
}
.auth-card h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 24px;
    text-align: center;
}
.auth-card .btn-primary {
    width: 100%;
    padding: 10px;
    font-size: 0.9375rem;
    justify-content: center;
}
.auth-footer {
    text-align: center;
    margin-top: 16px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}
.auth-footer a { color: var(--primary); text-decoration: none; }
.auth-footer a:hover, .auth-footer a:active { text-decoration: underline; }

/* Page header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    flex-wrap: wrap;
    gap: 8px;
}
.page-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
}
.back-link {
    font-size: 0.8125rem;
    color: var(--primary);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.back-link:hover, .back-link:active { text-decoration: underline; }

/* Footer */
.site-footer {
    padding: 16px 0;
    border-top: 1px solid var(--border);
    margin-top: 32px;
}
.site-footer-link {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    text-decoration: none;
}
.site-footer-link:hover, .site-footer-link:active {
    color: var(--primary);
    text-decoration: underline;
}

/* ─────────────────────────────────────────────────────────────
   Modal primitive
   ─────────────────────────────────────────────────────────────
   Shared anatomy for every overlay/modal/dialog/sheet in the app.
   Page-specific classes layer on top to set max-width, padding,
   colors, etc. — they should NOT redeclare position, inset,
   backdrop color, z-index, or the show/hide mechanics.

   Two variants are supported:

   1. Centered card (DEFAULT, preferred for new overlays).
      Use `.modal-backdrop` + `.modal-sheet`.
      Show with `.visible` or `.active` on the backdrop.
      Card animates in with the `modal-in` keyframe.

   2. Bottom sheet (legacy / form-heavy mobile flows).
      Use `.modal-backdrop modal-backdrop--bottom`
        +  `.modal-sheet modal-sheet--bottom`.
      Show with `.active` on the backdrop.
      Sheet slides up from the bottom edge.

   Either toggle class (`.visible` or `.active`) shows the modal,
   so existing JavaScript keeps working unchanged.

   Policy for new overlays: prefer the centered-card variant.
   Reach for the bottom-sheet variant only for multi-field forms
   on mobile where the edge-anchored sheet improves reachability.
   ───────────────────────────────────────────────────────────── */
@keyframes modal-in {
    from { transform: translateY(16px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-backdrop.visible,
.modal-backdrop.active {
    display: flex;
}

.modal-sheet {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 24px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    max-height: 90dvh;
    overflow-y: auto;
    animation: modal-in 0.2s ease-out;
}

/* Bottom-sheet variant — slide-up from the bottom edge.
   Uses opacity (not display) on the backdrop so the sheet
   transform can animate. */
.modal-backdrop--bottom {
    display: flex;
    align-items: flex-end;
    padding: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.modal-backdrop--bottom.active,
.modal-backdrop--bottom.visible {
    display: flex;
    opacity: 1;
    pointer-events: auto;
}
.modal-sheet--bottom {
    border-radius: 16px 16px 0 0;
    padding: 0;
    animation: none;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}
.modal-backdrop--bottom.active .modal-sheet--bottom,
.modal-backdrop--bottom.visible .modal-sheet--bottom {
    transform: translateY(0);
}

/* Top-anchored variant — used by the recipe search overlay.
   Pulls the sheet toward the top of the viewport. */
.modal-backdrop--top {
    align-items: flex-start;
    padding-top: 10vh;
}

/* Snackbar */
.snackbar {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #1e293b;
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-md);
    transition: transform 0.3s ease;
    z-index: 1000;
}
.snackbar.visible {
    transform: translateX(-50%) translateY(0);
}
.snackbar button {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.3);
    color: #60a5fa;
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 600;
}
.snackbar button:hover, .snackbar button:active {
    background: rgba(255,255,255,0.1);
}
