/* ===========================
   Grundlayout / Farben
   =========================== */

:root {
    --bg-main: #050505;
    --bg-panel: #151515;
    --bg-panel-soft: #1b1b1b;
    --bg-card: #111111;
    --border-soft: #303030;
    --text-main: #f5f5f5;
    --text-muted: #a0a0a0;
    
    --accent: #b91c1c;
    --accent-soft: #7f1d1d;
    --accent-hover: #991b1b;    
    --good: #10b981;
    --warn: #f59e0b;
    --bad:  #ef4444;
    
    --radius-lg: 18px;
    --radius-md: 14px;
    --radius-sm: 10px;
    --shadow-soft: 0 14px 40px rgba(0,0,0,0.65);
    
    --header-height: 64px;
    --payment-bar-height: 80px;
    --order-mobile-height: 34vh;
    --transition-fast: 0.18s ease-out;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
    overflow: hidden;
}

.app-root {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(circle at 50% 110%, rgba(185, 28, 28, 0.15) 0, transparent 55%),
        radial-gradient(circle at 10% -40%, rgba(185, 28, 28, 0.08) 0, transparent 55%),
        var(--bg-main);
}

/* ===========================
   Header + Banner
   =========================== */

.app-header {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    gap: 12px;
    background: rgba(5, 5, 5, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 20;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.header-left {
    display: flex;
    align-items: center;
}

.header-right.icon-row {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: flex-end;
}

.icon-button {
    position: relative;
    width: 36px;
    height: 36px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.2);
    background: transparent;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
}

.icon-button:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.icon-svg {
    width: 18px;
    height: 18px;
    stroke: #ffffff;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

.airtable-banner {
    flex: 1;
    margin: 0 16px;
    max-width: 420px;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: bold;
    color: #fff;
    display: none;
    align-items: center;
    justify-content: center;
}

/* ===========================
   Kategorien
   =========================== */

.category-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.category-bar::-webkit-scrollbar { display: none; }

.category-tab {
    border: 1px solid var(--border-soft);
    background: var(--bg-panel-soft);
    color: var(--text-main);
    border-radius: 999px;
    padding: 8px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: all var(--transition-fast);
}

.category-tab.active {
    background: var(--accent);
    border-color: var(--accent-hover);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 6px 15px rgba(185, 28, 28, 0.4);
}

/* ===========================
   Main Layout
   =========================== */

.app-main {
    flex: 1;
    display: flex;
    gap: 16px;
    padding: 8px 16px 0;
    min-height: 0;
}

.product-panel, .order-panel {
    background: rgba(15, 15, 15, 0.8);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    border: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    padding: 12px;
    min-height: 0;
}

.product-panel { flex: 2; }
.order-panel { flex: 1; }

.product-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
    padding-bottom: 20px;
}

/* ===========================
   Produkt-Kacheln
   =========================== */

.product-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    grid-auto-rows: 120px;
    gap: 12px;
}

.product-button {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 12px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border: 1px solid var(--border-soft);
    cursor: pointer;
    position: relative;
    user-select: none;
    transition: all var(--transition-fast);
}

.product-button:active { transform: scale(0.96); }

.product-button > div:first-child {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
}

.product-price {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 500;
}

.product-qty-badge, .product-minus {
    position: absolute;
    bottom: -6px;
    min-width: 28px;
    height: 28px;
    border-radius: 999px;
    color: #fff;
    border: 2px solid var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    z-index: 2;
}

.product-qty-badge {
    right: -6px;
    background: var(--accent);
    font-size: 14px;
}

.product-minus {
    left: -6px;
    background: var(--bad);
    font-size: 18px;
}

/* ===========================
   Ausverkaufte Artikel (Out of Stock)
   =========================== */
.product-button.out-of-stock {
    opacity: 0.3;
    filter: grayscale(100%);
    border-color: rgba(255, 255, 255, 0.1) !important;
    pointer-events: none; /* DAS BLOCKIERT DIE KLICKS! */
}

/* Im Bearbeitungsmodus (Edit-Mode) müssen Klicks auf leere Artikel erlaubt sein */
body.edit-mode .product-button.out-of-stock {
    pointer-events: auto;
    opacity: 0.6;
    cursor: pointer;
}

.out-of-stock-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-15deg);
    background: rgba(239, 68, 68, 0.95);
    color: white;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 900;
    letter-spacing: 2px;
    text-transform: uppercase;
    z-index: 10;
    pointer-events: none; /* Stempel selbst ist nicht klickbar */
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
}

/* ===========================
   Deckelbereich
   =========================== */

.new-deckel-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.new-deckel-input {
    flex: 1;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-soft);
    padding: 12px 14px;
    background: #050505;
    color: var(--text-main);
    font-size: 15px;
    font-weight: 600;
    outline: none;
}
.new-deckel-input:focus { border-color: var(--accent); }

.btn-accent {
    border-radius: var(--radius-md);
    border: none;
    background: var(--accent);
    color: #ffffff;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6);
    transition: all var(--transition-fast);
}

.btn-accent:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-ghost {
    border-radius: var(--radius-md);
    border: 1px solid var(--border-soft);
    background: transparent;
    color: var(--text-main);
    padding: 10px 16px;
    font-size: 14px;
    cursor: pointer;
}

