/* MadeOrganic design system - Apple HIG structure (large titles, grouped inset lists, tab bar / sidebar,
   light + dark), brand palette from the MadeOrganic / Natulique identity. */

:root {
    /* Brand palette */
    --mo-earth: #493026;
    --mo-beige: #F2E9E0;
    --mo-olea: #A79E7E;
    --mo-dark-beige: #DBC8AF;
    --mo-off-white: #FEF7EC;
    --mo-natural-white: #E8E6DF;

    /* Semantic tokens */
    --bg: var(--mo-off-white);
    --bg-grouped: var(--mo-beige);
    --surface: #FFFFFF;
    --text: var(--mo-earth);
    --text-secondary: #6E5F55;
    --separator: var(--mo-natural-white);
    --accent: var(--mo-earth);
    --accent-soft: var(--mo-dark-beige);
    --positive: #627345;
    --negative: #A8442F;
    --radius: 14px;
    --tap: 44px;

    --font-body: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
    --font-display: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --sidebar-w: 248px;
    --tabbar-h: 56px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1F1713;
        --bg-grouped: #2A1F19;
        --surface: #33261F;
        --text: #F2E9E0;
        --text-secondary: #B5A596;
        --separator: #46362D;
        --accent: var(--mo-dark-beige);
        --accent-soft: #5A4536;
        --positive: #A9BC80;
        --negative: #E08A74;
    }
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 17px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    min-height: 100%;
}

h1, h2, h3 { margin: 0; font-weight: 600; }

a { color: var(--accent); text-decoration: none; }

/* ---------- Large title ---------- */
.large-title {
    font-family: var(--font-display);
    font-size: clamp(2.2rem, 6vw, 3.2rem);
    line-height: 1.05;
    letter-spacing: -0.01em;
    font-weight: 600;
    padding: calc(var(--safe-top) + 28px) 20px 8px;
}
.page-subtitle { color: var(--text-secondary); padding: 0 20px 16px; }

/* ---------- Grouped inset lists ---------- */
.list-group {
    background: var(--surface);
    border-radius: var(--radius);
    margin: 0 16px 24px;
    overflow: hidden;
    border: 1px solid var(--separator);
}
.list-group-header {
    color: var(--text-secondary);
    font-size: 0.8rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0 32px 6px;
}
.list-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--tap);
    padding: 12px 16px;
    color: var(--text);
    border-bottom: 1px solid var(--separator);
}
.list-row:last-child { border-bottom: 0; }
a.list-row:active, button.list-row:active { background: var(--bg-grouped); }
.list-row .row-title { flex: 1; }
.list-row .row-value { color: var(--text-secondary); }
.list-row.has-chevron::after {
    content: "›";
    color: var(--text-secondary);
    font-size: 1.4rem;
    line-height: 1;
}

/* ---------- Buttons: outlined earth, as on the brand site ---------- */
.btn-mo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--tap);
    padding: 0 24px;
    border: 1.5px solid var(--accent);
    background: transparent;
    color: var(--accent);
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
}
.btn-mo:hover { background: var(--accent-soft); }
.btn-mo:disabled { opacity: 0.5; cursor: default; }
.btn-mo.filled { background: var(--accent); color: var(--bg); }

/* ---------- Form fields ---------- */
.field { display: block; padding: 10px 16px; border-bottom: 1px solid var(--separator); }
.field:last-child { border-bottom: 0; }
.field > span { display: block; font-size: 0.78rem; color: var(--text-secondary); }
.field input {
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    padding: 4px 0;
    outline: none;
}

.form-message { color: var(--negative); padding: 0 32px 16px; }

/* ---------- App shell: sidebar on wide screens, tab bar on phones ---------- */
.app-shell { min-height: 100dvh; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary);
    min-height: var(--tap);
    padding: 0 14px;
    border-radius: 10px;
    font-size: 0.95rem;
}
.nav-item svg { width: 22px; height: 22px; flex: none; }
.nav-item.active { color: var(--accent); background: var(--accent-soft); }

.sidebar {
    display: none;
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--bg-grouped);
    border-right: 1px solid var(--separator);
    padding: calc(var(--safe-top) + 24px) 12px 16px;
    flex-direction: column;
    gap: 4px;
}
.sidebar .brand { font-family: var(--font-display); font-size: 1.8rem; padding: 0 14px 20px; color: var(--text); }
.sidebar .spacer { flex: 1; }

