:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --border: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --success-hover: #16a34a;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --warning: #f59e0b;
    --radius: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
}

/* --- Nav --- */
nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    position: sticky;
    top: 0;
    z-index: 100;
}
nav a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius);
    transition: all 0.15s;
    white-space: nowrap;
    font-size: 0.85rem;
}
nav a:hover, nav a.active {
    color: var(--text);
    background: var(--surface-hover);
}
nav .brand {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    padding-right: 0.5rem;
    flex-shrink: 0;
}
nav .nav-logout {
    margin-left: auto;
    color: var(--danger) !important;
    flex-shrink: 0;
}

/* --- Layout --- */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.75rem;
}

.split {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 0.75rem;
    height: calc(100vh - 220px);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    color: white;
    touch-action: manipulation;
}
.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); }
.btn-success:hover { background: var(--success-hover); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-warning { background: var(--warning); color: #000; }
.btn-sm { padding: 0.35rem 0.6rem; font-size: 0.8rem; min-height: 32px; }
.btn-lg { padding: 0.8rem 1.5rem; font-size: 1.1rem; }
.btn-block { width: 100%; }

/* --- Product Grid --- */
.product-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.5rem 0;
    overflow-y: auto;
}
.product-grid-inner {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.5rem;
}
.product-category-section {
    margin-bottom: 0.25rem;
}
.product-category-header {
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    padding: 0.2rem 0.5rem;
    margin-bottom: 0.3rem;
    letter-spacing: 0.03em;
}

.product-btn {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 0.4rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.12s;
    color: var(--text);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}
.product-btn:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}
.product-btn:active {
    transform: scale(0.96);
}
.product-btn .name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.2rem;
    word-break: break-word;
}
.product-btn .price {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* --- Category tabs --- */
.category-tabs {
    display: flex;
    gap: 0.35rem;
    overflow-x: auto;
    padding: 0.4rem 0;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
}
.category-tab {
    padding: 0.45rem 0.8rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-muted);
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
    font-size: 0.85rem;
    touch-action: manipulation;
    flex-shrink: 0;
}
.category-tab:hover { border-color: var(--primary); color: var(--text); }
.category-tab.active {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
}

/* --- Order Panel --- */
.order-panel {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}
.order-header {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.order-header h2 {
    font-size: 1rem;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.order-items {
    flex: 1;
    overflow-y: auto;
    padding: 0.4rem;
    -webkit-overflow-scrolling: touch;
}
.order-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.4rem;
    border-radius: var(--radius);
    transition: background 0.15s;
}
.order-item:hover { background: var(--surface-hover); }
.order-item.cancelled {
    opacity: 0.4;
    text-decoration: line-through;
}
.order-item .qty {
    background: var(--primary);
    color: white;
    font-weight: 700;
    min-width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    flex-shrink: 0;
}
.order-item .item-name {
    flex: 1;
    font-weight: 500;
    font-size: 0.9rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.order-item .item-price {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.85rem;
    flex-shrink: 0;
}
.order-item .item-actions {
    display: flex;
    gap: 0.2rem;
    flex-shrink: 0;
}

.order-footer {
    border-top: 1px solid var(--border);
    padding: 0.75rem;
}
.order-total {
    display: flex;
    justify-content: space-between;
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 0.6rem;
}
.order-actions {
    display: flex;
    gap: 0.5rem;
}

/* --- Order list bar --- */
.orders-bar {
    display: flex;
    gap: 0.35rem;
    overflow-x: auto;
    padding: 0.4rem 0;
    margin-bottom: 0.4rem;
    -webkit-overflow-scrolling: touch;
}
.order-tab {
    padding: 0.4rem 0.7rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-muted);
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
    font-size: 0.85rem;
    touch-action: manipulation;
    flex-shrink: 0;
}
.order-tab:hover { border-color: var(--success); }
.order-tab.active {
    border-color: var(--success);
    background: var(--success);
    color: white;
}

/* --- Cards / Forms --- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
}
.card h3 { margin-bottom: 0.6rem; font-size: 1rem; }

input, select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.5rem 0.75rem;
    font-size: 16px; /* prevents iOS zoom on focus */
    width: 100%;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
}
label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.form-group { margin-bottom: 0.75rem; }
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