.order-list {
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
}

.order-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 8px;
    background: var(--bg-panel);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.order-item.active {
    background-color: rgba(185, 28, 28, 0.15) !important;
    border-left: 4px solid var(--accent) !important;
    color: #fff !important;
}

/* ===========================
   Payment-Bar
   =========================== */

.payment-bar {
    flex: 0 0 var(--payment-bar-height);
    padding: 10px 24px 24px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(5, 5, 5, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.payment-buttons {
    display: flex;
    gap: 12px;
}

.pay-btn {
    border-radius: var(--radius-md);
    border: none;
    background: var(--bg-panel-soft);
    color: #ffffff;
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    border: 1px solid var(--border-soft);
    transition: all var(--transition-fast);
}

.pay-btn:active { transform: scale(0.95); }

.total-display {
    text-align: right;
    font-size: 15px;
    font-weight: 800;
}
.total-subtext {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
}

/* ===========================
   Modals
   =========================== */

.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 50;
}
.modal.open { display: flex; }

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.modal-dialog {
    position: relative;
    background: #111;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 24px;
    min-width: min(480px, 100% - 32px);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
}

.modal-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.modal-body {
    font-size: 14px;
    color: var(--text-main);
    overflow-y: auto;
}

.modal-footer-row {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

.modal-close {
    border: none;
    background: transparent;
    color: #ffffff;
    font-size: 20px;
    cursor: pointer;
}

/* Modal Inputs & Split */
.field-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.field-label {
    font-size: 12px;
    color: var(--text-muted);
}
.text-field, .select-field {
    border-radius: 8px;
    border: 1px solid var(--border-soft);
    background: #050505;
    color: var(--text-main);
    padding: 10px 12px;
    font-size: 14px;
}

.split-product-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-radius: 10px;
    background: #1a1a1a;
    margin-bottom: 6px;
    font-size: 14px;
}

/* ===========================
   Login Screen
   =========================== */

.login-background {
    background: radial-gradient(circle at 50% 120%, #1e3a8a 0, #050505 55%);
}

.login-shell {
    min-height: 100vh;
    padding: 24px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    width: min(420px, 100%);
    background: rgba(0, 0, 0, 0.9);
    border-radius: 24px;
    border: 1px solid #222;
    padding: 30px 24px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.7);
    text-align: center;
}

/* ===========================
   Responsive – Mobile
   =========================== */

@media (max-width: 900px) {
    .app-main {
        flex-direction: column;
        padding: 6px 10px 0;
    }
    .order-panel {
        flex: 0 0 var(--order-mobile-height);
        max-height: var(--order-mobile-height);
    }
    .payment-bar {
        flex-direction: column;
        align-items: stretch;
        height: auto;
        padding: 12px;
        padding-bottom: env(safe-area-inset-bottom, 20px);
    }
    .total-display {
        text-align: center;
        font-size: 20px;
        margin-bottom: 8px;
    }
    .payment-buttons {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    .pay-btn {
        width: 100%;
        justify-content: center;
        padding: 14px 10px;
    }
    .product-list {
        grid-template-columns: repeat(2, 1fr);
        grid-auto-rows: 100px;
        gap: 8px;
    }
}

/* --- EDIT MODE MAGIC --- */
body.edit-mode .product-button {
    animation: wiggle 0.3s infinite alternate;
    border: 2px dashed var(--warn) !important;
    cursor: grab;
}
body.edit-mode .product-qty-badge, 
body.edit-mode .product-minus {
    display: none !important; 
}
body.edit-mode .product-button.add-new {
    background: rgba(16, 185, 129, 0.1);
    border: 2px dashed var(--good) !important;
    color: var(--good);
    animation: none;
    align-items: center;
    justify-content: center;
}
.drag-over {
    opacity: 0.3;
    transform: scale(0.9);
}
@keyframes wiggle {
    0% { transform: rotate(-1.5deg); }
    100% { transform: rotate(1.5deg); }
}

/* ========================================= */
/* PERFEKTES DRUCK-LAYOUT (Quittungen/iPad)  */
/* ========================================= */
@media print {
    /* Verstecke die normale Kasse und die dunklen Menüs */
    .app-root, .modal-backdrop, .modal-header-row, .modal-footer-row, .icon-row {
        display: none !important;
    }
    
    /* Hintergrund komplett weiß machen */
    body, html { 
        background: white !important; 
        margin: 0 !important; 
        padding: 0 !important; 
    }
    
    /* Das Modal von seinen Bildschirm-Einschränkungen befreien */
    .modal {
        position: static !important;
        display: block !important;
        background: white !important;
    }
    .modal-dialog {
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        box-shadow: none !important;
        background: white !important;
        border: none !important;
    }
    
    /* Nur den reinen Beleg-Inhalt anzeigen */
    .modal-body {
        display: block !important;
        background: white !important;
        color: black !important;
        width: 100% !important;
        padding: 0 !important;
        overflow: visible !important;
    }

    /* Alle weißen Texte für das Papier schwarz färben */
    .modal-body * {
        color: black !important;
        border-color: #ccc !important;
    }
}