:root {
    --bg: #f6f7f9;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --line: #d9dee7;
    --primary: #1f4f82;
    --primary-dark: #163a61;
    --danger: #a92727;
    --soft: #eef3f8;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: clamp(1.4rem, 4vw, 2rem); }
h2 { font-size: clamp(1.15rem, 3vw, 1.45rem); }
h3 { font-size: 1rem; }
p { margin: .35rem 0 0; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem clamp(1rem, 4vw, 2rem);
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
}

.container {
    width: min(1180px, 100%);
    margin: 0 auto;
    padding: 1rem;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: clamp(1rem, 3vw, 1.4rem);
    margin-bottom: 1rem;
}

.section-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}
.section-head.compact { align-items: center; margin-top: 1rem; }

.muted { color: var(--muted); }
.hidden { display: none !important; }

.button {
    appearance: none;
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
    border-radius: 999px;
    padding: .7rem 1rem;
    font-weight: 700;
    cursor: pointer;
    min-height: 44px;
}
.button:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.button.secondary { background: var(--soft); color: var(--primary); }
.button.secondary:hover { background: #dce9f5; }
.button.ghost { background: #fff; color: var(--primary); }
.button.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.button.danger:hover { background: #fff1f1; }
.button:disabled { opacity: .55; cursor: not-allowed; }

.tabs {
    display: flex;
    gap: .5rem;
    overflow-x: auto;
    padding: .25rem 0 .8rem;
}
.tab {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    border-radius: 999px;
    padding: .7rem 1rem;
    min-height: 44px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}
.tab.active { border-color: var(--primary); background: var(--primary); color: #fff; }
.admin-tab { display: none; }
.admin-tab.active { display: block; }

.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin: 1rem 0;
}
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: 1fr 1fr auto; align-items: end; }

label { display: grid; gap: .35rem; font-weight: 700; }
input, select, textarea {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: .65rem .75rem;
    font: inherit;
    background: #fff;
    color: var(--text);
}
textarea { resize: vertical; }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.inline-actions { margin-bottom: 0; align-self: end; }
.sticky-actions {
    position: sticky;
    bottom: 0;
    background: rgba(255,255,255,.95);
    border-top: 1px solid var(--line);
    padding-top: .75rem;
    margin-top: 1rem;
}

.notice {
    border: 1px solid #f3ce73;
    background: #fff7df;
    color: #6b4e00;
    border-radius: 12px;
    padding: .8rem;
}

.list {
    display: grid;
    gap: .75rem;
}
.item-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: .85rem;
    display: grid;
    gap: .55rem;
    background: #fff;
}
.item-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}
.item-actions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
.badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border-radius: 999px;
    padding: .2rem .55rem;
    font-size: .85rem;
    font-weight: 700;
    background: var(--soft);
    color: var(--primary);
}

.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 650px; }
.data-table th, .data-table td { border-bottom: 1px solid var(--line); padding: .55rem; text-align: left; vertical-align: top; }
.data-table th { color: var(--muted); font-size: .9rem; }
.data-table input { min-width: 110px; }
.data-table .small-input { max-width: 120px; }

.week-grid, .week-editor {
    display: grid;
    grid-template-columns: repeat(7, minmax(140px, 1fr));
    gap: .75rem;
    overflow-x: auto;
    padding-bottom: .25rem;
}
.day-card {
    min-width: 140px;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: .8rem;
    background: #fff;
}
.day-card.today { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.day-title { font-weight: 800; margin-bottom: .6rem; }
.slot-box {
    border-top: 1px solid var(--line);
    padding-top: .55rem;
    margin-top: .55rem;
}
.slot-title { color: var(--muted); font-weight: 800; font-size: .85rem; text-transform: uppercase; letter-spacing: .03em; }
.slot-meal { font-weight: 700; margin-top: .2rem; }
.slot-people { color: var(--muted); font-size: .9rem; }

.week-day-editor {
    min-width: 210px;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: .75rem;
    background: #fff;
}
.editor-slot {
    display: grid;
    gap: .5rem;
    padding-top: .7rem;
    margin-top: .7rem;
    border-top: 1px solid var(--line);
}
.editor-slot .row { display: grid; grid-template-columns: 1fr 82px; gap: .5rem; align-items: end; }

.shopping-table { margin-top: 1rem; }
.shopping-meta { margin-top: .75rem; }
.toast {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    max-width: min(420px, calc(100vw - 2rem));
    background: #111827;
    color: #fff;
    border-radius: 14px;
    padding: .85rem 1rem;
    box-shadow: var(--shadow);
    z-index: 30;
}

@media (max-width: 760px) {
    .topbar { align-items: flex-start; }
    .section-head { flex-direction: column; align-items: stretch; }
    .form-grid.two, .form-grid.three { grid-template-columns: 1fr; }
    .inline-actions { align-self: stretch; }
    .inline-actions .button, .form-actions .button { flex: 1 1 auto; }
    .item-row { flex-direction: column; }
    .item-actions { justify-content: flex-start; width: 100%; }
    .week-grid, .week-editor { grid-template-columns: 1fr; overflow-x: visible; }
    .day-card, .week-day-editor { min-width: 0; }
    .editor-slot .row { grid-template-columns: 1fr; }
}

@media print {
    body { background: #fff; }
    .topbar, #authPanel, .tabs, #mealsTab, #menuTab, #logoutBtn, .form-grid, .button, .toast { display: none !important; }
    #adminPanel, #shoppingTab { display: block !important; }
    .card { box-shadow: none; border: none; padding: 0; }
}
