/* Minimal site styles — replace with Tailwind/Bootstrap/your design system later. */

* { box-sizing: border-box; }

html, body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: #1a1a1a;
    background: #f7f7f8;
}

a { color: #2563eb; }
a.link-muted { color: #555; text-decoration: none; }
a.link-muted:hover { text-decoration: underline; }

.page { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: .75rem 1.5rem;
    background: #1f2937;
    color: white;
}
.topbar .brand { color: white; font-weight: 700; text-decoration: none; font-size: 1.1rem; }
.topbar .nav-links { display: flex; gap: 1rem; flex: 1; }
.topbar .nav-links a { color: #d1d5db; text-decoration: none; padding: .25rem .5rem; border-radius: 4px; }
.topbar .nav-links a:hover, .topbar .nav-links a.active { background: #374151; color: white; }
.topbar-right { display: flex; align-items: center; gap: .75rem; font-size: .9rem; color: #d1d5db; }
.topbar-right .user { color: white; font-weight: 500; }
.topbar-right .badge {
    background: #2563eb;
    padding: .15rem .5rem;
    border-radius: 999px;
    font-size: .8rem;
    color: white;
}
/* Per-restaurant logo lives inside the dashboard header row, just before the
   Refresh button. Same rounded-rectangle shape as the dash-stat cards. */
.dash-stat.dash-logo {
    padding: .35rem .75rem;
    min-width: 0;
    align-items: center;
    justify-content: center;
}
.dash-stat.dash-logo img {
    height: 56px;
    max-width: 200px;
    object-fit: contain;
    display: block;
}

/* Settings page */
.logo-grid {
    display: grid;
    grid-template-columns: minmax(180px, 240px) 1fr;
    gap: 1.5rem;
    align-items: start;
    margin-top: .75rem;
}
.logo-current, .logo-upload {
    display: flex;
    flex-direction: column;
    gap: .5rem;
}
.logo-preview {
    max-width: 200px;
    max-height: 120px;
    object-fit: contain;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    padding: .5rem;
}
.logo-placeholder {
    background: #f3f4f6;
    border: 1px dashed #d1d5db;
    color: #6b7280;
    padding: 1.5rem;
    text-align: center;
    border-radius: 4px;
    font-size: .9rem;
}

.content {
    flex: 1;
    padding: 1.5rem 2rem;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
}

.filter-bar {
    display: flex;
    gap: .75rem;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    padding: 1rem;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
}
.filter-bar label { display: flex; flex-direction: column; font-size: .85rem; color: #555; gap: .25rem; }
.filter-bar label.grow { flex: 1; }
.filter-bar input, .filter-bar select {
    padding: .4rem .5rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: .95rem;
    min-width: 160px;
}

.btn-primary, .btn-secondary, button {
    padding: .45rem .9rem;
    border-radius: 4px;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: .9rem;
}
.btn-primary { background: #2563eb; color: white; }
.btn-primary:hover:not(:disabled) { background: #1d4ed8; }
.btn-secondary { background: white; border-color: #d1d5db; color: #1a1a1a; }
.btn-secondary:hover { background: #f3f4f6; }
button:disabled { opacity: .55; cursor: default; }

.grid {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border: 1px solid #e5e7eb;
}
/* Tables in cards get a horizontal scrollbar on narrow screens rather than
   blowing out the layout. The card itself stays the page width. */
.card > table.grid {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
}
.card > table.grid > thead,
.card > table.grid > tbody {
    display: table;
    width: 100%;
}
.grid th, .grid td { padding: .5rem .75rem; text-align: left; border-bottom: 1px solid #f3f4f6; font-size: .9rem; }
.grid thead th { background: #f9fafb; font-weight: 600; }
.grid td.num, .grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid td.actions button { padding: .15rem .45rem; margin-right: .15rem; font-size: .8rem; }
.grid td.actions button.danger { color: #b91c1c; }

.error {
    background: #fef2f2;
    color: #991b1b;
    padding: .75rem 1rem;
    border: 1px solid #fecaca;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.notice { background: white; padding: 1.5rem; border: 1px solid #e5e7eb; border-radius: 6px; }
.muted { color: #6b7280; font-size: .85rem; }

.restaurant-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; margin-top: 1rem; }
.restaurant-card {
    display: block;
    padding: 1.25rem;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    text-decoration: none;
    color: #1a1a1a;
}
.restaurant-card:hover { border-color: #2563eb; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.restaurant-name { font-weight: 600; font-size: 1.05rem; }
.restaurant-id { color: #6b7280; font-size: .85rem; margin-top: .25rem; }

/* Modal */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 50;
}
.modal {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    width: min(90vw, 420px);
    box-shadow: 0 10px 30px rgba(0,0,0,.15);
}
.modal h2 { margin: 0 0 1rem 0; font-size: 1.15rem; }
.modal label { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .9rem; font-size: .85rem; color: #555; }
.modal input, .modal select { padding: .45rem; border: 1px solid #d1d5db; border-radius: 4px; font-size: .95rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .5rem; }

/* Dashboard ---------- */
.dash-header {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.dash-stat {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: .65rem 1rem;
    display: flex;
    flex-direction: column;
    min-width: 220px;
}
.dash-stat .label { font-size: .75rem; color: #6b7280; text-transform: uppercase; letter-spacing: .04em; }
.dash-stat .value { font-size: 1.05rem; font-weight: 600; color: #1f2937; }
.dash-header-spacer { flex: 1; }
.refresh-btn { align-self: center; white-space: nowrap; }
.success {
    background: #f0fdf4;
    color: #166534;
    padding: .65rem 1rem;
    border: 1px solid #bbf7d0;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.tabs {
    display: flex;
    gap: .25rem;
    margin: 1rem 0;
    border-bottom: 1px solid #d1d5db;
}
.tabs .tab {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px 6px 0 0;
    padding: .55rem 1rem;
    color: #4b5563;
    font-weight: 500;
    cursor: pointer;
}
.tabs .tab:hover { background: #f3f4f6; }
.tabs .tab.active {
    background: white;
    border-color: #d1d5db;
    border-bottom-color: white;
    color: #111827;
    margin-bottom: -1px;
}

.card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}
.card h2 { margin: 0 0 .75rem 0; font-size: 1.05rem; }

.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
    gap: 1rem;
}
.chart-grid .chart-wide { grid-column: 1 / -1; }
.chart-wrap { width: 100%; }

.pct-up { color: #15803d; }
.pct-down { color: #b91c1c; }

.week-ending {
    margin: .25rem 0 .75rem 0;
    font-size: 1.05rem;
    font-weight: 600;
    color: #2563eb;
}

.chart-title {
    margin: 0 0 .5rem 0;
    font-size: .95rem;
    font-weight: 600;
    color: #4b5563;
    text-align: center;
}

.chart-wide-block {
    /* Sits below the chart-grid as its own full-width block. */
}
.chart-toolbar {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    margin-bottom: .5rem;
}
.chart-toolbar label {
    display: flex;
    flex-direction: column;
    font-size: .8rem;
    color: #555;
    gap: .2rem;
}
.chart-toolbar select {
    padding: .35rem .5rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: .9rem;
    min-width: 160px;
}

.checkbox-toolbar {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-bottom: .5rem;
}
.checkbox-toolbar strong { color: #374151; }
.btn-small {
    padding: .2rem .55rem;
    font-size: .8rem;
}
.checkbox-row {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem .65rem;
}
.check-chip {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .25rem .6rem;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 999px;
    font-size: .85rem;
    cursor: pointer;
    user-select: none;
}
.check-chip:has(input:checked) {
    background: #dbeafe;
    border-color: #93c5fd;
    color: #1e40af;
}
.check-chip input { margin: 0; }

/* Items / Tree mapper page ---------- */
.items-layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 1rem;
    align-items: start;
}
.items-tree-panel {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: .75rem;
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 4rem);
    display: flex;
    flex-direction: column;
    gap: .5rem;
}
.items-tree-panel .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #f3f4f6;
    padding-bottom: .35rem;
}
.tree-search {
    width: 100%;
    padding: .35rem .5rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: .85rem;
    margin-bottom: .25rem;
}
.tree-toolbar { display: flex; flex-wrap: wrap; gap: .25rem; }
.tree-toolbar .danger { color: #b91c1c; }
.tree-scroll {
    overflow-y: auto;
    flex: 1;
    font-size: .9rem;
}
.tree-node {
    display: flex;
    align-items: center;
    gap: .25rem;
    padding: .15rem 0;
    cursor: default;
    border-radius: 3px;
}
.tree-node.selected {
    background: #dbeafe;
}
.tree-node:hover { background: #f3f4f6; }
.tree-node.dragging {
    opacity: 0.5;
    background: #fef9c3;
}
.tree-node.drop-target {
    outline: 2px dashed #2563eb;
    outline-offset: -2px;
    background: #eff6ff;
}
.tree-toggle {
    width: 16px;
    text-align: center;
    color: #6b7280;
    cursor: pointer;
    user-select: none;
}
.tree-label { cursor: pointer; user-select: none; flex: 1; }
.tree-level1 { font-weight: 600; color: #1f2937; }
.tree-level2 { color: #374151; }
.tree-level3 { color: #4b5563; }
.tree-count { color: #9ca3af; font-size: .8rem; margin-left: .25rem; }

.items-right-panel {
    display: flex;
    flex-direction: column;
    gap: .75rem;
}
.items-right-panel .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: .5rem;
}
.items-list { max-height: 360px; overflow-y: auto; }
.items-list .grid { font-size: .85rem; }
.items-list .row-selected { background: #eff6ff; }
.filter-bar.compact { margin-bottom: .5rem; padding: .5rem; }
.map-actions {
    display: flex;
    justify-content: center;
    gap: .5rem;
}
.map-actions button { padding: .5rem 1rem; font-size: .9rem; }

/* ----- Mobile / narrow viewport overrides ----- */
@media (max-width: 720px) {
    .content {
        padding: 1rem .75rem;
    }
    .topbar {
        flex-wrap: wrap;
        gap: .5rem;
        padding: .5rem .75rem;
    }
    .topbar .nav-links {
        flex: 1 0 100%;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    .topbar .nav-links a {
        flex-shrink: 0;
    }
    .topbar-right {
        flex-wrap: wrap;
        font-size: .8rem;
    }

    /* Dashboard header — full-width cards stacked */
    .dash-header { flex-direction: column; gap: .5rem; }
    .dash-stat { min-width: 0; width: 100%; }
    .dash-header-spacer { display: none; }
    .dash-stat.dash-logo img { height: 48px; }
    .refresh-btn { width: 100%; }

    /* Filter bar — wrap nicely */
    .filter-bar { flex-direction: column; gap: .5rem; }
    .filter-bar label, .filter-bar input, .filter-bar select { width: 100%; min-width: 0; }
    .filter-bar.compact { padding: .5rem; }

    /* Charts — slightly shorter to fit on small screens */
    .chart-grid { grid-template-columns: 1fr; }
    .chart-wrap { height: 240px !important; }
    .chart-wide-block .chart-wrap { height: 280px !important; }

    /* Items page — stack tree on top, right panel below */
    .items-layout { grid-template-columns: 1fr; }
    .items-tree-panel { position: static; max-height: 60vh; }

    /* Logo grid in Settings stacks */
    .logo-grid { grid-template-columns: 1fr; }

    /* Tabs from the old single-page Dashboard (no longer used but harmless) */
    .tabs { overflow-x: auto; white-space: nowrap; }

    /* Headings tighter */
    h1 { font-size: 1.3rem; }
    h2 { font-size: 1.05rem; }
}

#blazor-error-ui {
    background: #fee;
    border-top: 1px solid #fcc;
    color: #900;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0,0,0,0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