/* --- Table --- */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    padding: 0.5rem 0.6rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; }
td { font-size: 0.85rem; }
tr:hover { background: var(--surface-hover); }

/* --- Stats --- */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}
.stat-card .value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--primary);
}
.stat-card .label {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 0.2rem;
}

/* --- Dialog overlay --- */
.dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 1rem;
}
.dialog {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    width: 100%;
    max-width: 420px;
}
.dialog h3 { margin-bottom: 0.75rem; }
.dialog-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

.hidden { display: none !important; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ======================== */
/* --- Responsive Mobile --- */
/* ======================== */
@media (max-width: 768px) {
    /* Prevent anything from pushing page wider than viewport */
    html, body {
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Nav: hide brand, compact links, no margin-auto push */
    nav {
        gap: 0.1rem;
        padding: 0.35rem 0.3rem;
        flex-wrap: wrap;
    }
    nav .brand {
        display: none;
    }
    nav a {
        font-size: 0.78rem;
        padding: 0.3rem 0.35rem;
    }
    nav .nav-logout {
        margin-left: auto;
    }

    .container {
        padding: 0.3rem;
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Kasse: stack vertically */
    .split {
        grid-template-columns: 1fr;
        height: auto;
        gap: 0;
        padding-bottom: 38vh;
    }

    /* Scrollable bars must not exceed viewport */
    .orders-bar, .deckel-bar, .category-tabs {
        max-width: 100%;
    }

    /* Products: always 3 columns, contained */
    .product-grid {
        gap: 0.3rem;
        max-width: 100%;
    }
    .product-grid-inner {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.3rem;
    }
    .product-btn {
        min-width: 0;
        overflow: hidden;
    }
    .product-btn .name {
        font-size: 0.8rem;
    }
    .product-btn .price {
        font-size: 0.7rem;
    }

    /* Order panel: fixed bottom sheet */
    .order-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: auto;
        max-height: 36vh;
        z-index: 90;
        border-radius: 12px 12px 0 0;
        box-shadow: 0 -4px 24px rgba(0,0,0,0.5);
        border: none;
        border-top: 1px solid var(--border);
    }
    .order-items {
        max-height: none;
        min-height: 0;
        padding: 0 0.4rem;
    }
    .order-item {
        padding: 0.2rem 0;
        gap: 0.3rem;
    }
    .order-item .qty {
        min-width: 22px;
        height: 22px;
        font-size: 0.75rem;
        border-radius: 4px;
    }
    .order-item .item-name { font-size: 0.8rem; }
    .order-item .item-price { font-size: 0.8rem; }
    .order-item .item-actions .btn-sm {
        min-width: 30px;
        min-height: 30px;
        font-size: 0.85rem;
        padding: 0;
    }
    .order-header { padding: 0.3rem 0.4rem; }
    .order-header h2 { font-size: 0.85rem; }
    .order-header input {
        padding: 0.25rem 0.4rem;
        font-size: 14px;
        height: 28px;
    }
    .order-footer { padding: 0.3rem 0.4rem; }
    .order-total { font-size: 1rem; margin-bottom: 0.25rem; }
    .order-actions { gap: 0.3rem; }
    .btn-lg { padding: 0.45rem 0.6rem; font-size: 0.85rem; }

    /* Forms */
    .form-row { grid-template-columns: 1fr; gap: 0; }
    .card { padding: 0.75rem; }

    /* Stats */
    .stat-cards { grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }
    .stat-card { padding: 0.6rem 0.3rem; }
    .stat-card .value { font-size: 1.1rem; }
    .stat-card .label { font-size: 0.65rem; }

    /* Tables */
    table { min-width: 0; }
    th, td { padding: 0.4rem; font-size: 0.78rem; }
    th { font-size: 0.72rem; }
}
