:root {
  --red: #c0392b; --red-dark: #96281b; --red-light: #f9eceb;
  --amber: #e67e22; --amber-light: #fef5ec;
  --green: #27ae60; --green-light: #eafaf1;
  --gray-50: #f8f8f7; --gray-100: #f0efee; --gray-200: #e2e1df;
  --gray-400: #a09e9b; --gray-600: #6b6966; --gray-800: #2c2b29; --gray-900: #1a1918;
  --white: #fff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.14);
  --radius: 12px; --radius-sm: 8px;
  --nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body { font-family: 'DM Sans', sans-serif; background: var(--gray-50); color: var(--gray-800); font-size: 15px; line-height: 1.5; }

/* LOGIN */
#login-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--gray-900); z-index: 999; padding: 24px; }
.login-box { background: var(--white); border-radius: 20px; padding: 40px 32px; width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); }
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.login-logo-icon { width: 48px; height: 48px; background: var(--red); border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 24px; flex-shrink: 0; }
.login-logo-text { font-size: 17px; font-weight: 600; line-height: 1.2; }
.login-logo-sub { font-size: 12px; color: var(--gray-400); }
.login-title { font-size: 22px; font-weight: 600; margin-bottom: 6px; }
.login-sub { color: var(--gray-600); font-size: 14px; margin-bottom: 24px; }
.login-error { background: var(--red-light); color: var(--red); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; margin-bottom: 14px; display: none; }

/* FORMS */
.form-group { margin-bottom: 14px; }
label { display: block; font-size: 13px; font-weight: 500; color: var(--gray-600); margin-bottom: 5px; }
input, select, textarea { width: 100%; padding: 12px 14px; border: 1.5px solid var(--gray-200); border-radius: var(--radius-sm); font-family: inherit; font-size: 16px; color: var(--gray-800); background: var(--white); transition: border-color 0.15s; outline: none; -webkit-appearance: none; appearance: none; }
input:focus, select:focus, textarea:focus { border-color: var(--red); }
textarea { resize: vertical; min-height: 80px; font-size: 15px; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23a09e9b' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }

/* BUTTONS */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 20px; border-radius: var(--radius-sm); font-family: inherit; font-size: 15px; font-weight: 500; cursor: pointer; border: none; transition: all 0.15s; touch-action: manipulation; }
.btn-primary { background: var(--red); color: white; }
.btn-primary:active { background: var(--red-dark); transform: scale(0.98); }
.btn-secondary { background: var(--gray-100); color: var(--gray-800); border: 1.5px solid var(--gray-200); }
.btn-secondary:active { background: var(--gray-200); }
.btn-full { width: 100%; }
.btn-icon { padding: 8px 10px; font-size: 16px; background: var(--gray-100); border: 1px solid var(--gray-200); border-radius: var(--radius-sm); cursor: pointer; min-width: 38px; min-height: 38px; display: inline-flex; align-items: center; justify-content: center; touch-action: manipulation; }
.btn-icon.del:active { background: var(--red-light); }

/* LOADING */
.loading-overlay { position: fixed; inset: 0; background: rgba(255,255,255,0.88); z-index: 600; display: none; align-items: center; justify-content: center; flex-direction: column; gap: 14px; }
.loading-overlay.show { display: flex; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--gray-200); border-top-color: var(--red); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 14px; color: var(--gray-600); }

/* APP LAYOUT */
#app { display: none; min-height: 100vh; }
#app.visible { display: block; }

.topbar { background: var(--gray-900); padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 50; }
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-icon { font-size: 20px; }
.topbar-title { font-size: 17px; font-weight: 600; color: white; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-user { font-size: 12px; color: var(--gray-400); }
.topbar-btn { background: rgba(255,255,255,0.12); border: none; border-radius: 8px; padding: 6px 10px; color: white; font-size: 13px; cursor: pointer; }

.content-area { padding: 16px; padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 20px); }

/* BOTTOM NAV */
.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom); background: var(--white); border-top: 1px solid var(--gray-200); display: flex; align-items: stretch; z-index: 100; box-shadow: 0 -2px 12px rgba(0,0,0,0.06); }
.nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer; border: none; background: none; color: var(--gray-400); font-size: 10px; font-family: inherit; font-weight: 500; padding: 6px 2px; transition: color 0.15s; touch-action: manipulation; }
.nav-item.active { color: var(--red); }
.nav-icon { font-size: 22px; line-height: 1; }
.nav-item.admin-only { display: none; }