.tabbar {
    position: fixed;
    inset: auto 0 0 0;
    height: calc(var(--tabbar-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    display: flex;
    justify-content: space-around;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 1px solid var(--separator);
    z-index: 20;
}
.tabbar .nav-item { flex-direction: column; justify-content: center; gap: 2px; font-size: 0.68rem; padding: 0 6px; background: none; }
.tabbar .nav-item.active { background: none; }

.content { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 24px); }

@media (min-width: 900px) {
    .sidebar { display: flex; }
    .tabbar { display: none; }
    .content { margin-left: var(--sidebar-w); padding-bottom: 48px; max-width: calc(var(--sidebar-w) + 1100px); }
}

/* ---------- Login ---------- */
.login-wrap { max-width: 440px; margin: 0 auto; padding-top: 8vh; }
.login-brand { text-align: center; font-family: var(--font-display); font-size: 2.6rem; margin-bottom: 8px; }

.loading { color: var(--text-secondary); padding: 24px 20px; }

.blazor-error-boundary { background: var(--negative); color: white; padding: 1rem; }

/* ---------- Loading ---------- */
.loading-block { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 56px 24px; color: var(--text-secondary); text-align: center; }
.loading-hint { font-size: 0.85rem; max-width: 36ch; }
.spinner {
    width: 30px; height: 30px;
    border: 3px solid var(--separator);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* ---------- Framework error banner (hidden until Blazor shows it) ---------- */
#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    z-index: 1000;
    padding: 12px 20px calc(12px + var(--safe-bottom));
    background: var(--negative);
    color: #fff;
}
#blazor-error-ui .reload { color: #fff; text-decoration: underline; margin-left: 8px; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 16px; top: 12px; }

/* ---------- Home dashboard ---------- */
.home-stat { font-variant-numeric: lining-nums; font-feature-settings: "lnum" 1; font-family: var(--font-display); font-size: 2rem; font-weight: 600; color: var(--text); line-height: 1; }
.home-stat.alert-text, .list-row .alert-text { color: var(--negative); font-weight: 600; }

/* ---------- Home: consumption chart and top products (plain CSS, themed with the app tokens) ---------- */
.home-card { padding: 16px; }
.home-empty { color: var(--text-secondary); padding: 8px 0; }
.home-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 20px; }
.home-kpi-value { font-family: var(--font-display); font-variant-numeric: lining-nums; font-feature-settings: "lnum" 1; font-size: 1.8rem; font-weight: 600; line-height: 1.1; }
.home-kpi-value.up { color: var(--positive); }
.home-kpi-value.down { color: var(--negative); }
.home-kpi-label { color: var(--text-secondary); font-size: 0.78rem; }

.home-chart { display: flex; align-items: flex-end; gap: 4px; height: 168px; }
.home-bar-col { flex: 1 1 0; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; text-align: center; }
.home-bar-stack { flex: 1 1 auto; display: flex; flex-direction: column; justify-content: flex-end; }
.home-bar { width: 100%; border-radius: 4px 4px 0 0; min-height: 3px; }
.home-bar.sold { background: var(--accent); }
.home-bar.internal { background: var(--mo-olea); border-radius: 4px 4px 0 0; }
.home-bar-stack .home-bar + .home-bar { margin-top: 1px; }
.home-bar-value { font-size: 0.68rem; color: var(--text-secondary); height: 14px; line-height: 14px; font-variant-numeric: lining-nums; }
.home-bar-day { display: flex; flex-direction: column; align-items: center; font-size: 0.66rem; line-height: 1.25; color: var(--text-secondary); padding-top: 4px; border-top: 1px solid var(--separator); }
.home-bar-day.today { color: var(--text); font-weight: 700; }
.home-legend { display: flex; gap: 16px; margin-top: 12px; color: var(--text-secondary); font-size: 0.8rem; }
.home-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.home-legend .dot.sold { background: var(--accent); }
.home-legend .dot.internal { background: var(--mo-olea); }

.home-top-row { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 8px 0; }
.home-top-row + .home-top-row { border-top: 1px solid var(--separator); }
.home-top-name { overflow-wrap: anywhere; }
.home-top-track { height: 8px; background: var(--bg-grouped); border-radius: 4px; overflow: hidden; }
.home-top-fill { height: 100%; background: var(--accent); border-radius: 4px; }
.home-top-count { font-variant-numeric: lining-nums; font-weight: 600; min-width: 2ch; text-align: right; }
@media (max-width: 640px) { .home-top-row { grid-template-columns: minmax(0, 1fr) auto; row-gap: 6px; } .home-top-track { grid-column: 1 / -1; order: 3; } }

/* ---------- Focus: the page title gets focus after navigation (screen readers), but no visible frame ---------- */
h1:focus, h1:focus-visible { outline: none; }

/* ---------- DevExpress popups (confirm dialogs etc.): comfortable padding and spacing ---------- */
.dxbl-modal-header { padding: 16px 12px 16px 20px; }   /* close button has its own inner space: keep it in line with the footer buttons */
.dxbl-modal-body { padding: 16px 20px; }
.dxbl-modal-footer { padding: 12px 20px 24px; gap: 12px; justify-content: center !important; align-items: center; }
.dxbl-modal-footer .btn-mo { min-width: 112px; }

/* ---------- DevExpress popups in the app's own look (warm surface, serif title) instead of the neutral grey default ---------- */
.dxbl-modal-content, .dxbl-modal-header, .dxbl-modal-body, .dxbl-modal-footer { background: var(--surface); color: var(--text); }
.dxbl-modal-content { border: 1px solid var(--separator); border-radius: 14px; overflow: hidden; box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35); }
.dxbl-modal-header { border-bottom: 0; }
.dxbl-modal-title { font-family: var(--font-display); font-size: 1.6rem; font-weight: 600; letter-spacing: -0.005em; }
.dxbl-modal-body { font-size: 1rem; line-height: 1.45; }
.dxbl-modal-footer { border-top: 0; }
.dxbl-modal-header .dxbl-btn-tool { color: var(--text-secondary); }

/* DevExpress gives the popup dialog a fixed 28px side margin; with our width it pushed the dialog past the right edge on phones.
   Centre it with automatic margins and never let it be wider than the screen. */
dxbl-modal-dialog.dxbl-popup { margin-left: auto !important; margin-right: auto !important; max-width: calc(100vw - 24px) !important; }
