:root {
    --bg: #ffffff;
    --panel: #fafaf8;
    --line: #e4e4e0;
    --line-soft: #eeeeea;
    --line-strong: #d6d6d1;
    --ink: #1a1a1a;
    --ink-2: #3a3a37;
    --muted: #5f5f5a;
    --accent: #2f6b3a;
    --accent-dark: #1f4a27;
    --accent-soft: #e3ede4;
    --warn-bg: #fff6e5;
    --warn-line: #9a5b00;
    --warn-ink: #7a4700;
    --danger: #a12a1e;
    --display: "Space Grotesk", system-ui, sans-serif;
    --topbar-h: 57px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
h1:focus { outline: none; }
a { color: var(--accent-dark); }
img { display: block; max-width: 100%; }
code { font-size: 0.92em; background: var(--line-soft); padding: 1px 5px; border-radius: 4px; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
.spacer { flex: 1 1 auto; }
.icon { flex: 0 0 auto; }
.mobile-only { display: none !important; }

/* ---------- Buttons and fields ---------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 0 16px;
    border: 1px solid var(--line-strong); border-radius: 6px;
    background: var(--bg); color: var(--ink);
    font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--panel); }
.btn:disabled, .btn.is-busy { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-quiet { border-color: transparent; background: transparent; }
.btn-dashed { border-style: dashed; border-color: #b9b9b3; background: transparent; color: var(--accent-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #7f2017; }
.btn-danger-text { color: var(--danger); }
.btn-wide { min-width: 200px; min-height: 48px; }
.btn:focus-visible, .btn:focus-within, .icon-btn:focus-visible, .row:focus-visible, .recipe-row:focus-visible,
.thumb-btn:focus-visible, .link-btn:focus-visible, .wordmark:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px;
}

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    flex: 0 0 44px; width: 44px; height: 44px;
    border: 0; border-radius: 6px; background: transparent; color: var(--muted);
    cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--line-soft); color: var(--ink); }

.link-btn {
    min-height: 44px; padding: 0; border: 0; background: transparent;
    color: var(--accent-dark); text-decoration: underline; cursor: pointer; font-size: 14px;
}

.field {
    width: 100%; min-width: 0; height: 44px; padding: 0 12px;
    border: 1px solid var(--line-strong); border-radius: 6px; background: var(--bg);
}
textarea.field { height: auto; padding: 10px 12px; line-height: 1.5; resize: vertical; }
.field:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field.chk { border: 2px solid var(--warn-line); background: var(--warn-bg); }
.field-title { height: 52px; font-size: 20px; font-weight: 600; }
.field-below { margin-top: 8px; }
.lbl { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 500; color: var(--ink-2); }
.hint { font-size: 14px; color: var(--muted); }
.flag { display: block; margin-top: 4px; font-size: 13px; font-weight: 600; color: var(--warn-ink); }
.empty { padding: 16px 12px; font-size: 14px; color: var(--muted); }

.notice { padding: 10px 14px; border-radius: 8px; background: var(--line-soft); font-size: 15px; }
.notice-error { background: #fbeceb; color: #7f2017; }
.notice-check { background: var(--warn-bg); color: #5c3600; }

/* ---------- Shell ---------- */

.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 6px 20px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.wordmark { font-family: var(--display); font-weight: 700; font-size: 20px; letter-spacing: -0.01em; color: var(--ink); text-decoration: none; }
.account { display: flex; align-items: center; gap: 4px; margin: 0; }
.account-name { font-size: 14px; color: var(--muted); max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Three columns + detail ---------- */

.browser {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: 200px 200px 280px minmax(0, 1fr);
    align-items: stretch;
}

.col { min-width: 0; padding: 8px; border-right: 1px solid var(--line); background: var(--panel); }
.col-recipes { background: var(--bg); }
.col-head { display: flex; align-items: center; justify-content: space-between; min-height: 44px; padding-left: 12px; }
.col-head h2 { font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.col-actions { display: flex; }
.col-add { display: flex; gap: 6px; margin: 0 4px 8px; }
.col-add .btn { padding: 0 12px; }
.col-edit { flex-wrap: wrap; }
.col-edit .field { flex: 1 1 100%; }
.col-edit .btn { flex: 1 1 auto; }
.col-notice { margin: 0 4px 8px; font-size: 14px; }

.row {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    min-height: 44px; padding: 0 12px; border-radius: 6px;
    color: var(--ink); text-decoration: none;
}
.row:hover { background: var(--line-soft); }
.row.on { background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }
.count { font-size: 13px; font-weight: 400; color: var(--muted); }

.search { position: relative; margin: 0 4px 8px; }
.search .icon { position: absolute; left: 12px; top: 14px; color: var(--muted); }
.search .field { padding-left: 36px; }

.recipe-row {
    display: flex; align-items: center; gap: 12px;
    padding: 8px 12px; border-radius: 6px; color: var(--ink); text-decoration: none;
}
.recipe-row:hover { background: var(--line-soft); }
.recipe-row.on { background: var(--accent-soft); color: var(--accent-dark); }
.recipe-row-text { display: flex; flex-direction: column; min-width: 0; }
.recipe-row-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recipe-row.on .recipe-row-name { font-weight: 600; }
.recipe-row-meta { font-size: 13px; color: var(--muted); min-height: 19px; }
.thumb { flex: 0 0 52px; width: 52px; height: 44px; border-radius: 4px; object-fit: cover; }
.thumb-empty { background: repeating-linear-gradient(135deg, #ececE8 0 8px, var(--line) 8px 16px); }

.detail { min-width: 0; padding: 24px 40px 64px; }
.detail-empty { max-width: 420px; margin: 12vh auto 0; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 20px; }
.detail-empty-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.message-page { max-width: 420px; margin: 12vh auto 0; padding: 0 16px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.message-page h1 { font-family: var(--display); font-size: 28px; }

.mobile-bar { display: none; }

/* ---------- Recipe view ---------- */

.recipe { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.recipe-bar { display: flex; align-items: center; gap: 8px; }
.recipe-cover { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; background: var(--line-soft); }
.thumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.thumb-btn { position: relative; width: 88px; height: 60px; padding: 0; border: 0; border-radius: 6px; overflow: hidden; background: var(--line-soft); cursor: pointer; }
.thumb-btn img { width: 100%; height: 100%; object-fit: cover; }
.thumb-btn.on { outline: 2px solid var(--accent); outline-offset: 2px; }
.thumb-tag { position: absolute; left: 4px; bottom: 4px; padding: 0 5px; border-radius: 3px; background: rgba(26, 26, 26, 0.8); color: #fff; font-size: 11px; font-weight: 600; }
.thumbs .btn-dashed { min-height: 60px; }

.recipe-head { display: flex; flex-direction: column; gap: 6px; }
.recipe-kicker { font-size: 14px; color: var(--muted); }
.recipe-head h1 { font-family: var(--display); font-weight: 700; font-size: 44px; line-height: 1.1; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.recipe-meta { display: flex; flex-wrap: wrap; gap: 20px; margin-top: 4px; font-size: 15px; color: var(--ink-2); }
.recipe-meta strong { font-weight: 600; }

.recipe-body { display: flex; flex-wrap: wrap; gap: 40px; padding-top: 24px; border-top: 1px solid var(--line); }
.recipe-body h2, .editor h2 { margin-bottom: 12px; font-family: var(--display); font-weight: 600; font-size: 20px; }
.recipe-ingredients { flex: 1 1 220px; min-width: 0; }
.recipe-method { flex: 2 1 340px; min-width: 0; }
.recipe-ingredients ul, .recipe-method ol { list-style: none; margin: 0; padding: 0; }
.recipe-ingredients li { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.recipe-ingredients li:last-child { border-bottom: 0; }
.amount { flex: 0 0 72px; font-weight: 600; font-variant-numeric: tabular-nums; }
.recipe-method ol { display: flex; flex-direction: column; gap: 18px; font-size: 17px; line-height: 1.6; }
.recipe-method li { display: flex; gap: 16px; }
.step-no { flex: 0 0 26px; font-family: var(--display); font-weight: 700; font-size: 20px; color: var(--accent); }
.step-text { white-space: pre-line; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Editor ---------- */

.editor { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 28px; }
.editor-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.editor-head h1 { font-family: var(--display); font-weight: 700; font-size: 28px; letter-spacing: -0.01em; }
.editor-actions { display: flex; gap: 8px; }
.editor-section { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.editor-section h2 { margin-bottom: 0; }
.editor-section h3 { font-size: 15px; font-weight: 600; margin-top: 8px; }
.editor-grid { display: flex; flex-wrap: wrap; gap: 16px; }
.grow2 { flex: 2 1 180px; min-width: 0; }
.grow1 { flex: 1 1 100px; min-width: 0; }
.editor-columns { display: flex; flex-wrap: wrap; gap: 40px; }
.editor-columns > .editor-section { flex: 1 1 300px; }

.photo-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.photo-tile { width: 168px; }
.photo-tile img { width: 168px; height: 112px; object-fit: cover; border-radius: 6px; background: var(--line-soft); }
.photo-tile img.is-cover { outline: 2px solid var(--accent); outline-offset: 2px; }
.photo-tile-row { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.cover-label { font-size: 14px; font-weight: 600; color: var(--accent-dark); }
.photo-add { display: flex; flex-direction: column; gap: 8px; justify-content: center; min-height: 112px; }

.line-head { display: flex; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: -8px; }
.amount-col { flex: 0 0 88px; }
.lines { display: flex; flex-direction: column; gap: 8px; }
.line { display: flex; gap: 8px; align-items: flex-start; }
.line .step-no { padding-top: 8px; flex-basis: 20px; font-size: 18px; }
.flag-step, .step-add { margin-left: 28px; }

.editor-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding-top: 20px; border-top: 1px solid var(--line); }
.delete-confirm { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; }

/* ---------- Scan ---------- */

.scan { width: 100%; max-width: 640px; margin: 0 auto; padding: 16px 16px 64px; display: flex; flex-direction: column; gap: 16px; }
.scan h1 { font-family: var(--display); font-weight: 700; font-size: 24px; }
.scan-intro { color: var(--ink-2); }
.scan-pages { display: flex; flex-wrap: wrap; gap: 12px; }
.scan-page { position: relative; width: 132px; }
.scan-page img { width: 132px; height: 176px; object-fit: cover; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--line-soft); }
.scan-page-remove { position: absolute; top: 4px; right: 4px; background: rgba(255, 255, 255, 0.92); color: var(--ink); }
.scan-page-no { display: block; margin-top: 4px; font-size: 13px; color: var(--muted); }
.scan-add { display: flex; flex-direction: column; gap: 8px; justify-content: center; min-height: 176px; }
.scan-foot { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-top: 8px; }

/* ---------- Sign in ---------- */

.signin { min-height: 100vh; min-height: 100dvh; padding: 48px 16px; display: flex; align-items: center; justify-content: center; background: var(--panel); }
.signin-card { width: 100%; max-width: 400px; padding: 40px 32px; display: flex; flex-direction: column; gap: 28px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.signin-head { text-align: center; display: flex; flex-direction: column; gap: 8px; }
.signin-head h1 { font-family: var(--display); font-weight: 700; font-size: 32px; letter-spacing: -0.02em; }
.signin-head p { color: var(--ink-2); }
.signin-buttons { display: flex; flex-direction: column; gap: 12px; }
.btn-sso { min-height: 48px; }
.signin-foot { text-align: center; font-size: 13px; color: var(--muted); }

/* ---------- Blazor error bar ---------- */

#blazor-error-ui {
    display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
    padding: 12px 20px; background: #7f2017; color: #fff;
}
#blazor-error-ui a { color: #fff; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 16px; top: 10px; }
.blazor-error-boundary { padding: 16px; background: #7f2017; color: #fff; }
.blazor-error-boundary::after { content: "Something went wrong."; }

/* ---------- Mobile first: one column, chips for course and cuisine ---------- */

@media (max-width: 899px) {
    .mobile-only { display: inline-flex !important; }

    .browser { display: flex; flex-direction: column; padding-bottom: 84px; }
    .browser.has-detail { padding-bottom: 0; }
    .browser.has-detail > .col, .browser.has-detail > .mobile-bar { display: none; }
    .browser:not(.has-detail) > .detail { display: none; }

    .col { padding: 4px 0 0; border-right: 0; background: var(--bg); }
    .col-head { padding: 0 4px 0 16px; }
    .col-add { margin: 0 16px 8px; }
    .col-recipes .col-actions { display: none; }
    .col-notice { margin: 0 16px 8px; }
    .recipe-bar { flex-wrap: wrap; }

    .col-list { display: flex; gap: 8px; padding: 0 16px 8px; overflow-x: auto; scrollbar-width: none; }
    .col-list::-webkit-scrollbar { display: none; }
    .row { flex: 0 0 auto; padding: 0 16px; border: 1px solid var(--line-strong); border-radius: 22px; white-space: nowrap; }
    .row.on { background: var(--accent); border-color: var(--accent); color: #fff; }
    .row.on .count { color: #fff; }

    .search { margin: 0 16px 8px; }
    .recipe-list { border-top: 1px solid var(--line-soft); }
    .recipe-row { padding: 10px 16px; border-radius: 0; border-bottom: 1px solid var(--line-soft); }
    .recipe-row-name { font-weight: 600; }
    .thumb { flex-basis: 72px; width: 72px; height: 56px; border-radius: 6px; }
    .empty { padding: 20px 16px; }

    .mobile-bar {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
        display: flex; gap: 8px;
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
        background: var(--bg); border-top: 1px solid var(--line);
    }
    .mobile-bar .btn { flex: 1 1 0; min-height: 52px; border-radius: 8px; }

    .topbar { padding: 6px 8px 6px 16px; }
    .detail { padding: 8px 16px 48px; }
    .recipe { gap: 16px; }
    .recipe-cover { width: calc(100% + 32px); max-width: none; margin: 0 -16px; border-radius: 0; aspect-ratio: 3 / 2; }
    .thumbs { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 4px; }
    .thumb-btn { flex: 0 0 76px; width: 76px; height: 56px; }
    .thumbs .btn-dashed { flex: 0 0 auto; min-height: 56px; }
    .recipe-head h1 { font-size: 34px; }
    .recipe-body { gap: 24px; padding-top: 20px; }
    .recipe-ingredients, .recipe-method { flex-basis: 100%; }
    .recipe-ingredients li { padding: 10px 0; }

    .editor { gap: 24px; }
    .editor-head h1 { font-size: 24px; }
    .editor-actions .btn-primary { display: none; }
    .field { height: 48px; }
    .editor-columns { gap: 24px; }
    .editor-foot { flex-direction: column-reverse; align-items: stretch; }
    .photo-tile, .photo-tile img { width: calc(50vw - 22px); }
    .photo-add { flex: 1 1 100%; min-height: 0; flex-direction: row; }
    .photo-add .btn { flex: 1 1 0; min-height: 56px; }
    .scan-add { flex: 1 1 100%; min-height: 0; flex-direction: row; }
    .scan-add .btn { flex: 1 1 0; min-height: 56px; }
    .scan-foot { align-items: stretch; }
}
