/* ============================================================
   Marktgebühren – Stylesheet
   CI: #003861 (Primär)  #a43315 (Akzent)
   Mobile-first, Hell/Dunkel umschaltbar (auto/light/dark)
   ============================================================ */

:root {
    --ci-primary: #003861;
    --ci-primary-2: #0a4d80;
    --ci-accent:  #a43315;
    --ci-accent-2:#c9421f;

    --bg:         #f5f6f8;
    --surface:    #ffffff;
    --surface-2:  #f0f2f5;
    --text:       #1a1d22;
    --text-muted: #5b6470;
    --border:     #d8dde3;
    --border-strong: #b8c0c9;
    --shadow:     0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.06);

    --ok-bg:  #e6f4ea;
    --ok-fg:  #1e6b34;
    --err-bg: #fdecea;
    --err-fg: #7a1c14;
    --warn:   var(--ci-accent);

    --radius: 10px;
    --radius-sm: 6px;
    --gap: 1rem;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
            "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:         #0e1116;
        --surface:    #161b22;
        --surface-2:  #1c2330;
        --text:       #e6e8ec;
        --text-muted: #9aa3ad;
        --border:     #2a3340;
        --border-strong: #3a4555;
        --shadow:     0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.5);
        --ok-bg:  #143824;
        --ok-fg:  #93dba9;
        --err-bg: #3a1a14;
        --err-fg: #f3a89e;
    }
}

/* Manueller Override per data-theme */
:root[data-theme="light"] {
    --bg:#f5f6f8; --surface:#fff; --surface-2:#f0f2f5;
    --text:#1a1d22; --text-muted:#5b6470;
    --border:#d8dde3; --border-strong:#b8c0c9;
    --shadow:0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.06);
    --ok-bg:#e6f4ea; --ok-fg:#1e6b34;
    --err-bg:#fdecea; --err-fg:#7a1c14;
}
:root[data-theme="dark"] {
    --bg:#0e1116; --surface:#161b22; --surface-2:#1c2330;
    --text:#e6e8ec; --text-muted:#9aa3ad;
    --border:#2a3340; --border-strong:#3a4555;
    --shadow:0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.5);
    --ok-bg:#143824; --ok-fg:#93dba9;
    --err-bg:#3a1a14; --err-fg:#f3a89e;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
}

/* Topbar */
.topbar {
    background: var(--ci-primary);
    color: #fff;
    box-shadow: var(--shadow);
    position: sticky; top: 0; z-index: 50;
}
.topbar-inner {
    max-width: 1200px; margin: 0 auto;
    display: flex; align-items: center; gap: .75rem;
    padding: .6rem 1rem;
    flex-wrap: wrap;
}
.brand {
    color: #fff; font-weight: 700; text-decoration: none;
    font-size: 1.05rem; letter-spacing: .3px;
    flex: 0 0 auto;
}
.nav-toggle {
    display: none;
    background: transparent; border: 1px solid rgba(255,255,255,.35);
    color: #fff; border-radius: var(--radius-sm);
    padding: .35rem .5rem;
    cursor: pointer;
}
.nav {
    display: flex; gap: .15rem; flex-wrap: wrap;
    flex: 1 1 auto;
    margin: 0 .5rem;
}
.nav a {
    color: rgba(255,255,255,.85);
    text-decoration: none;
    padding: .4rem .65rem;
    border-radius: var(--radius-sm);
    font-size: .92rem;
    display: inline-flex; align-items: center; gap: .4rem;
    line-height: 1;
}
.nav a:hover  { background: rgba(255,255,255,.12); color: #fff; }
.nav a.active { background: var(--ci-accent); color: #fff; }

.topbar-right {
    display: flex; align-items: center; gap: .4rem; margin-left: auto;
}
.user-chip {
    display: inline-flex; align-items: center; gap: .35rem;
    color: rgba(255,255,255,.92); font-size: .9rem;
    padding: .35rem .6rem;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255,255,255,.25);
    text-decoration: none;
    line-height: 1;
    transition: background .15s, border-color .15s;
    max-width: 220px;
    overflow: hidden;
}
.user-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip:hover { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.5); color: #fff; }
.user-chip.active { background: var(--ci-accent); border-color: var(--ci-accent); color: #fff; }

/* Main */
.container {
    max-width: 1200px; margin: 0 auto;
    padding: 1rem;
}

/* Card */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}
.card.narrow { max-width: 520px; margin-left: auto; margin-right: auto; }
.card-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap;
}
.head-actions {
    display: flex; gap: .5rem; align-items: end; flex-wrap: wrap;
}
.day-print-form {
    display: flex; gap: .5rem; align-items: end; flex-wrap: wrap;
}
.day-print-form label { margin: 0; }
.day-print-form input[type="date"] { width: auto; }

