:root {
    --paper: #f4f7f7;
    --ink: #1f2b2c;
    --accent: #1c8287;
    --accent-dark: #145d68;
    --accent-tint: #e6f2f1;
    --accent-secondary: #a9d16f;
    --accent-secondary-dark: #7fae42;
    --line: #dbe4e3;
    --success-bg: #e4f2e4;
    --success-border: #b7dfc0;
    --error-bg: #f8d7da;
    --error-border: #f0b8bd;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    line-height: 1.5;
}

a { color: var(--accent-dark); }

.topbar {
    background: #fff;
    border-bottom: 2px solid var(--line);
}
.topbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}
.brand { font-size: 1.25rem; font-weight: bold; color: var(--accent-dark); }

.main-nav { display: flex; gap: 1rem; flex: 1; }
.main-nav a {
    text-decoration: none;
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    color: var(--ink);
}
.main-nav a.active, .main-nav a:hover { background: var(--accent); color: #fff; }

.user-menu { display: flex; align-items: center; gap: 0.75rem; margin-left: auto; }
.user-name { font-style: italic; }
.logout-link {
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--accent);
    border-radius: 6px;
    text-decoration: none;
}

.page-content { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }

.card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
th, td { text-align: left; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--line); }
th { background: var(--accent-tint); }

.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    text-decoration: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95rem;
}
.btn:hover { background: var(--accent-dark); }
.btn-danger { background: #a33; }
.btn-danger:hover { background: #822; }
.btn-secondary { background: #999; }

input, select, textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.95rem;
}
label { display: block; margin-top: 0.75rem; margin-bottom: 0.25rem; font-weight: bold; }

.flash { padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 1rem; }
.flash-success { background: var(--success-bg); border: 1px solid var(--success-border); }
.flash-error { background: var(--error-bg); border: 1px solid var(--error-border); }

.site-footer {
    text-align: center;
    padding: 1.5rem;
    color: #888;
    font-size: 0.85rem;
}

.filters { display: flex; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: end; }
.filters > div { flex: 1; min-width: 160px; }

.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 4px; font-size: 0.8rem; }
.badge-free { background: #d6ead6; }
.badge-partial { background: #f5e6c8; }
.badge-paid { background: #e0e0e0; }
.badge-gpd { background: #dbe6f5; }

/* Логін */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-box { max-width: 380px; width: 100%; padding: 2rem; }
.login-box h1 { text-align: center; font-size: 1.3rem; color: var(--accent-dark); }
.login-box .btn { width: 100%; margin-top: 1.25rem; }

/* ── Нові компоненти v2 ──────────────────────────────────────────── */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
.page-header h1 { margin: 0; font-size: 1.4rem; }

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 1rem;
}
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid-5 { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 640px) {
    .form-grid, .form-grid-3, .form-grid-5 { grid-template-columns: 1fr; }
}

.hidden { display: none !important; }

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.85rem; }

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    background: #ddd;
    color: #444;
}
.badge-ok   { background: var(--success-bg); color: #2a6b2a; border: 1px solid var(--success-border); }
.badge-warn { background: #fff3cd; color: #856404; border: 1px solid #ffc107; }
.badge-info { background: #cce5ff; color: #004085; border: 1px solid #b8daff; }
.badge-danger { background: var(--error-bg); color: #721c24; border: 1px solid var(--error-border); }

.row-danger td { background: #fff5f5; }
.row-inactive td { opacity: 0.55; }

.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--line); }
.tab-link {
    padding: 0.6rem 1.1rem;
    text-decoration: none;
    color: var(--ink);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}
.tab-link.active {
    border-bottom-color: var(--accent);
    color: var(--accent-dark);
    font-weight: bold;
}
.tab-link:hover { background: var(--accent-tint); }

.role-badge {
    font-size: 0.78rem;
    background: var(--accent-tint);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    color: var(--accent-dark);
}

.actions { white-space: nowrap; }

dl.info-grid {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.4rem 1.5rem;
    margin: 0 0 1rem;
}
dl.info-grid dt { font-weight: bold; color: #888; }

.tech-text {
    background: var(--accent-tint);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 1rem;
    line-height: 1.7;
}

.main-nav a {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.flash-error { background: var(--error-bg); border: 1px solid var(--error-border); }

/* ══════════════════════════════════════════════════════════
   SIDEBAR LAYOUT  (ОСББ-style, school colors)
   ══════════════════════════════════════════════════════════ */

/* Sidebar-aware body */
body.has-sidebar {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar main";
    min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
    grid-area: sidebar;
    width: 240px;
    background: var(--accent-dark);
    color: rgba(255,255,255,0.92);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow: hidden;
    z-index: 200;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1.1rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.12);
    color: #fff;
}
.sidebar-brand-name {
    font-size: 1.05rem;
    font-weight: bold;
    line-height: 1.1;
}
.sidebar-brand-sub {
    font-size: 0.75rem;
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sidebar-section-label {
    font-size: 0.68rem;
    font-weight: bold;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.45);
    padding: 0.6rem 1.1rem 0.3rem;
}

.sidebar-nav {
    flex: 1;
    padding: 0.5rem 0;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.sidebar-nav::-webkit-scrollbar { display: none; }

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 1.1rem;
    text-decoration: none;
    color: rgba(255,255,255,0.82);
    border-radius: 0;
    font-size: 0.92rem;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
}
.sidebar-link:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}
.sidebar-link.active {
    background: rgba(255,255,255,0.15);
    color: #fff;
    border-left-color: var(--paper);        /* кремовий акцент */
    font-weight: 600;
}
.sidebar-link svg { flex-shrink: 0; opacity: 0.85; }
.sidebar-link.active svg { opacity: 1; }

/* User block at bottom of sidebar */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.9rem 1rem;
    border-top: 1px solid rgba(255,255,255,0.12);
    background: rgba(0,0,0,0.15);
}
.sidebar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.95rem;
    flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-name:hover { color: #fff; }
.sidebar-user-role {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.5);
}
.sidebar-logout {
    color: rgba(255,255,255,0.5);
    text-decoration: none;
    padding: 0.3rem;
    border-radius: 4px;
    flex-shrink: 0;
    transition: color 0.15s;
}
.sidebar-logout:hover { color: #fff; }

/* ── Topbar ────────────────────────────────────────── */
.topbar {
    grid-area: topbar;
    background: #fff;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar-inner {
    padding: 0 1.5rem;
    height: 56px;
    display: flex;
    align-items: center;
    gap: 1rem;
    max-width: none;
    margin: 0;
}
.topbar-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--ink);
    margin: 0;
    flex: 1;
}
.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: auto;
}
.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    color: var(--ink);
    text-decoration: none;
    font-style: italic;
}
.topbar-user:hover { color: var(--accent-dark); }

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--ink);
    padding: 0.3rem;
    border-radius: 6px;
}
.sidebar-toggle:hover { background: var(--paper); }

