:root {
    --bg: #0e1117;
    --surface: #171c25;
    --surface-2: #202735;
    --surface-3: #283243;
    --text: #f3f7f5;
    --muted: #97a5a0;
    --line: #2e3848;
    --primary: #43d39e;
    --primary-strong: #23b985;
    --primary-soft: rgba(67, 211, 158, .14);
    --danger: #ff7474;
    --warning: #f3bd5b;
    --success: #64d98b;
    --shadow: 0 20px 60px rgba(0,0,0,.24);
    --radius: 18px;
}

:root[data-theme="light"] {
    --bg: #eef3f0;
    --surface: #ffffff;
    --surface-2: #f5f8f6;
    --surface-3: #e8efeb;
    --text: #17221e;
    --muted: #62716b;
    --line: #d8e1dc;
    --primary: #15956d;
    --primary-strong: #0f7d5b;
    --primary-soft: rgba(21,149,109,.12);
    --danger: #c93d48;
    --warning: #a86a00;
    --success: #178747;
    --shadow: 0 20px 60px rgba(23,48,38,.10);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); color: var(--text); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font: 15px/1.5 Inter, Segoe UI, system-ui, -apple-system, sans-serif; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; background: var(--surface); border-right: 1px solid var(--line); padding: 22px 16px; display: flex; flex-direction: column; z-index: 30; }
.brand { display: flex; align-items: center; gap: 12px; padding: 6px 10px 24px; }
.brand-mark { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; background: linear-gradient(145deg, var(--primary), var(--primary-strong)); color: white; font-weight: 900; box-shadow: 0 10px 30px var(--primary-soft); }
.brand-mark.large { width: 58px; height: 58px; border-radius: 18px; font-size: 24px; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 20px; letter-spacing: -.4px; }
.brand small { color: var(--muted); font-size: 12px; }
.sidebar nav { display: grid; gap: 6px; }
.nav-link { padding: 12px 14px; border-radius: 12px; color: var(--muted); font-weight: 650; transition: .18s ease; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }
.sidebar-foot { margin-top: auto; display: grid; gap: 12px; }
.user-chip { padding: 14px; border-radius: 14px; background: var(--surface-2); }
.user-chip strong, .user-chip small { display: block; }
.user-chip small { color: var(--muted); }

