:root{
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #f4f6fb;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1f2937;
    --text-muted: #64748b;
    --danger-bg: #fee2e2;
    --danger-text: #991b1b;
    --ok-bg: #dcfce7;
    --ok-text: #166534;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 14px rgba(15,23,42,.06);
}

*{ box-sizing: border-box; }

body{
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

h1,h2,h3{ margin: 0 0 14px; }
h1{ font-size: 21px; }
h2{ font-size: 17px; }
a{ color: var(--primary); text-decoration: none; }
a:hover{ text-decoration: underline; }

/* ---------- Navigation ---------- */
.topnav{
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 4px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 8px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow);
    scrollbar-width: none;
}
.topnav::-webkit-scrollbar{ display: none; }
.topnav-item{
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 64px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    text-decoration: none !important;
    flex: 0 0 auto;
}
.topnav-item .ic{ font-size: 20px; }
.topnav-item.active, .topnav-item:hover{
    background: var(--bg);
    color: var(--primary);
}

/* ---------- Layout ---------- */
.page{ max-width: 900px; margin: 0 auto; padding: 16px 12px 60px; }

.flash{
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    font-size: 14px;
    font-weight: 600;
}
.flash-success{ background: var(--ok-bg); color: var(--ok-text); }
.flash-error{ background: var(--danger-bg); color: var(--danger-text); }

/* ---------- Karten ---------- */
.card{
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}
.card-grid{
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}
.tile{
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 18px 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-decoration: none !important;
    color: var(--text) !important;
    font-weight: 600;
    font-size: 13px;
    text-align: center;
}
.tile .ic{ font-size: 28px; }
.tile:hover{ border-color: var(--primary); }

/* ---------- Formulare ---------- */
label{ display:block; font-size: 13px; font-weight: 600; margin: 10px 0 4px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=search], select, textarea{
    width: 100%;
    padding: 10px 12px;
    font-size: 15px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
}
input:focus, select:focus, textarea:focus{ outline: none; border-color: var(--primary); }

.btn, button, input[type=submit]{
    display: inline-block;
    padding: 11px 18px;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    background: var(--primary);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    box-shadow: var(--shadow);
}
.btn:hover, button:hover, input[type=submit]:hover{ background: var(--primary-dark); }
.btn:active, button:active, input[type=submit]:active{ transform: scale(.98); }
.btn-sm{ padding: 7px 12px; font-size: 12px; }
.btn-secondary{ background: #64748b; }
.btn-danger{ background: #dc2626; }
.btn-row{ display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* ---------- Tabellen ---------- */
.table-wrap{
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
table{ width: 100%; border-collapse: collapse; font-size: 13px; }
th{
    position: sticky; top: 0;
    background: var(--primary);
    color: #fff;
    text-align: left;
    padding: 10px 12px;
    font-size: 12px;
    white-space: nowrap;
}
td{ padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
td.actions-cell{
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    white-space: nowrap;
}
td.actions-cell form{ display: inline-flex; margin: 0; }
tbody tr:hover{ background: #f8fafc; }

th.sortable-th{
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 22px;
}
th.sortable-th:hover{ background: var(--primary-dark); }
th.sortable-th::after{
    content: "";
    position: absolute;
    right: 8px;
    top: 50%;
    margin-top: -6px;
    width: 0; height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 4px solid rgba(255,255,255,.5);
    opacity: .6;
}
th.sortable-th.sort-desc::after{
    border-bottom: none;
    border-top: 4px solid rgba(255,255,255,.5);
}
th.sortable-th.sort-asc::after,
th.sortable-th.sort-desc::after{
    opacity: 1;
    border-bottom-color: #fff;
    border-top-color: #fff;
}
tr.row-empty td{ background: var(--danger-bg); color: var(--danger-text); }
tr.row-counted td{ background: var(--ok-bg); }

.qr-thumb{
    width: 48px; height: 48px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: #fff;
    padding: 2px;
    display: block;
}
.qr-large{ width: 220px; height: 220px; border-radius: var(--radius); border: 1px solid var(--border); background: #fff; padding: 8px; }

.toolbar{ display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar input[type=search]{ flex: 1; }
.count-badge{ align-self: center; font-size: 12px; color: var(--text-muted); white-space: nowrap; }

.badge{ display:inline-block; padding:3px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-ok{ background: var(--ok-bg); color: var(--ok-text); }
.badge-warn{ background: #fef9c3; color: #854d0e; }
.badge-empty{ background: var(--danger-bg); color: var(--danger-text); }

/* ---------- Tabs (z.B. Kisten / Alles) ---------- */
.tabs{
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.tab-btn{
    background: transparent;
    color: var(--text-muted);
    box-shadow: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    padding: 10px 16px;
    font-size: 14px;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
}
.tab-btn:hover{ background: var(--bg); color: var(--text); }
.tab-btn.tab-btn-active{
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 700;
}

.login-wrap{ max-width: 380px; margin: 60px auto; }
.center{ text-align: center; }
.muted{ color: var(--text-muted); font-size: 13px; }
