/* Framework Thumm – Mobile-first, iPhone-optimiert (Safe Areas, 16px Inputs gegen Auto-Zoom) */

:root {
    --bg: #f4f4f5;
    --surface: #ffffff;
    --border: #e4e4e7;
    --text: #18181b;
    --text-muted: #71717a;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --green: #16a34a;
    --sidebar-bg: #1e293b;
    --sidebar-text: #cbd5e1;
    --radius: 12px;
    --tabbar-h: calc(56px + env(safe-area-inset-bottom));
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #101014;
        --surface: #1c1c21;
        --border: #2e2e35;
        --text: #f4f4f5;
        --text-muted: #a1a1aa;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--primary); text-decoration: none; }
code { background: rgba(127,127,127,.12); padding: 1px 5px; border-radius: 5px; font-size: .85em; }
pre { background: rgba(127,127,127,.1); padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.muted { color: var(--text-muted); }
.hidden { display: none !important; }
.break-all { word-break: break-all; }

/* ---------- Grundlayout ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--sidebar-bg);
    color: #fff;
    padding: 10px 16px;
    padding-top: calc(10px + env(safe-area-inset-top));
}
.topbar-title { flex: 1; font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-user {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; text-transform: uppercase;
}
.burger { background: none; border: 0; color: #fff; font-size: 22px; padding: 4px 8px; cursor: pointer; }

.content {
    padding: 16px;
    padding-bottom: calc(var(--tabbar-h) + 16px);
    max-width: 1100px;
    margin: 0 auto;
}

/* Sidebar: mobil als Overlay, Desktop fest */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 260px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 16px 12px;
    padding-top: calc(16px + env(safe-area-inset-top));
    transform: translateX(-100%);
    transition: transform .2s ease;
    z-index: 50;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.sidebar.open { transform: translateX(0); }
.sidebar-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 40;
    display: none;
}
.sidebar.open + .sidebar-overlay { display: block; }
.sidebar-brand { font-weight: 700; color: #fff; font-size: 17px; padding: 8px 12px 16px; }
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 12px;
    border-radius: 10px;
    color: var(--sidebar-text);
    font-size: 15px;
    width: 100%;
    background: none; border: 0; cursor: pointer; text-align: left;
    font-family: inherit;
}
.nav-item:hover { background: rgba(255,255,255,.07); }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-icon { width: 22px; text-align: center; }
.sidebar-footer { margin-top: auto; border-top: 1px solid rgba(255,255,255,.1); padding-top: 8px; }

/* System-Untermenü */
.nav-group { margin-top: 10px; border-top: 1px solid rgba(255,255,255,.1); padding-top: 10px; }
.nav-group summary { list-style: none; cursor: pointer; }
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group-title { color: rgba(203,213,225,.7); font-size: 13px; text-transform: uppercase; letter-spacing: .05em; }
.nav-caret { margin-left: auto; transition: transform .15s; }
.nav-group[open] .nav-caret { transform: rotate(180deg); }
.nav-group-items .nav-item { padding-left: 24px; }

/* Untere Tab-Leiste (mobil) */
.tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
}
.tab {
    flex: 1;
    display: flex; flex-direction: column; align-items: center;
    padding: 8px 4px 6px;
    color: var(--text-muted);
    font-size: 10px;
    background: none; border: 0; cursor: pointer; font-family: inherit;
}
.tab.active { color: var(--primary); }
.tab-icon { font-size: 20px; line-height: 1.2; }

@media (min-width: 900px) {
    .sidebar { transform: none; }
    .content { margin-left: 260px; padding: 28px 32px; padding-bottom: 32px; }
    .topbar { display: none; }
    .tabbar { display: none; }
    :root { --tabbar-h: 0px; }
}

