:root {
    --ink: #181613;
    --ink-2: #28241f;
    --paper: #f2eee7;
    --card: #fffefa;
    --muted: #706a62;
    --line: #ded7cd;
    --red: #d93624;
    --red-bright: #ef5945;
    --red-dark: #aa291b;
    --gold: #efb64c;
    --green: #16805f;
    --radius: 1rem;
    color-scheme: light;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 1rem;
    line-height: 1.5;
}

button, input, textarea, select { font: inherit; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

.admin-page { min-height: 100vh; }

.admin-sidebar {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    display: flex;
    width: 17rem;
    flex-direction: column;
    padding: 1.5rem 1rem;
    background: var(--ink);
    color: white;
}

.admin-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.25rem 0.5rem;
    text-decoration: none;
}

.admin-brand > span {
    display: grid;
    width: 2.55rem;
    height: 2.55rem;
    place-items: center;
    border: 2px solid var(--red-bright);
    border-radius: 50%;
    color: var(--red-bright);
    font-family: Georgia, "Times New Roman", serif;
    font-weight: 900;
    letter-spacing: -0.08em;
}

.admin-brand strong { font-family: Georgia, "Times New Roman", serif; font-size: 1.15rem; }

.admin-sidebar nav {
    display: grid;
    gap: 0.2rem;
    margin-top: 2.5rem;
}

.admin-sidebar nav a {
    padding: 0.72rem 0.85rem;
    border-radius: 0.65rem;
    color: rgba(255, 255, 255, 0.62);
    font-size: 0.9rem;
    font-weight: 700;
    text-decoration: none;
}