/* Icon basics */
.ic { display: inline-block; vertical-align: middle; flex: 0 0 auto; }
h1 .ic, h2 .ic { width: 22px; height: 22px; vertical-align: -3px; margin-right: .35rem; opacity: .85; }
.btn .ic { width: 18px; height: 18px; }
.btn-sm .ic { width: 16px; height: 16px; }

/* Buttons with icon + text */
.btn { display: inline-flex; align-items: center; gap: .4rem; }
.btn-icon { padding: .55rem .7rem; }
.btn-icon.btn-sm { padding: .4rem .5rem; }
.btn-ghost.btn-icon { padding: .4rem .55rem; }

/* Kompakte Filter-Bar */
.filter-bar {
    display: flex; flex-wrap: wrap;
    gap: .5rem .6rem;
    align-items: end;
    margin-bottom: 1rem;
    padding: .6rem .75rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.filter-bar .field {
    margin: 0;
    display: flex; flex-direction: column; gap: .15rem;
    flex: 1 1 130px;
    min-width: 130px;
    color: var(--text);
}
.filter-bar .field span {
    font-size: .75rem;
    color: var(--text-muted);
    line-height: 1;
    letter-spacing: .2px;
}
.filter-bar input[type="text"],
.filter-bar input[type="date"],
.filter-bar input[type="number"],
.filter-bar select {
    margin-top: 0;
    padding: .45rem .55rem;
    font-size: .92rem;
    width: 100%;
}
.filter-actions {
    display: flex; gap: .35rem;
    align-items: end;
    flex: 0 0 auto;
}
.filter-actions .btn { padding: .5rem .7rem; }
h1, h2 {
    color: var(--ci-primary); margin: 0 0 .75rem 0; line-height: 1.2;
}
:root[data-theme="dark"] h1, :root[data-theme="dark"] h2,
@media (prefers-color-scheme: dark) {
    h1, h2 { color: #6cb0e8; }
}
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; margin-top: 1rem; }

p.muted, .muted { color: var(--text-muted); font-size: .92rem; }

/* Form */
form label {
    display: block; margin: .9rem 0; font-size: .92rem; color: var(--text-muted);
}
form label.checkbox {
    display: flex; align-items: center; gap: .5rem; color: var(--text);
}
input[type="text"], input[type="number"], input[type="email"],
input[type="password"], input[type="date"], input[type="search"],
select, textarea {
    display: block; width: 100%;
    padding: .65rem .8rem;
    font: inherit; color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    margin-top: .25rem;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--ci-primary);
    box-shadow: 0 0 0 3px rgba(0,56,97,.2);
}
input[type="checkbox"] { width: 1.05rem; height: 1.05rem; margin: 0; }

/* Buttons */
.btn {
    display: inline-block;
    padding: .6rem 1rem;
    font: inherit; font-weight: 500;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    text-decoration: none; cursor: pointer;
    transition: background .15s, border-color .15s, transform .05s;
    line-height: 1.2;
}
.btn:hover  { background: var(--border); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--ci-primary); color: #fff; border-color: var(--ci-primary); }
.btn-primary:hover { background: var(--ci-primary-2); border-color: var(--ci-primary-2); }
.btn-warn { background: var(--ci-accent); color: #fff; border-color: var(--ci-accent); }
.btn-warn:hover { background: var(--ci-accent-2); border-color: var(--ci-accent-2); }
.btn-ghost { background: transparent; color: rgba(255,255,255,.95); border: 1px solid rgba(255,255,255,.35); }
.btn-ghost:hover { background: rgba(255,255,255,.12); }
.btn-sm { padding: .35rem .6rem; font-size: .85rem; }
.btn-lg { padding: .9rem 1.2rem; font-size: 1.05rem; width: 100%; }

.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }
form.inline { display: inline; }

/* Flash */
.flash {
    padding: .75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: .95rem;
}
.flash-ok  { background: var(--ok-bg); color: var(--ok-fg); }
.flash-err { background: var(--err-bg); color: var(--err-fg); }