/* FAB */
.fab { position: fixed; right: 18px; bottom: calc(var(--nav-h) + var(--safe-bottom) + 14px); width: 54px; height: 54px; background: var(--red); border-radius: 50%; border: none; color: white; font-size: 26px; cursor: pointer; box-shadow: 0 4px 16px rgba(192,57,43,0.4); display: none; align-items: center; justify-content: center; z-index: 90; transition: transform 0.15s; touch-action: manipulation; }
.fab:active { transform: scale(0.92); }
.fab.visible { display: flex; }

/* PAGES */
.page { display: none; }
.page.active { display: block; }

/* STATS */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.stat-card { background: var(--white); border-radius: var(--radius); padding: 16px; border: 1px solid var(--gray-200); }
.stat-label { font-size: 11px; color: var(--gray-400); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.stat-value { font-size: 32px; font-weight: 600; line-height: 1; }
.stat-sub { font-size: 11px; color: var(--gray-400); margin-top: 4px; }
.stat-clickable { cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; }
.stat-clickable:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
.stat-clickable:active { transform: scale(0.97); }
.stat-red .stat-value { color: var(--red); }
.stat-amber .stat-value { color: var(--amber); }
.stat-green .stat-value { color: var(--green); }

/* CARDS */
.fahrer-card, .kontrolle-card, .audit-card, .user-card { background: var(--white); border-radius: var(--radius); border: 1px solid var(--gray-200); padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow-sm); }
.fahrer-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.fahrer-name { font-size: 16px; font-weight: 600; }
.fahrer-edv { font-size: 12px; color: var(--gray-400); font-family: 'DM Mono', monospace; margin-top: 2px; }
.fahrer-card-mid { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.fahrer-card-bot { display: flex; align-items: center; justify-content: space-between; }
.fahrer-meta { font-size: 12px; color: var(--gray-600); }
.fahrer-actions { display: flex; gap: 6px; }

.kontrolle-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px; }
.kontrolle-fahrer { font-size: 15px; font-weight: 600; }
.kontrolle-datum { font-size: 12px; color: var(--gray-400); margin-top: 2px; }
.kontrolle-meta { font-size: 12px; color: var(--gray-600); margin-top: 4px; }
.kontrolle-kommentar { font-size: 12px; color: var(--gray-600); margin-top: 6px; font-style: italic; }

.audit-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.audit-user { font-size: 13px; font-weight: 600; }
.audit-time { font-size: 11px; color: var(--gray-400); font-family: 'DM Mono', monospace; white-space: nowrap; }
.audit-detail { font-size: 13px; color: var(--gray-600); }