/* ── Main content ──────────────────────────────────── */
body.has-sidebar .page-content {
    grid-area: main;
    max-width: none;
    padding: 1.5rem 2rem;
    overflow-x: auto;
}

/* ── Responsive: collapse sidebar on mobile ─────────── */
@media (max-width: 768px) {
    body.has-sidebar {
        grid-template-columns: 1fr;
        grid-template-areas:
            "topbar"
            "main";
    }
    .sidebar {
        position: fixed;
        width: 240px;
        max-width: 85vw;
        left: -240px;
        top: 0;
        height: 100vh;
        transition: left 0.25s ease;
    }
    .sidebar.open {
        left: 0;
        box-shadow: 4px 0 20px rgba(0,0,0,0.3);
    }
    .sidebar-toggle { display: flex; }
    body.has-sidebar .page-content { padding: 1rem; }
}

/* ── v3: Nutrition, HACCP, diet, seasonal menu ─────── */
.form-grid-3 { grid-template-columns: repeat(3, 1fr); }
.form-grid-5 { grid-template-columns: repeat(5, 1fr); }

dl.info-grid { display: grid; grid-template-columns: 10rem 1fr; gap: 0.35rem 1rem; margin: 0; }
dl.info-grid dt { font-weight: 600; color: var(--text-muted, #666); }
dl.info-grid dd { margin: 0; }

.row-danger { background: #fff5f5; }

details summary { color: var(--accent); cursor: pointer; font-size: 0.88rem; }
details summary:hover { text-decoration: underline; }
details[open] summary { margin-bottom: 0.5rem; }

.hidden { display: none !important; }

/* Badge colours for norm status */
.badge-ok     { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.badge-danger { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }

/* ── Панель (dashboard) ──────────────────────────────── */
.dash-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}
.dash-card-wide { grid-column: 1 / -1; }
.dash-card-label { font-size: 0.8rem; color: #777; text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 0.5rem; }
.dash-stat { font-size: 1.9rem; font-weight: 700; color: var(--ink); line-height: 1.1; }
.dash-sub { font-size: 0.85rem; color: #777; margin-top: 0.25rem; }
.dash-sub .badge { margin-left: 0.35rem; }
.dash-card-link { display: inline-block; margin-top: 0.75rem; font-size: 0.85rem; }
.dash-haccp-row { margin: 0.3rem 0; }
.dash-mini-list { list-style: none; margin: 0.6rem 0 0; padding: 0; font-size: 0.82rem; }
.dash-mini-list li { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.2rem 0; border-bottom: 1px dashed var(--line); color: #555; }
.dash-mini-date { color: #999; white-space: nowrap; }
.dash-chart { width: 100%; height: 140px; display: block; }
.dash-bar { fill: var(--accent); }
.dash-bar:hover { fill: var(--accent-dark); }
.dash-axis { stroke: var(--line); stroke-width: 1; }
@media (max-width: 900px) {
    .dash-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .dash-grid { grid-template-columns: 1fr; }
}
