:root {
    --green-dark: #2f5e28;
    --green: #4a7c3c;
    --green-light: #7cae63;
    --grey-dark: #3f3f3f;
    --bg: #f4f6f2;
    --card-bg: #ffffff;
    --danger: #b23b3b;
    --ok: #2f8f4e;
    --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    font-family: 'Segoe UI', Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--grey-dark);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    overflow-x: hidden;
    width: 100%;
}

body { min-height: 100vh; }

header.top {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 6px 18px;
    padding-top: calc(6px + env(safe-area-inset-top, 0px));
    background: var(--card-bg);
    border-bottom: 3px solid var(--green);
    position: sticky;
    top: 0;
    z-index: 105;
}

header.top img.logo { height: 60px; width: auto; flex-shrink: 0; }

.hamburger-btn {
    flex-shrink: 0;
    background: none;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    color: var(--green-dark);
    padding: 4px 6px;
}
.nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 109;
}
.nav-backdrop.open { display: block; }
.nav-menu {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 220px;
    background: #fff;
    z-index: 110;
    box-shadow: 2px 0 16px rgba(0,0,0,0.2);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    padding-top: calc(20px + env(safe-area-inset-top, 0px));
    display: flex;
    flex-direction: column;
}
.nav-menu.open { transform: translateX(0); }
.nav-menu-close {
    align-self: flex-end;
    background: none;
    border: none;
    font-size: 1.3rem;
    color: var(--grey-dark);
    cursor: pointer;
    padding: 6px 18px 10px;
}
.nav-menu a {
    padding: 16px 22px;
    text-decoration: none;
    color: var(--grey-dark);
    font-weight: 700;
    font-size: 1.05rem;
    border-bottom: 1px solid #eee;
}
.nav-menu a:active { background: var(--bg); }
header.top .titles { flex: 1; min-width: 0; }
header.top h1 { font-size: 1.05rem; margin: 0; color: var(--green-dark); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.top .sub { font-size: 0.8rem; color: #777; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

header.top a.exit {
    font-size: 0.8rem;
    color: #888;
    text-decoration: none;
    border: 1px solid #ddd;
    padding: 6px 10px;
    border-radius: 8px;
    flex-shrink: 0;
    white-space: nowrap;
}

main { padding: 16px; max-width: 1100px; margin: 0 auto; }

.station-grid, .btn-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
    margin-top: 10px;
}

.station-pick {
    background: var(--card-bg);
    border: 2px solid #e2e6df;
    border-radius: var(--radius);
    padding: 22px 12px;
    text-align: center;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--grey-dark);
    text-decoration: none;
    display: block;
}
.station-pick:active { background: #eef3ea; }

/* Grosse Bestell-Buttons am POS */
.order-btn {
    position: relative;
    border: none;
    border-radius: var(--radius);
    padding: 0;
    min-height: 130px;
    color: #fff;
    font-size: 1.15rem;
    font-weight: 700;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-shadow: 0 3px 0 rgba(0,0,0,0.15);
    cursor: pointer;
    transition: transform 0.08s ease;
    touch-action: manipulation;
}
.order-btn:active { transform: scale(0.96); box-shadow: 0 1px 0 rgba(0,0,0,0.15); }
.order-btn .queue-badge {
    background: rgba(0,0,0,0.28);
    border-radius: 20px;
    padding: 3px 12px;
    font-size: 0.95rem;
    font-weight: 700;
    min-width: 34px;
}
.order-btn.flash {
    animation: flashfeedback 0.5s ease;
}
@keyframes flashfeedback {
    0% { box-shadow: 0 0 0 0 rgba(255,255,255,0.9), 0 3px 0 rgba(0,0,0,0.15); }
    100% { box-shadow: 0 0 0 18px rgba(255,255,255,0), 0 3px 0 rgba(0,0,0,0.15); }
}
.order-btn.flash-correct {
    animation: flashcorrect 0.5s ease;
}
@keyframes flashcorrect {
    0% { box-shadow: 0 0 0 0 rgba(178,59,59,0.9), 0 3px 0 rgba(0,0,0,0.15); filter: brightness(0.85); }
    100% { box-shadow: 0 0 0 18px rgba(178,59,59,0), 0 3px 0 rgba(0,0,0,0.15); filter: brightness(1); }
}

/* Größenstufen: bis 6 Produkte gross, bis 12 mittel, darüber kompakt (mit Scroll) */
.btn-grid.tier-lg { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.btn-grid.tier-md { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.btn-grid.tier-md .order-btn { min-height: 92px; font-size: 0.95rem; }
.btn-grid.tier-md .order-btn .queue-badge { font-size: 0.85rem; padding: 2px 9px; }
.btn-grid.tier-sm { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.btn-grid.tier-sm .order-btn { min-height: 72px; font-size: 0.8rem; }
.btn-grid.tier-sm .order-btn .queue-badge { font-size: 0.75rem; padding: 2px 7px; }

/* Ausgabe: schlanke, einspaltige Listenzeilen statt breiter Kacheln - dadurch von
   Natur aus überlaufsicher (kein Grid mit festen Pixel-Spalten, das bei schmalen
   Screens rechnerisch eng werden kann). .output-card ist der äussere Rahmen,
   .row-main die eigentliche Zeile, .details das Inline-Akkordeon darunter. */
#cards { display: flex; flex-direction: column; gap: 8px; }
.output-card {
    background: var(--card-bg);
    border-radius: 12px;
    border: 2px solid #e2e6df;
    overflow: hidden;
}
.output-card.has-open { border-color: var(--green); }
.row-main {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
}
.row-name {
    flex: 1 1 auto;
    min-width: 0;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 700;
    color: var(--grey-dark);
    text-decoration: underline;
    text-decoration-color: #d8ddd3;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
    overflow-wrap: break-word;
    padding: 4px 0;
}
.row-count {
    flex: 0 0 auto;
    min-width: 28px;
    text-align: center;
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--grey-dark);
}
.output-card.has-open .row-count { color: var(--green-dark); }
.row-btn {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 8px;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.row-btn-undo { background: #eee; color: #555; }
.row-btn-undo:disabled { opacity: 0.4; }
.row-btn-fulfill { background: var(--green); color: #fff; }
.row-btn-fulfill:disabled { background: #ccc; color: #888; }

/* Inline-Detailansicht: klappt innerhalb derselben Zeile auf/zu */
.details {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.28s ease;
    padding: 0 10px;
}
.details.open {
    max-height: 280px;
    overflow-y: auto;
    padding: 0 10px 10px;
    border-top: 1px solid #eee;
    padding-top: 8px;
}
.details table.admin-table { font-size: 0.85rem; }
.details tr.row-alert td { color: var(--danger); font-weight: 700; }

/* Überfällig-Alarm: Zeile (und ihre Detailansicht) blinken deutlich rot */
.output-card.alert {
    border-color: var(--danger);
    animation: alertBlink 1s ease-in-out infinite;
}
.output-card.alert .row-count { color: var(--danger); }
.output-card.alert .row-name { text-decoration-color: var(--danger); }
@keyframes alertBlink {
    0%, 100% { background: #ffffff; box-shadow: 0 0 0 rgba(178,59,59,0); }
    50% { background: #ffd9d9; box-shadow: 0 0 18px rgba(178,59,59,0.55); }
}

.new-order-pulse { animation: pulseCard 1s ease 2; }
@keyframes pulseCard {
    0% { background: #ffffff; }
    40% { background: #dff2d8; }
    100% { background: #ffffff; }
}

form.simple { max-width: 420px; }
form.simple label { display: block; margin: 12px 0 4px; font-weight: 600; font-size: 0.9rem; }
form.simple input, form.simple select {
    width: 100%; padding: 10px; border-radius: 8px; border: 1px solid #ccc; font-size: 1rem;
}
.btn-primary {
    background: var(--green); color: #fff; padding: 12px 20px;
    border: none; border-radius: 10px; font-size: 1rem; font-weight: 700; cursor: pointer;
}
form.simple .btn-primary {
    margin-top: 18px;
}
.error { background: #fbe4e4; color: var(--danger); padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.ok-msg { background: #e2f3e0; color: var(--ok); padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }

table.admin-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; }
table.admin-table th, table.admin-table td { padding: 10px 12px; border-bottom: 1px solid #eee; text-align: left; font-size: 0.92rem; }
table.admin-table th { background: #eef3ea; }
table.matrix td, table.matrix th { text-align: center; }
table.matrix input[type=checkbox] { width: 20px; height: 20px; }

nav.admin-nav { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
nav.admin-nav a {
    text-decoration: none; color: var(--grey-dark); background: #fff; border: 1px solid #ddd;
    padding: 8px 14px; border-radius: 8px; font-size: 0.9rem;
}
nav.admin-nav a.active { background: var(--green); color: #fff; border-color: var(--green); }

.pill { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 0.78rem; font-weight: 700; }
.pill.active { background: #e2f3e0; color: var(--ok); }
.pill.inactive { background: #f0f0f0; color: #888; }

/* Start-Overlay an der Ausgabe: erst antippen, dann ist Ton freigegeben */
.start-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    padding-top: calc(24px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}
.start-overlay h2 { margin: 0 0 8px; color: var(--green-dark); }
.start-overlay p { max-width: 360px; color: #666; }

.conn-error {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 95;
    background: var(--danger);
    color: #fff;
    text-align: center;
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    font-weight: 700;
    font-size: 0.9rem;
}

/* Nachricht Kasse -> Ausgabe */
.msg-bar {
    display: flex;
    gap: 8px;
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    background: #fff;
    border-top: 2px solid var(--green);
    position: sticky;
    bottom: 0;
}
.msg-bar input {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #ccc;
    font-size: 1rem;
}
.msg-bar button {
    flex: 0 0 auto;
    background: var(--green);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    font-weight: 700;
    cursor: pointer;
}
.msg-confirm {
    position: fixed;
    bottom: 72px;
    left: 10px;
    right: 10px;
    background: var(--ok);
    color: #fff;
    padding: 12px;
    border-radius: 10px;
    font-weight: 700;
    text-align: center;
    animation: msgBlink 1s ease-in-out infinite;
    z-index: 90;
}
@keyframes msgBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}

/* Nachrichten-Laufband an der Ausgabe/Kasse: bleibt fest am unteren Bildschirmrand.
   Heller Hintergrund, grüne Schrift, dünner leuchtend grüner Rahmen; jede Nachricht
   bekommt eine eigene, gestapelte Zeile statt aneinandergehängt zu werden. */
.msg-bar-ticker {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 85;
    max-height: 128px;
    padding: 5px 0;
    padding-bottom: calc(5px + env(safe-area-inset-bottom, 0px));
    border: 2px solid var(--green);
    box-shadow: 0 0 8px rgba(74, 124, 60, 0.5);
    background: var(--bg);
    color: var(--green-dark);
    align-items: stretch;
}
.msg-bar-ticker .msg-rows {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 10px;
    min-width: 0;
}
.msg-row {
    overflow: hidden;
    position: relative;
    height: 20px;
    flex-shrink: 0;
}
.msg-row .msg-text {
    white-space: nowrap;
    display: inline-block;
    padding-left: 100%;
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--green-dark);
    animation: marquee 14s linear infinite;
}
@keyframes marquee {
    from { transform: translateX(0); }
    to { transform: translateX(-100%); }
}
.msg-bar-ticker #msgAckBtn {
    flex: 0 0 auto;
    width: 46px;
    background: var(--green);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1.2rem;
    cursor: pointer;
    margin: 2px 8px 2px 2px;
}

/* Mobile: Kopfzeile und Ausgabe-Kacheln an schmale Bildschirme anpassen */
@media (max-width: 480px) {
    header.top {
        padding: 5px 10px;
        gap: 8px;
        padding-top: calc(5px + env(safe-area-inset-top, 0px));
    }
    header.top .logo { height: 46px; }
    .hamburger-btn { font-size: 1.4rem; padding: 4px; }
    header.top h1 { font-size: 0.95rem; }
    header.top .sub { font-size: 0.7rem; }
    header.top a.exit { font-size: 0.72rem; padding: 5px 8px; }
    main { padding: 10px; }

    .row-main { padding: 7px 8px; gap: 6px; }
    .row-name { font-size: 0.92rem; }
    .row-count { font-size: 1.25rem; min-width: 24px; }
    .row-btn { width: 34px; height: 34px; font-size: 0.95rem; }

    .btn-grid { gap: 8px; }
    /* Tier-abhängige Größe, damit auf dem Handy auch bei mehr Produkten alles ohne
       Scrollen passt - vorher wurde hier pauschal überschrieben (Bug). */
    .btn-grid.tier-lg { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
    .btn-grid.tier-lg .order-btn { min-height: 100px; font-size: 1rem; }
    .btn-grid.tier-md { grid-template-columns: repeat(auto-fill, minmax(98px, 1fr)); gap: 6px; }
    .btn-grid.tier-md .order-btn { min-height: 76px; font-size: 0.82rem; }
    .btn-grid.tier-md .order-btn .queue-badge { font-size: 0.72rem; padding: 2px 7px; }
    .btn-grid.tier-sm { grid-template-columns: repeat(auto-fill, minmax(82px, 1fr)); gap: 6px; }
    .btn-grid.tier-sm .order-btn { min-height: 62px; font-size: 0.7rem; }
    .btn-grid.tier-sm .order-btn .queue-badge { font-size: 0.62rem; padding: 1px 6px; }

    .start-overlay h2 { font-size: 1.15rem; }
    .start-overlay p { font-size: 0.9rem; }
}