.admin-sidebar nav a:hover,
.admin-sidebar nav a[aria-current="page"] {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.admin-sidebar nav a[aria-current="page"] { box-shadow: inset 3px 0 var(--red); }

.sidebar-footer {
    display: grid;
    gap: 0.7rem;
    margin-top: auto;
    padding: 1rem 0.5rem 0;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-footer a,
.sidebar-footer button {
    border: 0;
    background: transparent;
    color: rgba(255, 255, 255, 0.62);
    font-size: 0.82rem;
    font-weight: 700;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.admin-main { min-height: 100vh; margin-left: 17rem; }

.admin-topbar {
    display: flex;
    min-height: 4.8rem;
    align-items: center;
    justify-content: flex-end;
    padding: 0 2rem;
    border-bottom: 1px solid var(--line);
    background: rgba(242, 238, 231, 0.9);
    backdrop-filter: blur(12px);
}

.admin-topbar > div { display: grid; text-align: right; }
.admin-topbar span { color: var(--muted); font-size: 0.7rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.admin-topbar strong { font-size: 0.9rem; }

.sidebar-toggle { display: none; border: 0; background: transparent; font-size: 1.5rem; }

.admin-content {
    width: min(100% - 3rem, 86rem);
    margin: 0 auto;
    padding-block: 3rem 5rem;
}

.admin-heading { max-width: 50rem; margin-bottom: 2.2rem; }
.admin-eyebrow { margin: 0 0 0.7rem; color: var(--red-dark); font-size: 0.75rem; font-weight: 900; letter-spacing: 0.14em; text-transform: uppercase; }
.admin-heading h1,
.auth-card h1 { margin: 0 0 0.7rem; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2.5rem, 5vw, 4.7rem); font-weight: 500; letter-spacing: -0.045em; line-height: 1; }
.admin-heading > p:last-child,
.auth-card > p { color: var(--muted); }

.flash { margin-bottom: 1.5rem; padding: 0.9rem 1rem; border: 1px solid transparent; border-radius: 0.75rem; font-weight: 700; }
.flash-success { border-color: #a9dccb; background: #e7f6f0; color: #105e47; }
.flash-error { border-color: #e8afa6; background: #fff0ed; color: #9b281c; }

.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.8rem; margin-bottom: 1.2rem; }
.metric-grid article { min-height: 10.5rem; padding: 1.25rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.metric-grid span,
.metric-grid small { display: block; color: var(--muted); }
.metric-grid span { font-size: 0.75rem; font-weight: 850; letter-spacing: 0.08em; text-transform: uppercase; }
.metric-grid strong { display: block; margin: 1.4rem 0 0.25rem; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.5rem, 3vw, 2.45rem); line-height: 1; }
.metric-grid small { font-size: 0.75rem; }
.metric-grid .metric-status { background: var(--ink); color: white; }
.metric-status.metric-open { background: #145a47; }
.metric-status.metric-soon { background: #775515; }
.metric-status span,
.metric-status small { color: rgba(255, 255, 255, 0.62); }

.analytics-overview-grid { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(15rem, .8fr); gap: 1.2rem; margin-bottom: 1.2rem; }
.analytics-chart-panel { min-width: 0; }
.analytics-chart-heading { display: flex; align-items: start; justify-content: space-between; gap: 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
.analytics-chart-heading > div:first-child > span,
.analytics-section-title > span { color: var(--muted); font-size: 0.75rem; font-weight: 850; letter-spacing: 0.08em; text-transform: uppercase; }
.analytics-chart-heading h2 { margin: .2rem 0 0; font-family: Georgia, "Times New Roman", serif; font-size: 1.8rem; }
.analytics-kpis { display: flex; gap: 1.2rem; text-align: right; }
.analytics-kpis div { display: grid; }
.analytics-kpis strong { font-size: 1.05rem; }
.analytics-kpis small { color: var(--muted); font-size: .7rem; }
.analytics-chart-scroll { margin-top: 1rem; overflow-x: auto; overscroll-behavior-inline: contain; }
.analytics-chart { display: block; width: 100%; min-width: 43rem; height: auto; }
.analytics-grid-line { stroke: #e9e3da; stroke-width: 1; stroke-dasharray: 4 5; }
.analytics-axis-line { stroke: #cfc6ba; stroke-width: 1; }
.analytics-axis-value,
.analytics-date-label { fill: var(--muted); font-family: Inter, ui-sans-serif, system-ui, sans-serif; font-size: 10px; }
.analytics-bar { transition: opacity 150ms ease; }
.analytics-bar:hover { opacity: .72; }
.analytics-bar-views { fill: var(--red); }
.analytics-bar-actions { fill: var(--gold); }
.analytics-bar-mcp-requests { fill: var(--green); }
.analytics-bar-mcp-tools { fill: var(--gold); }
.analytics-legend { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: .35rem; color: var(--muted); font-size: .75rem; font-weight: 750; }
.analytics-legend span { display: inline-flex; align-items: center; gap: .4rem; }
.analytics-legend i { width: .7rem; height: .7rem; border-radius: .2rem; }
.analytics-legend .legend-views { background: var(--red); }
.analytics-legend .legend-actions { background: var(--gold); }
.analytics-legend .legend-mcp-requests { background: var(--green); }
.analytics-legend .legend-mcp-tools { background: var(--gold); }
.analytics-empty { margin: .8rem 0 0; color: var(--muted); font-size: .8rem; }
.metric-grid-overview { grid-template-columns: 1fr; gap: 1.2rem; margin: 0; }
.metric-grid-overview article { min-height: 0; }
.analytics-breakdown-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.2rem; margin-bottom: 1.2rem; }
.analytics-breakdown { min-width: 0; }
.analytics-section-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .8rem; padding-bottom: .8rem; border-bottom: 1px solid var(--line); }
.analytics-section-title small { color: var(--muted); font-size: .72rem; }
.analytics-list-row { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding: .42rem 0; font-size: .84rem; }
.analytics-list-row span { min-width: 0; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.analytics-list-row strong { font-variant-numeric: tabular-nums; }
.analytics-subtitle { margin: 1rem 0 .3rem; padding-top: .8rem; border-top: 1px solid var(--line); color: var(--ink); font-size: .72rem; font-weight: 850; letter-spacing: .06em; text-transform: uppercase; }
.analytics-events-panel { margin-bottom: 1.2rem; }
.analytics-events-panel .panel-heading > small { color: var(--muted); font-size: .72rem; }
.analytics-panel-actions { display: flex; align-items: center; gap: .8rem; }
.analytics-panel-actions > small { color: var(--muted); font-size: .72rem; }
.analytics-export-form { margin: 0; }
.analytics-export-form .secondary-button { min-height: 2.25rem; padding: .4rem .8rem; font-size: .75rem; }
.analytics-event-list { max-height: 28rem; overflow: auto; }
.analytics-event-row { display: grid; grid-template-columns: 10.5rem 7rem 9rem 10rem minmax(14rem, 1fr); align-items: baseline; gap: .8rem; padding: .72rem 0; border-bottom: 1px solid var(--line); font-size: .77rem; }
.analytics-event-row:last-child { border-bottom: 0; }
.analytics-event-row time,
.analytics-event-row > span,
.analytics-event-row small { color: var(--muted); }
.analytics-event-row time,
.analytics-session { font-variant-numeric: tabular-nums; }
.analytics-event-row small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mcp-endpoint-panel { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; }
.mcp-endpoint-panel > div { display: grid; min-width: 0; gap: .35rem; }
.mcp-endpoint-panel span { color: var(--muted); font-size: .72rem; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.mcp-endpoint-panel code { overflow: hidden; color: var(--ink); font-size: .9rem; text-overflow: ellipsis; white-space: nowrap; }
.mcp-state { flex: none; padding: .35rem .65rem; border-radius: 999px; font-size: .72rem; }
.mcp-state.is-enabled { background: #e2f3ed; color: #126147; }
.mcp-state.is-disabled { background: #f7dfdb; color: var(--red-dark); }
.mcp-outcome { font-weight: 800; }
.mcp-outcome.is-success { color: var(--green); }
.mcp-outcome.is-error { color: var(--red-dark); }

.overview-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.2rem; }
.admin-panel { padding: 1.5rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.panel-heading { display: flex; align-items: start; justify-content: space-between; gap: 1rem; padding-bottom: 1.2rem; border-bottom: 1px solid var(--line); }
.panel-heading span { color: var(--muted); font-size: 0.75rem; font-weight: 850; letter-spacing: 0.08em; text-transform: uppercase; }
.panel-heading h2 { margin: 0.25rem 0 0; font-family: Georgia, "Times New Roman", serif; font-size: 1.6rem; }
.panel-heading a { color: var(--red-dark); font-size: 0.82rem; font-weight: 800; text-decoration: none; }
.compact-row { display: grid; grid-template-columns: 8rem 1fr; gap: 1rem; padding: 0.85rem 0; border-bottom: 1px solid var(--line); font-size: 0.88rem; }
.compact-row:last-child { border-bottom: 0; }
.compact-row span { color: var(--muted); }

.form-panel { display: grid; max-width: 48rem; gap: 1.2rem; }
.season-form { max-width: 52rem; }
.date-field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.9rem; }
.form-hint { margin: -0.2rem 0 0; padding: 0.75rem 0.9rem; border-left: 3px solid var(--gold); border-radius: 0.25rem 0.6rem 0.6rem 0.25rem; background: #fff7e5; color: #5f4b25; font-size: 0.82rem; }
.schedule-explainer { padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: 0.75rem; background: #f8f5ef; }
.schedule-explainer > strong { display: block; margin-bottom: 0.65rem; }
.schedule-explainer p { margin: 0.35rem 0; color: var(--muted); font-size: 0.86rem; }
.schedule-explainer b { color: var(--ink); }
label { display: grid; gap: 0.42rem; color: var(--ink); font-size: 0.8rem; font-weight: 850; }
label small { color: var(--muted); font-weight: 500; }
input,
textarea,
select {
    width: 100%;
    padding: 0.75rem 0.85rem;
    border: 1px solid var(--line);
    border-radius: 0.6rem;
    outline: 0;
    background: white;
    color: var(--ink);
    font-size: 0.92rem;
}

textarea { resize: vertical; line-height: 1.55; }
input:focus,
textarea:focus,
select:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(221, 62, 43, 0.1); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 2rem; padding-bottom: 1.1rem; border-bottom: 1px solid var(--line); }
.switch-row span { display: grid; }
.switch-row small { margin-top: 0.2rem; }
.switch-row input { width: 2.8rem; height: 1.55rem; appearance: none; padding: 0.18rem; border: 0; border-radius: 999px; background: #c9c2b8; cursor: pointer; transition: background 160ms ease; }
.switch-row input::before { display: block; width: 1.18rem; height: 1.18rem; border-radius: 50%; background: white; box-shadow: 0 2px 6px rgba(0,0,0,.2); content: ""; transition: transform 160ms ease; }
.switch-row input:checked { background: var(--green); }
.switch-row input:checked::before { transform: translateX(1.25rem); }

.admin-button,
.secondary-button,
.danger-button {
    display: inline-flex;
    min-height: 2.85rem;
    align-items: center;
    justify-content: center;
    padding: 0.65rem 1.15rem;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 0.84rem;
    font-weight: 850;
    cursor: pointer;
}

.admin-button { background: var(--red); color: white; }
.admin-button:hover { background: var(--red-dark); }
.secondary-button { border-color: var(--line); background: white; color: var(--ink); }
.danger-button { margin-top: 1rem; border-color: #e3a197; background: transparent; color: var(--red-dark); }
.danger-link { padding: 0; border: 0; background: transparent; color: var(--red-dark); font-size: 0.8rem; font-weight: 850; cursor: pointer; }

.inline-form { display: flex; align-items: end; gap: 0.8rem; max-width: 40rem; margin-bottom: 1rem; }
.inline-form label { flex: 1; }
.closure-form { max-width: 50rem; }
.list-panel { max-width: 50rem; }
.admin-list-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.9rem 0; border-bottom: 1px solid var(--line); }
.admin-list-row:first-child { padding-top: 0; }
.admin-list-row:last-child { padding-bottom: 0; border-bottom: 0; }
.admin-list-row > div { display: grid; }
.admin-list-row span { color: var(--muted); font-size: 0.78rem; }
.muted { color: var(--muted); }

.menu-editor { display: grid; gap: 0.55rem; }
.menu-edit-row { display: grid; grid-template-columns: 2.2rem minmax(10rem, .8fr) minmax(16rem, 1.6fr) 6rem 6rem 2rem; align-items: end; gap: 0.65rem; padding: 0.9rem; border: 1px solid var(--line); border-radius: 0.8rem; background: var(--card); }
.menu-edit-row .row-number { align-self: center; color: var(--red-dark); font-size: 0.7rem; font-weight: 900; }
.menu-edit-row input { padding: 0.58rem 0.65rem; }
.row-remove { width: 2rem; height: 2rem; margin-bottom: 0.35rem; border: 0; border-radius: 50%; background: #f7dfdb; color: var(--red-dark); font-size: 1.1rem; cursor: pointer; }
.sticky-actions { position: sticky; z-index: 5; bottom: 1rem; display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1rem; padding: 0.8rem; border: 1px solid var(--line); border-radius: 999px; background: rgba(255, 254, 250, .9); box-shadow: 0 12px 35px rgba(25,20,15,.14); backdrop-filter: blur(12px); }

.upload-panel { display: flex; align-items: end; gap: 1rem; margin-top: 1.2rem; }
.upload-panel > div { margin-right: auto; }
.upload-panel strong { display: block; }
.upload-panel p { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.8rem; }
.upload-panel label { flex: 1; }

.log-panel { max-height: 38rem; overflow: auto; padding: 0; }
.log-row { display: grid; grid-template-columns: 11.5rem 10rem 6rem minmax(12rem, 1fr); gap: 1rem; padding: 0.75rem 1rem; border-bottom: 1px solid var(--line); font-size: 0.75rem; }
.log-row time,
.log-row span { color: var(--muted); }
.log-row code { overflow: hidden; font-size: 0.75rem; text-overflow: ellipsis; white-space: nowrap; }

.auth-page { display: grid; min-height: 100vh; place-items: center; padding: 1rem; background: var(--ink); color: white; }
.auth-page::before { position: fixed; inset: 0; background: radial-gradient(circle at 75% 20%, rgba(221,62,43,.28), transparent 35%), radial-gradient(circle at 10% 90%, rgba(239,182,76,.12), transparent 35%); content: ""; }
.auth-shell { position: relative; width: min(100%, 31rem); }
.auth-shell > .admin-brand { margin-bottom: 1.2rem; }
.auth-card { padding: clamp(1.5rem, 5vw, 2.5rem); border: 1px solid rgba(255,255,255,.14); border-radius: 1.2rem; background: var(--card); box-shadow: 0 35px 90px rgba(0,0,0,.36); color: var(--ink); }
.auth-card h1 { font-size: clamp(2.4rem, 9vw, 3.8rem); }
.stack-form { display: grid; gap: 1rem; margin-top: 1.8rem; }
.stack-form .admin-button { width: 100%; margin-top: 0.4rem; }
.auth-help { padding: 0.85rem 1rem; border-left: 3px solid var(--gold); border-radius: 0.25rem 0.6rem 0.6rem 0.25rem; background: #fff7e5; color: #5f4b25 !important; font-size: 0.85rem; }

@media (max-width: 1120px) {
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
    .analytics-overview-grid { grid-template-columns: 1fr; }
    .metric-grid-overview { grid-template-columns: repeat(2, 1fr); }
    .analytics-breakdown-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .analytics-breakdown:last-child { grid-column: 1 / -1; }
    .menu-edit-row { grid-template-columns: 2rem 1fr 6rem 6rem 2rem; }
    .ingredients-field { grid-column: 2 / span 3; grid-row: 2; }
}

@media (max-width: 840px) {
    .admin-sidebar { transform: translateX(-100%); transition: transform 180ms ease; }
    .admin-sidebar.is-open { transform: translateX(0); box-shadow: 20px 0 50px rgba(0,0,0,.28); }
    .admin-main { margin-left: 0; }
    .admin-topbar { justify-content: space-between; padding-inline: 1rem; }
    .sidebar-toggle { display: block; }
    .admin-content { width: min(100% - 1.25rem, 86rem); padding-top: 2rem; }
    .overview-grid { grid-template-columns: 1fr; }
    .analytics-event-row { grid-template-columns: 9.5rem 6.5rem 1fr; }
    .analytics-event-row > span:nth-of-type(2) { grid-column: 3; }
    .analytics-event-row small { grid-column: 1 / -1; }
    .upload-panel { display: grid; }
    .upload-panel > div { margin-right: 0; }
    .log-row { grid-template-columns: 1fr auto; }
    .log-row code { grid-column: 1 / -1; }
}

@media (max-width: 600px) {
    .metric-grid { grid-template-columns: 1fr; }
    .metric-grid-overview { grid-template-columns: 1fr; }
    .analytics-chart-heading { display: grid; }
    .analytics-kpis { justify-content: space-between; text-align: left; }
    .analytics-breakdown-grid { grid-template-columns: 1fr; }
    .analytics-breakdown:last-child { grid-column: auto; }
    .analytics-events-panel .panel-heading,
    .analytics-panel-actions { display: grid; }
    .analytics-event-row { grid-template-columns: 1fr auto; gap: .25rem .7rem; }
    .analytics-event-row > strong,
    .analytics-event-row > span:nth-of-type(2),
    .analytics-event-row small { grid-column: 1 / -1; }
    .mcp-endpoint-panel { align-items: flex-start; }
    .metric-grid article { min-height: 8rem; }
    .metric-grid strong { margin-top: .8rem; }
    .date-field-grid { grid-template-columns: 1fr; }
    .inline-form { display: grid; }
    .menu-edit-row { grid-template-columns: 1.7rem 1fr 2rem; }
    .menu-edit-row label { grid-column: 2; }
    .menu-edit-row .row-number { grid-column: 1; grid-row: 1; }
    .menu-edit-row .row-remove { grid-column: 3; grid-row: 1; }
    .menu-edit-row .ingredients-field { grid-column: 2; grid-row: auto; }
    .sticky-actions { position: static; display: grid; border-radius: .8rem; }
    .switch-row { align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: .01ms !important; }
}