/* ---------- Komponenten ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}
.card h2 { font-size: 16px; margin: 0 0 12px; }
.card h3 { font-size: 14px; margin: 16px 0 8px; }
.card-danger { border-color: #fecaca; }
.card-highlight { border-color: var(--green); border-width: 2px; }

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin: 4px 0 16px;
}
.page-head h1 { font-size: 22px; margin: 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}
.stat-value { font-size: 24px; font-weight: 700; }
.stat-label { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* Dashboard-Widget-Raster (Positions-Logik: order + size half/full) */
.widget-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
.widget-grid .card { margin-bottom: 0; }
@media (min-width: 900px) {
    .widget-grid { grid-template-columns: 1fr 1fr; }
    .widget-full { grid-column: 1 / -1; }
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 16px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    text-align: center;
}
.btn:hover { border-color: var(--text-muted); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* Formulare */
label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 5px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; font-size: 14px; }
label.check-inline { display: inline-flex; margin-right: 16px; }
input[type=text], input[type=email], input[type=password], input[type=number],
select, textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font-size: 16px; /* verhindert iOS-Zoom beim Fokussieren */
    font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
input[type=file] { font-size: 14px; margin: 8px 0; max-width: 100%; }
.form-actions { margin-top: 18px; display: flex; gap: 8px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

/* Tabellen: Desktop klassisch, mobil als Karten */
.card-table { padding: 8px 0; overflow-x: auto; }
.card-table h2 { padding: 12px 20px 0; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 20px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: top; }
th { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: 0; }
table.plain td { padding: 8px 12px 8px 0; border: 0; }
.row-actions { white-space: nowrap; }
.row-actions form { display: inline-block; }
.inline-form { display: inline-block; }

@media (max-width: 700px) {
    .card-table table, .card-table tbody, .card-table tr, .card-table td { display: block; width: 100%; }
    .card-table thead { display: none; }
    .card-table tr { border-bottom: 8px solid var(--bg); padding: 6px 0; }
    .card-table td { border: 0; padding: 5px 20px; }
    .card-table td[data-label]::before {
        content: attr(data-label);
        display: block;
        font-size: 11px;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: .04em;
    }
    .row-actions { white-space: normal; }
    .row-actions .btn { margin: 4px 4px 0 0; }
}

/* Badges & Flash */
.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    background: rgba(127,127,127,.15);
    color: var(--text-muted);
    vertical-align: middle;
}
.badge-green { background: rgba(22,163,74,.12); color: var(--green); }
.badge-yellow { background: rgba(202,138,4,.14); color: #a16207; }
.badge-red { background: rgba(220,38,38,.12); color: var(--danger); }

.flash {
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 12px;
    font-size: 14px;
    border: 1px solid;
}
.flash-success { background: rgba(22,163,74,.08); border-color: rgba(22,163,74,.35); color: var(--green); }
.flash-error { background: rgba(220,38,38,.08); border-color: rgba(220,38,38,.35); color: var(--danger); }
.flash-info { background: rgba(37,99,235,.08); border-color: rgba(37,99,235,.35); color: var(--primary); }

/* Tabs (Einstellungen) */
.tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    margin-bottom: 16px;
    -webkit-overflow-scrolling: touch;
}
.tabs a {
    padding: 9px 14px;
    border-radius: 10px;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}
.tabs a.active { background: var(--primary); color: #fff; }

/* Module */
.module-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
.module-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.module-actions form { display: flex; gap: 8px; align-items: center; }

/* Berechtigungen */
.perm-group { margin-bottom: 12px; }
.perm-group-title { font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: 4px; }

/* Logs */
.log-pre { max-height: 400px; overflow: auto; white-space: pre-wrap; }

.restore-box { margin-top: 10px; padding: 12px; border: 1px dashed var(--danger); border-radius: 10px; }

/* ---------- Auth-Seiten ---------- */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    padding-top: calc(20px + env(safe-area-inset-top));
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px 28px;
}
.auth-card h1 { font-size: 22px; margin: 0 0 4px; }
.auth-sub { color: var(--text-muted); margin: 0 0 18px; }
.auth-card .btn { margin-top: 20px; }
.auth-link { text-align: center; margin-top: 18px; font-size: 14px; }