.main { margin-left: 260px; min-height: 100vh; }
.main-auth { margin-left: 0; display: grid; place-items: center; }
.topbar { min-height: 104px; padding: 24px 34px; display: flex; align-items: center; gap: 16px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 90%, transparent); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(16px); }
.topbar h1 { margin: 0; font-size: clamp(24px,3vw,34px); letter-spacing: -.8px; }
.topbar p { margin: 2px 0 0; color: var(--muted); }
.topbar .icon-button:last-child { margin-left: auto; }
.page-content { padding: 30px 34px 60px; max-width: 1680px; margin: 0 auto; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; margin-bottom: 24px; }
.card h2, .card h3 { margin-top: 0; }
.narrow-card { max-width: 620px; margin-inline: auto; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.section-heading h2 { margin: 0; font-size: 21px; }
.section-heading p { margin: 3px 0 0; color: var(--muted); }
.page-toolbar { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-toolbar > div { display: flex; gap: 10px; }

.stats-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 18px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.stat-card span, .stat-card small { color: var(--muted); display: block; }
.stat-card strong { display: block; margin: 8px 0 2px; font-size: 34px; letter-spacing: -1px; }
.stat-card.warning { border-color: color-mix(in srgb, var(--warning) 50%, var(--line)); }
.dashboard-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 24px; }

.button { border: 1px solid transparent; border-radius: 11px; min-height: 42px; padding: 9px 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; font-weight: 750; transition: .18s ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.button-primary { background: var(--primary); color: #07130f; }
.button-primary:hover { background: var(--primary-strong); color: white; }
.button-secondary { background: var(--surface-2); border-color: var(--line); color: var(--text); }
.button-ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.button-small { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.button-block { width: 100%; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); cursor: pointer; }
.icon-button.danger { color: var(--danger); }
.mobile-menu { display: none; }

.alert { border-radius: 13px; padding: 13px 15px; margin-bottom: 18px; border: 1px solid var(--line); }
.alert-success { background: color-mix(in srgb, var(--success) 13%, var(--surface)); border-color: color-mix(in srgb, var(--success) 40%, var(--line)); }
.alert-error { background: color-mix(in srgb, var(--danger) 11%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 42%, var(--line)); }

.form-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 16px; }
.form-grid.single { grid-template-columns: 1fr; }
.form-grid label { color: var(--muted); font-size: 13px; font-weight: 700; }
.form-grid input, .form-grid select, .form-grid textarea, .filter-bar input, .filter-bar select, .calculator-bar input, .calculator-bar select, .inline-adjust input { width: 100%; margin-top: 7px; border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; background: var(--surface-2); color: var(--text); outline: none; }
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus, .filter-bar input:focus, .filter-bar select:focus, .calculator-bar input:focus, .calculator-bar select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { resize: vertical; }
.span-2 { grid-column: span 2; }
.span-full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; align-items: center; }
.check-label { display: flex !important; align-items: center; gap: 10px; min-height: 42px; }
.check-label input { width: auto; margin: 0; }
.muted { color: var(--muted); font-weight: 400; }
.compact-top { margin-top: 20px; }
.page-form { padding-bottom: 72px; }
.sticky-actions { position: fixed; right: 30px; bottom: 26px; z-index: 18; display: flex; gap: 10px; padding: 10px; background: color-mix(in srgb,var(--surface) 88%,transparent); border: 1px solid var(--line); border-radius: 15px; backdrop-filter: blur(14px); box-shadow: var(--shadow); }

.filter-bar, .calculator-bar { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.filter-bar input { max-width: 340px; margin: 0; }
.filter-bar select { max-width: 220px; margin: 0; }
.calculator-bar label { min-width: 230px; color: var(--muted); font-size: 13px; font-weight: 700; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 840px; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .55px; }
td strong, td small { display: block; }
td small { color: var(--muted); margin-top: 2px; }
tfoot th { color: var(--text); font-size: 14px; }
.row-muted { opacity: .55; }
.row-danger { background: color-mix(in srgb,var(--danger) 7%,transparent); }
.stock-low { color: var(--danger) !important; }
.stock-positive { color: var(--success); }
.inline-adjust { display: grid; grid-template-columns: 90px 150px auto; gap: 6px; align-items: center; }
.inline-adjust input { margin: 0; padding: 8px; }

.badge { display: inline-flex; align-items: center; width: fit-content; border: 1px solid var(--line); border-radius: 999px; padding: 4px 9px; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 750; }
.badge-approved, .badge-ready_to_test { color: var(--success); border-color: color-mix(in srgb,var(--success) 40%,var(--line)); background: color-mix(in srgb,var(--success) 9%,var(--surface)); }
.badge-steeping, .badge-testing { color: var(--warning); border-color: color-mix(in srgb,var(--warning) 40%,var(--line)); background: color-mix(in srgb,var(--warning) 9%,var(--surface)); }
.badge-discarded, .badge-low_stock { color: var(--danger); border-color: color-mix(in srgb,var(--danger) 40%,var(--line)); background: color-mix(in srgb,var(--danger) 9%,var(--surface)); }

.list-stack { display: grid; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 18px; padding: 14px 4px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row:hover strong { color: var(--primary); }
.list-row strong, .list-row small { display: block; }
.list-row small { color: var(--muted); margin-top: 2px; }
.align-right { text-align: right; }
.align-right > * { margin-left: auto; }
.empty-state { padding: 34px 20px; border: 1px dashed var(--line); border-radius: 14px; color: var(--muted); text-align: center; }

.recipe-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 18px; }
.recipe-card { border: 1px solid var(--line); border-radius: 16px; padding: 20px; background: var(--surface-2); display: flex; flex-direction: column; }
.recipe-card-top { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.recipe-card h3 { font-size: 22px; margin: 16px 0 6px; }
.recipe-card p { color: var(--muted); margin: 0 0 18px; min-height: 46px; }
.recipe-metrics { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-top: auto; }
.recipe-metrics span { background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 10px; }
.recipe-metrics strong, .recipe-metrics small { display: block; }
.recipe-metrics small { color: var(--muted); font-size: 11px; }
.recipe-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin: 14px 0; }
.card-actions { display: flex; gap: 8px; }

.ingredient-editor { display: grid; gap: 10px; }
.ingredient-row { display: grid; grid-template-columns: 28px minmax(240px,2fr) minmax(130px,.7fr) minmax(210px,1.2fr) 42px; gap: 10px; align-items: end; padding: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 13px; }
.ingredient-row label { color: var(--muted); font-size: 12px; font-weight: 700; }
.ingredient-row input, .ingredient-row select { width: 100%; margin-top: 5px; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; background: var(--surface); color: var(--text); }
.drag-handle { color: var(--muted); align-self: center; }

.hero-card { display: flex; align-items: center; justify-content: space-between; gap: 28px; }
.hero-card h2 { font-size: clamp(28px,4vw,46px); margin: 12px 0 4px; letter-spacing: -1.2px; }
.hero-card p { color: var(--muted); margin: 0; }
.hero-metrics { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.hero-metrics span { min-width: 118px; padding: 13px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-2); }
.hero-metrics strong, .hero-metrics small { display: block; }
.hero-metrics strong { font-size: 18px; }
.hero-metrics small { color: var(--muted); }
.mix-summary { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 10px; margin-bottom: 20px; }
.mix-summary span { padding: 13px; border-radius: 13px; background: var(--primary-soft); border: 1px solid color-mix(in srgb,var(--primary) 25%,var(--line)); }
.mix-summary strong, .mix-summary small { display: block; }
.mix-summary strong { font-size: 19px; }
.mix-summary small { color: var(--muted); }
.preline { white-space: pre-line; }

.timeline { display: grid; gap: 12px; }
.timeline-item { position: relative; border-left: 3px solid var(--line); padding: 8px 0 8px 18px; }
.timeline-item.done { border-left-color: var(--primary); }
.timeline-item strong, .timeline-item span, .timeline-item small { display: block; }
.timeline-item span { color: var(--muted); }
.timeline-item small { color: var(--muted); font-size: 12px; }
.tasting-grid { display: grid; gap: 14px; }
.tasting-card { border: 1px solid var(--line); background: var(--surface-2); border-radius: 15px; padding: 18px; }
.tasting-head { display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.tasting-head strong, .tasting-head small { display: block; }
.tasting-head small { color: var(--muted); }
.rating-pill { background: var(--primary-soft); color: var(--primary); border-radius: 999px; padding: 7px 11px; font-weight: 800; }
.score-strip { display: grid; grid-template-columns: repeat(6,1fr); gap: 7px; margin: 14px 0; }
.score-strip span { text-align: center; padding: 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.score-strip small, .score-strip strong { display: block; }
.score-strip small { color: var(--muted); font-size: 10px; }
.score-strip strong { font-size: 18px; }
.tasting-card p { margin-bottom: 0; color: var(--muted); }

.collapsible-card .collapse-body { display: none; padding-top: 20px; }
.collapsible-card.open .collapse-body { display: block; }
.section-toggle { width: 100%; border: 0; background: none; color: var(--text); display: flex; align-items: center; justify-content: space-between; text-align: left; cursor: pointer; padding: 0; }
.section-toggle strong, .section-toggle small { display: block; }
.section-toggle small { color: var(--muted); }

.auth-wrap { min-height: 100vh; width: 100%; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 30% 20%,var(--primary-soft),transparent 35%),var(--bg); }
.auth-card { width: min(460px,100%); padding: 34px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 14px; }
.auth-brand h1 { margin: 0; font-size: 34px; }
.auth-copy { color: var(--muted); margin: 16px 0 24px; }

@media (max-width: 1200px) {
    .stats-grid { grid-template-columns: repeat(2,1fr); }
    .recipe-grid { grid-template-columns: repeat(2,1fr); }
    .form-grid { grid-template-columns: repeat(2,1fr); }
    .mix-summary { grid-template-columns: repeat(3,1fr); }
    .ingredient-row { grid-template-columns: 24px 1.7fr .7fr 1fr 42px; }
}

@media (max-width: 900px) {
    .sidebar { transform: translateX(-102%); transition: .22s ease; box-shadow: var(--shadow); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .mobile-menu { display: inline-grid; place-items: center; }
    .topbar { padding: 18px 20px; min-height: 88px; }
    .topbar p { display: none; }
    .page-content { padding: 22px 18px 50px; }
    .dashboard-grid { grid-template-columns: 1fr; gap: 0; }
    .hero-card { align-items: flex-start; flex-direction: column; }
    .hero-metrics { justify-content: flex-start; }
}

@media (max-width: 680px) {
    .stats-grid, .recipe-grid, .form-grid, .mix-summary { grid-template-columns: 1fr; }
    .span-2, .span-full { grid-column: auto; }
    .section-heading, .page-toolbar { align-items: stretch; flex-direction: column; }
    .page-toolbar > div, .card-actions, .form-actions { flex-wrap: wrap; }
    .button { width: 100%; }
    .filter-bar, .calculator-bar { display: grid; grid-template-columns: 1fr; }
    .filter-bar input, .filter-bar select, .calculator-bar label { max-width: none; width: 100%; }
    .ingredient-row { grid-template-columns: 1fr 42px; }
    .ingredient-row .drag-handle { display: none; }
    .ingredient-row label { grid-column: 1 / -1; }
    .ingredient-row .icon-button { grid-column: 2; grid-row: 1; }
    .score-strip { grid-template-columns: repeat(3,1fr); }
    .inline-adjust { min-width: 340px; }
    .sticky-actions { left: 12px; right: 12px; bottom: 12px; }
    .auth-card { padding: 25px; }
}