/* Receipt creation: info & totals */
.info-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0,1fr));
    gap: .5rem 1rem;
    background: var(--surface-2);
    padding: .75rem 1rem;
    border-radius: var(--radius-sm);
    margin: .5rem 0 1rem;
    font-size: .92rem;
}
.info-grid .label {
    display: block; color: var(--text-muted); font-size: .8rem;
}
.totals {
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: .75rem 1rem;
    margin: 1rem 0;
}
.totals .row {
    display: flex; justify-content: space-between;
    padding: .25rem 0; font-size: 1rem;
}
.totals .total {
    border-top: 1px solid var(--border-strong);
    margin-top: .25rem; padding-top: .5rem;
    font-size: 1.2rem;
    color: var(--ci-primary);
}
@media (prefers-color-scheme: dark) {
    .totals .total { color: #6cb0e8; }
}
:root[data-theme="dark"] .totals .total { color: #6cb0e8; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data {
    width: 100%; border-collapse: collapse;
    font-size: .92rem;
}
table.data th, table.data td {
    text-align: left;
    padding: .55rem .6rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
table.data th { background: var(--surface-2); font-weight: 600; color: var(--text-muted); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr.cancelled td { text-decoration: line-through; color: var(--text-muted); }
table.data .actions { display: flex; gap: .35rem; flex-wrap: wrap; }

/* Filters */
.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: .75rem;
    margin-bottom: 1rem;
}
.filters label { margin: 0; }
.filter-actions { display: flex; align-items: end; gap: .5rem; flex-wrap: wrap; }

.summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: .75rem;
    background: var(--surface-2);
    padding: .75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
}
.summary .label { display: block; color: var(--text-muted); font-size: .8rem; }
.summary strong { font-size: 1.1rem; }

/* Receipt paper */
.receipt-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.cancel-form { background: var(--surface-2); padding: .75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; }

.receipt-paper {
    background: #fff;
    color: #111;
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.4;
    padding: 1.25rem 1.5rem;
    max-width: 360px;
    margin: 0 auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.receipt-logo-wrap { text-align: center; margin-bottom: .5rem; }
.receipt-logo { max-width: 100%; max-height: 90px; height: auto; }
.logo-preview {
    background: #fff; border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: .75rem;
    text-align: center; margin-top: .25rem;
}
.logo-preview img { max-width: 100%; max-height: 120px; height: auto; }
.favicon-preview { display: inline-block; padding: .5rem; }
.favicon-preview img { max-width: 64px; max-height: 64px; image-rendering: -webkit-optimize-contrast; }
.receipt-head { text-align: center; font-weight: 600; }
.receipt-title { text-align: center; font-size: 1.1rem; margin: .5rem 0; color: #111; }
.receipt-cancelled {
    text-align: center; font-weight: 700; color: var(--ci-accent);
    margin: .5rem 0;
}
.receipt-meta { display: grid; grid-template-columns: max-content 1fr; gap: .25rem .75rem; margin: .5rem 0; }
.receipt-meta dt { color: #555; }
.receipt-meta dd { margin: 0; }
.receipt-totals { width: 100%; border-collapse: collapse; }
.receipt-totals td { padding: .15rem 0; }
.receipt-totals td.num { text-align: right; font-variant-numeric: tabular-nums; }
.receipt-totals tr.total td { font-weight: 700; padding-top: .35rem; border-top: 1px dashed #999; }
.receipt-foot { font-size: .85rem; color: #444; margin-top: .75rem; text-align: center; }
.receipt-paper hr { border: none; border-top: 1px dashed #999; margin: .5rem 0; }

/* Print */
@media print {
    .topbar, .no-print, .receipt-actions, .cancel-form { display: none !important; }
    body { background: #fff; }
    .container { padding: 0; }
    .card { border: none; box-shadow: none; padding: 0; margin: 0; }
    .receipt-paper { border: none; max-width: 80mm; padding: 4mm; }
}

/* Tablet: Topbar mit Hamburger */
@media (max-width: 900px) {
    .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
    .nav {
        order: 99;
        width: 100%;
        flex-direction: column;
        gap: .15rem;
        margin: .35rem 0 0;
        max-height: 0;
        overflow: hidden;
        transition: max-height .2s ease;
    }
    .nav.open { max-height: 60vh; overflow: auto; }
    .nav a { padding: .55rem .7rem; font-size: 1rem; }
    .nav a .ic { width: 20px; height: 20px; }
}

/* Phones */
@media (max-width: 600px) {
    .topbar-inner { padding: .45rem .6rem; gap: .4rem; }
    .brand { font-size: 1rem; }
    .user-chip span { display: none; }
    .user-chip { padding: .35rem .45rem; }
    h1 { font-size: 1.25rem; }
    .container { padding: .6rem; }
    .card { padding: .85rem; }
    .info-grid { grid-template-columns: 1fr 1fr; }
    .totals .total { font-size: 1.15rem; }
    .btn-lg { padding: 1rem 1.2rem; font-size: 1.1rem; }
    .filter-bar .field { flex: 1 1 calc(50% - .3rem); min-width: 0; }
    .filter-bar .filter-actions { flex: 1 1 100%; }
    .filter-bar .filter-actions .btn { flex: 1 1 auto; justify-content: center; }
    .day-print-form { flex: 1 1 100%; }
    .day-print-form .btn { flex: 1 1 auto; justify-content: center; }
}

code {
    font-family: var(--font-mono); background: var(--surface-2);
    padding: .1rem .35rem; border-radius: 4px; font-size: .9em;
}