.user-card { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.user-card-name { font-size: 15px; font-weight: 600; }
.user-card-meta { font-size: 12px; color: var(--gray-400); margin-top: 2px; }

/* BADGES */
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge-ok { background: var(--green-light); color: #1e8449; }
.badge-warn { background: var(--amber-light); color: #a04000; }
.badge-danger { background: var(--red-light); color: var(--red-dark); }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }
.badge-blue { background: #eaf4fb; color: #1a5276; }
.badge-purple { background: #f4ecf7; color: #6c3483; }
.badge-login { background: var(--green-light); color: #1e8449; }
.badge-logout { background: var(--gray-100); color: var(--gray-600); }
.badge-create { background: #eaf4fb; color: #1a5276; }
.badge-update { background: var(--amber-light); color: #a04000; }
.badge-delete { background: var(--red-light); color: var(--red-dark); }

.klassen-list { display: flex; gap: 4px; flex-wrap: wrap; }

/* MODAL */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 300; display: none; align-items: flex-end; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal { background: var(--white); border-radius: 20px 20px 0 0; width: 100%; max-width: 600px; max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: var(--safe-bottom); box-shadow: var(--shadow-lg); animation: slideUp 0.22s ease; }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-handle { width: 36px; height: 4px; background: var(--gray-200); border-radius: 2px; margin: 12px auto 0; }
.modal-header { padding: 16px 20px 14px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--gray-100); }
.modal-title { font-size: 17px; font-weight: 600; }
.modal-close { background: var(--gray-100); border: none; border-radius: 50%; width: 30px; height: 30px; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--gray-600); }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px 16px; border-top: 1px solid var(--gray-100); display: flex; gap: 10px; flex-direction: column; }

/* KLASSEN */
.klassen-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.klasse-cb { display: flex; align-items: center; justify-content: center; padding: 12px 8px; border: 1.5px solid var(--gray-200); border-radius: var(--radius-sm); cursor: pointer; font-size: 15px; font-weight: 600; transition: all 0.15s; user-select: none; }
.klasse-cb input { display: none; }
.klasse-cb:has(input:checked) { background: var(--red-light); border-color: var(--red); color: var(--red-dark); }

/* VERLAUF */
.verlauf-item { background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.verlauf-date { font-size: 13px; font-weight: 600; }
.verlauf-meta { font-size: 12px; color: var(--gray-400); margin-top: 2px; }
.verlauf-note { font-size: 12px; color: var(--gray-600); margin-top: 4px; font-style: italic; }

/* MISC */
.empty-state { text-align: center; padding: 48px 24px; color: var(--gray-400); }
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-text { font-size: 15px; }
.search-bar { background: var(--white); border-radius: var(--radius-sm); border: 1.5px solid var(--gray-200); padding: 10px 14px; font-size: 16px; width: 100%; margin-bottom: 12px; -webkit-appearance: none; }
.search-bar:focus { border-color: var(--red); outline: none; }
.section-title { font-size: 12px; font-weight: 600; color: var(--gray-400); text-transform: uppercase; letter-spacing: 0.06em; margin: 16px 0 8px; }
.section-title:first-child { margin-top: 0; }
.detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
.detail-item label { font-size: 11px; color: var(--gray-400); display: block; margin-bottom: 3px; }

/* TOAST */
.toast { position: fixed; bottom: calc(var(--nav-h) + var(--safe-bottom) + 10px); left: 16px; right: 16px; background: var(--gray-900); color: white; padding: 12px 18px; border-radius: var(--radius-sm); font-size: 14px; z-index: 999; transform: translateY(20px); opacity: 0; transition: all 0.25s; box-shadow: var(--shadow-lg); text-align: center; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }

/* DESKTOP */
.sidebar { display: none; }

@media (min-width: 768px) {
  .bottom-nav { display: none; }
  #app.visible { display: flex; min-height: 100vh; }
  .sidebar { display: flex !important; position: fixed; top: 0; left: 0; width: 220px; height: 100vh; background: var(--gray-900); flex-direction: column; z-index: 100; }
  .sidebar-logo { padding: 24px 20px 20px; border-bottom: 1px solid rgba(255,255,255,0.08); }
  .sidebar-logo-title { font-size: 15px; font-weight: 600; color: white; line-height: 1.2; }
  .sidebar-logo-sub { font-size: 11px; color: var(--gray-400); margin-top: 2px; }
  .sidebar-nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
  .sidebar-nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm); cursor: pointer; color: var(--gray-400); font-size: 14px; font-weight: 500; transition: all 0.15s; border: none; background: none; width: 100%; text-align: left; }
  .sidebar-nav-item:hover { background: rgba(255,255,255,0.06); color: white; }
  .sidebar-nav-item.active { background: var(--red); color: white; }
  .sidebar-nav-item.admin-only { display: none; }
  .sidebar-footer { padding: 16px 12px; border-top: 1px solid rgba(255,255,255,0.08); }
  .sidebar-user-info { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
  .sidebar-avatar { width: 32px; height: 32px; background: var(--red); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; color: white; flex-shrink: 0; }
  .sidebar-username { font-size: 13px; color: white; font-weight: 500; }
  .sidebar-role { font-size: 11px; color: var(--gray-400); }
  .app-main { margin-left: 220px; flex: 1; min-width: 0; }
  .fab { bottom: 28px; right: 28px; }
  .fab.visible { display: flex; }
  .topbar { background: var(--white); border-bottom: 1px solid var(--gray-200); padding: 0 28px; height: 56px; padding-top: 0; }
  .topbar-title { color: var(--gray-800); }
  .topbar-btn { background: var(--gray-100); color: var(--gray-800); border: 1px solid var(--gray-200); }
  .content-area { padding: 28px; padding-bottom: 28px; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .modal-overlay { align-items: center; }
  .modal { border-radius: 16px; max-height: 88vh; }
  .modal-handle { display: none; }
  .modal-footer { flex-direction: row; justify-content: flex-end; }
  .modal-footer .btn-full { width: auto; }
  .toast { left: auto; right: 24px; width: auto; min-width: 260px; bottom: 24px; text-align: left; }
}
