/* ═══════════════════════════════════════════════════════════════
   App2 Design System — "Werkstatt-Premium"
   Professionell, warm, klar. Wie ein hochwertiges Werkzeug.
   ═══════════════════════════════════════════════════════════════ */

/* ── Fonts ───────────────────────────────────────────────────── */
@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@600;700&display=swap");

/* ── Alpine.js ──────────────────────────────────────────────── */
[x-cloak] { display: none !important; }

/* ── Custom Properties ───────────────────────────────────────── */
:root {
    /* Primärfarben */
    --primary: #0B84C4;
    --primary-hover: #0972AA;
    --primary-soft: #E8F4FB;
    --accent: #F59E0B;
    --accent-hover: #D97706;
    --accent-soft: #FEF3C7;

    /* Status */
    --success: #10B981;
    --success-soft: #D1FAE5;
    --warning: #F59E0B;
    --warning-soft: #FEF3C7;
    --danger: #EF4444;
    --danger-soft: #FEE2E2;
    --info: #6366F1;
    --info-soft: #E0E7FF;

    /* Neutrals */
    --text: #1E293B;
    --text-secondary: #64748B;
    --text-muted: #94A3B8;
    --bg: #FFFFFF;
    --bg-subtle: #F8FAFC;
    --bg-muted: #F1F5F9;
    --border: #E2E8F0;
    --border-active: #CBD5E1;

    /* Elevation */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.12);

    /* Spacing & Radii */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    /* Typography */
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-display: "Montserrat", var(--font-sans);

    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.5rem;
    --text-2xl: 2rem;

    /* Layout */
    --header-height: 56px;
    --sidebar-width: 260px;
    --content-max: 640px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-sans);
    color: var(--text);
    background: var(--bg-subtle);
    line-height: 1.5;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

img, svg { display: block; max-width: 100%; }

input, button, textarea, select {
    font: inherit;
    color: inherit;
}

/* ── Layout ──────────────────────────────────────────────────── */
.app2-shell {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

.app2-content {
    flex: 1;
    padding: 16px 16px calc(var(--safe-bottom) + 16px);
    max-width: var(--content-max);
    margin: 0 auto;
    width: 100%;
}

/* ── Header ──────────────────────────────────────────────────── */
.app2-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.app2-header-title {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app2-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--primary-soft);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: var(--text-sm);
    flex-shrink: 0;
    overflow: hidden;
}

.app2-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ── Sidebar Navigation ─────────────────────────────────────── */
.app2-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg);
    border-right: 1px solid var(--border);
    z-index: 300;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
}

.app2-sidebar.open {
    transform: translateX(0);
}

.app2-sidebar-brand {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: 700;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.app2-sidebar-items {
    flex: 1;
    padding: 8px 0;
    overflow-y: auto;
}

.app2-sidebar-items a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.app2-sidebar-items a svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    flex-shrink: 0;
}

.app2-sidebar-items a.active {
    color: var(--primary);
    background: var(--primary-soft);
    font-weight: 600;
}

.app2-sidebar-items a:hover:not(.active) {
    background: var(--bg-muted);
    color: var(--text);
}

.app2-sidebar-divider {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 16px 20px 6px;
}

.app2-sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 8px 0;
    flex-shrink: 0;
}

.app2-sidebar-footer a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.app2-sidebar-footer a svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    flex-shrink: 0;
}

.app2-sidebar-footer a.active {
    color: var(--primary);
    background: var(--primary-soft);
    font-weight: 600;
}

.app2-sidebar-footer a:hover:not(.active) {
    background: var(--bg-muted);
}

/* ── Sidebar Overlay (mobile) ──────────────────────────────── */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 250;
}

/* ── Hamburger Button ──────────────────────────────────────── */
.app2-hamburger {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    margin: -8px;
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
}

.app2-hamburger svg {
    width: 24px;
    height: 24px;
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
    background: var(--bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
    transition: box-shadow 0.2s, transform 0.2s;
}

/* Cards mit Dropdown-Menüs brauchen overflow:visible */
.card-has-menu {
    overflow: visible;
}

.card-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-header-title {
    font-weight: 600;
    font-size: var(--text-base);
    color: var(--text);
}

.card-header-subtitle {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.card-body {
    padding: 0 16px 16px;
}

.card-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

/* Card mit farbigem Seitenbalken */
.card-accent {
    border-left: 4px solid var(--primary);
}

.card-accent.success { border-left-color: var(--success); }
.card-accent.warning { border-left-color: var(--warning); }
.card-accent.danger  { border-left-color: var(--danger); }
.card-accent.info    { border-left-color: var(--info); }

/* ── Section ─────────────────────────────────────────────────── */
.section {
    margin-bottom: 24px;
}

.section-title {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
    padding: 0 4px;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: var(--text-base);
    border: none;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    min-height: 48px;
    line-height: 1;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover { background: var(--primary-hover); color: white; }

.btn-accent {
    background: var(--accent);
    color: white;
}

.btn-accent:hover { background: var(--accent-hover); color: white; }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}

.btn-outline:hover { background: var(--primary-soft); color: var(--primary); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover { background: var(--bg-muted); }

.btn-sm {
    padding: 8px 16px;
    font-size: var(--text-sm);
    min-height: 36px;
}

.btn-block {
    width: 100%;
}

.btn-icon {
    padding: 10px;
    min-height: unset;
}

.btn-icon svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* ── Forms ────────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: var(--text-base);
    background: var(--bg);
    transition: border-color 0.15s, box-shadow 0.15s;
    min-height: 48px;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-hint {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 4px;
}

.form-error {
    font-size: var(--text-sm);
    color: var(--danger);
    margin-top: 4px;
}

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.5;
}

.badge-primary  { background: var(--primary-soft); color: var(--primary); }
.badge-success  { background: var(--success-soft); color: #065F46; }
.badge-warning  { background: var(--warning-soft); color: #92400E; }
.badge-danger   { background: var(--danger-soft);  color: #991B1B; }
.badge-info     { background: var(--info-soft);    color: #3730A3; }
.badge-neutral  { background: var(--bg-muted);     color: var(--text-secondary); }

/* ── Stat Numbers (Dashboard) ────────────────────────────────── */
.stat {
    text-align: center;
    padding: 16px;
}

.stat-value {
    font-family: var(--font-display);
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.stat-label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ── List Items ──────────────────────────────────────────────── */
.list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

.list-item:last-child {
    border-bottom: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.list-item:first-child {
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.list-item:only-child {
    border-radius: var(--radius-md);
}

.list-item:active {
    background: var(--bg-muted);
}

.list-item-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--primary-soft);
    color: var(--primary);
}

.list-item-icon svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.list-item-content {
    flex: 1;
    min-width: 0;
}

.list-item-title {
    font-weight: 600;
    font-size: var(--text-base);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item-subtitle {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item-action {
    flex-shrink: 0;
    color: var(--text-muted);
}

.list-item-action svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* Rechte Seite eines list-item: Badges/Status + Chevron.
   Darf den Titel nicht verdrängen — deshalb begrenzt auf max. 45 % Breite
   und Badges darin truncaten per Ellipsis. */
.list-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    max-width: 45%;
    min-width: 0;
}

.list-item-meta .badge {
    max-width: 100%;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Quick Actions ───────────────────────────────────────────── */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.quick-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 8px;
    background: var(--bg);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    text-decoration: none;
    color: var(--text);
}

.quick-action:hover { background: var(--bg-muted); color: var(--text); }
.quick-action:active { transform: scale(0.95); }

.quick-action-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-soft);
    color: var(--primary);
}

.quick-action-icon svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.quick-action-label {
    font-size: var(--text-sm);
    font-weight: 600;
    text-align: center;
}

/* ── Alerts ──────────────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.alert-icon svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    flex-shrink: 0;
}

.alert-success { background: var(--success-soft); color: #065F46; }
.alert-warning { background: var(--warning-soft); color: #92400E; }
.alert-danger  { background: var(--danger-soft);  color: #991B1B; }
.alert-info    { background: var(--info-soft);    color: #3730A3; }

/* ── Empty State ─────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    fill: var(--border);
    margin: 0 auto 16px;
}

.empty-state-title {
    font-weight: 600;
    font-size: var(--text-lg);
    margin-bottom: 4px;
    color: var(--text);
}

.empty-state-text {
    font-size: var(--text-sm);
}

/* ── Login Page ──────────────────────────────────────────────── */
.login-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 24px;
    background: linear-gradient(135deg, var(--bg-subtle) 0%, var(--primary-soft) 100%);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 40px 32px;
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo-text {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--primary);
}

.login-logo-sub {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ── Tabs ────────────────────────────────────────────────────── */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0;
}

.tab {
    flex-shrink: 0;
    padding: 12px 16px;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* ── Search ──────────────────────────────────────────────────── */
.search-bar {
    position: relative;
}

.search-bar input {
    width: 100%;
    padding: 10px 16px 10px 40px;
    border: 2px solid var(--border);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    background: var(--bg-muted);
    transition: border-color 0.15s, background 0.15s;
}

.search-bar input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.search-bar svg {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    fill: var(--text-muted);
    pointer-events: none;
}

/* ── Skeleton Loading ────────────────────────────────────────── */
.skeleton {
    background: linear-gradient(90deg, var(--bg-muted) 25%, var(--bg-subtle) 50%, var(--bg-muted) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

@keyframes skeleton-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text   { height: 16px; margin-bottom: 8px; }
.skeleton-title  { height: 24px; width: 60%; margin-bottom: 12px; }
.skeleton-avatar { width: 40px; height: 40px; border-radius: var(--radius-full); }

/* ── HTMX Indicators ───────────────────────────────────────── */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

.htmx-request.htmx-indicator {
    display: inline-block;
}

/* Loading Spinner */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Utilities ───────────────────────────────────────────────── */
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-muted  { color: var(--text-secondary); }
.text-sm     { font-size: var(--text-sm); }
.text-xs     { font-size: var(--text-xs); }
.text-lg     { font-size: var(--text-lg); }
.text-xl     { font-size: var(--text-xl); }

.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }

.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }

.flex        { display: flex; }
.flex-col    { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1      { flex: 1; }

.flex-wrap   { flex-wrap: wrap; }
.gap-4       { gap: 4px; }
.ml-8        { margin-left: 8px; }
.mb-12       { margin-bottom: 12px; }

.hidden { display: none !important; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ── Responsive: Tablet ──────────────────────────────────────── */
@media (min-width: 768px) {
    :root {
        --content-max: 720px;
    }

    .app2-header {
        padding: 0 24px;
    }

    .app2-content {
        padding: 24px 24px calc(var(--safe-bottom) + 24px);
    }

    .quick-actions {
        grid-template-columns: repeat(4, 1fr);
    }

    .list-item:hover {
        background: var(--bg-subtle);
    }

    /* Zwei-Spalten-Layout für Listenseiten */
    .page-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 16px;
    }

    .page-grid-full {
        grid-column: 1 / -1;
    }
}

/* ── Responsive: Desktop ────────────────────────────────────── */
@media (min-width: 1024px) {
    /* Sidebar immer sichtbar */
    .app2-sidebar {
        transform: translateX(0);
    }

    /* Overlay nie sichtbar auf Desktop */
    .sidebar-overlay {
        display: none !important;
    }

    /* Hamburger verstecken */
    .app2-hamburger {
        display: none;
    }

    /* Header rechts neben Sidebar */
    .app2-header {
        position: fixed;
        top: 0;
        left: var(--sidebar-width);
        right: 0;
        padding: 0 32px;
    }

    /* Desktop-Header: Logo in Sidebar, also in Header verstecken */
    .app2-header-title {
        display: none;
    }

    /* Content rechts neben Sidebar */
    .app2-content {
        margin-left: var(--sidebar-width);
        margin-right: 0;
        padding: calc(var(--header-height) + 24px) 32px 48px;
        max-width: none;
        width: auto;
    }

    .quick-actions {
        grid-template-columns: repeat(4, 1fr);
    }

    .card:hover {
        box-shadow: var(--shadow-md);
    }

    /* Breitere Buttons am Desktop */
    .btn-block {
        max-width: 360px;
    }

    /* Tabs: mehr Platz */
    .tab {
        padding: 12px 24px;
    }
}

/* ── Responsive: Wide Desktop ───────────────────────────────── */
@media (min-width: 1280px) {
    /* Dashboard Stats nebeneinander */
    .stats-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 16px;
    }

    .stats-grid .card {
        margin-bottom: 0;
    }

    /* Zwei-Spalten-Layout für Detailseiten */
    .detail-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 24px;
        align-items: start;
    }

    .detail-grid-full {
        grid-column: 1 / -1;
    }

    .quick-actions {
        grid-template-columns: repeat(6, 1fr);
    }

    /* Drei Spalten auf Listenseiten */
    .page-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ── Responsive: Ultra Wide ─────────────────────────────────── */
@media (min-width: 1536px) {
    :root {
        --content-max: 1280px;
        --sidebar-width: 280px;
    }
}

/* ── PWA Standalone Mode ────────────────────────────────────── */
@media (display-mode: standalone) {
    .login-page {
        padding-top: env(safe-area-inset-top, 24px);
    }

    .app2-header {
        padding-top: env(safe-area-inset-top, 0);
        height: calc(var(--header-height) + env(safe-area-inset-top, 0));
    }
}

/* ── Kanban Mobile Tabs ────────────────────────────────────── */
.kanban-tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 16px;
    padding-bottom: 4px;
}
.kanban-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border: none;
    border-radius: var(--radius-full);
    background: var(--bg-muted);
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.kanban-tab.active {
    background: var(--primary);
    color: #fff;
}
.kanban-tab-count {
    font-size: 0.7rem;
    background: rgba(255,255,255,0.2);
    border-radius: var(--radius-full);
    padding: 0 6px;
    min-width: 18px;
    text-align: center;
}
.kanban-tab:not(.active) .kanban-tab-count {
    background: var(--border);
}

/* On mobile, section-title inside kanban is hidden (tab bar shows it) */
.kanban-column-title { display: none; }

/* Bauleiter-Avatare mit Badge pro Spalte */
.kanban-avatar {
    position: relative;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}
.kanban-avatar img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}
.kanban-avatar-fallback {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.7rem;
}
.kanban-avatar-badge {
    position: absolute;
    top: -4px;
    right: -6px;
    min-width: 16px;
    height: 16px;
    border-radius: 999px;
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    line-height: 1;
}

/* ── Photo Grid ───────────────────────────────────────────── */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
}
.photo-card {
    position: relative;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px;
    background: var(--bg-card, #fff);
}
.photo-frame {
    position: relative;
    width: 100%;
    height: 130px;
    border-radius: calc(var(--radius) - 2px);
    background: var(--bg-muted);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
.photo-thumb {
    width: 100%;
    height: 130px;
    object-fit: cover;
    display: block;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.photo-frame.loaded .photo-thumb {
    opacity: 1;
}
.photo-frame .photo-spinner {
    position: absolute;
    width: 22px;
    height: 22px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
.photo-frame.loaded .photo-spinner {
    display: none;
}
.photo-name {
    margin-top: 6px;
    font-weight: 600;
    font-size: var(--text-sm);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.photo-folder {
    color: var(--text-secondary);
    font-size: 0.78rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.photo-star-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0,0,0,0.5);
    border: none;
    color: #FCD34D;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s;
}
.photo-card:hover .photo-star-btn,
.photo-card:active .photo-star-btn {
    opacity: 1;
}

/* ── Desktop Grids ──────────────────────────────────────────── */
@media (min-width: 1024px) {
    /* Kanban: tabs hidden, all columns visible as grid */
    .kanban-tabs { display: none; }
    .kanban-column-title { display: flex; min-height: 3.2rem; align-items: flex-start; }
    .kanban-column[style*="display: none"] { display: block !important; }
    .kanban-column { display: block !important; }

    .kanban-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
        gap: 20px;
        align-items: start;
    }

    .kanban-grid .section {
        margin-bottom: 0;
    }

    /* Dashboard: Termine + Handlungsbedarf nebeneinander */
    .dashboard-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 24px;
        align-items: start;
    }

    .dashboard-grid .section {
        margin-bottom: 0;
    }

    /* Settings: Sektionen in Spalten */
    .settings-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 24px;
        align-items: start;
    }

    .settings-grid .section {
        margin-bottom: 0;
    }

    .settings-grid-full {
        grid-column: 1 / -1;
    }

    /* Due: Aktiv + Verschoben nebeneinander */
    .due-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 24px;
        align-items: start;
    }

    .due-grid .section {
        margin-bottom: 0;
    }

    /* Offers: Überfällig + Anstehend nebeneinander */
    .offers-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 24px;
        align-items: start;
    }

    .offers-grid .section {
        margin-bottom: 0;
    }
}

/* ── Planning Table ─────────────────────────────────────────── */
.planning-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

@media (min-width: 1024px) {
    .planning-scroll {
        overflow-x: visible;
    }

    .planning-table {
        min-width: 100%;
    }
}

/* ── Dropdown Menus (must escape card overflow) ────────────── */
.dropdown-menu {
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    z-index: 50;
    min-width: 140px;
}

.dropdown-menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: var(--text-sm);
}

.dropdown-menu button:hover {
    background: var(--bg-muted);
}

.dropdown-menu button:first-child {
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.dropdown-menu button:last-child {
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

/* ── Tables ─────────────────────────────────────────────────── */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

.table th {
    text-align: left;
    padding: 10px 12px;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--bg-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table tbody tr:hover {
    background: var(--bg-subtle);
}

.table .num {
    font-variant-numeric: tabular-nums;
    text-align: right;
}

/* ── Inline Input ───────────────────────────────────────────── */
.input {
    padding: 8px 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    background: var(--bg);
    transition: border-color 0.15s, box-shadow 0.15s;
    min-height: 36px;
}

.input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.input::placeholder {
    color: var(--text-muted);
}

/* ── ETL Specific ───────────────────────────────────────────── */
.etl-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.etl-stat {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.etl-stat-value {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.etl-stat-label {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.etl-stat-meta {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 2px;
}

.etl-stat.running {
    border-left: 3px solid var(--success);
}

.etl-stat.idle {
    border-left: 3px solid var(--border-active);
}

/* Tab bar using pills */
.pill-tabs {
    display: inline-flex;
    gap: 2px;
    padding: 4px;
    background: var(--bg-muted);
    border-radius: var(--radius-sm);
    overflow-x: auto;
}

.pill-tab {
    padding: 8px 16px;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-secondary);
    border-radius: 6px;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

.pill-tab:hover {
    background: var(--bg);
    color: var(--text);
}

.pill-tab.active {
    background: var(--bg);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

/* Section header with action */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.section-header-title {
    font-weight: 700;
    font-size: var(--text-base);
}

.section-header-subtitle {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

/* ── Floating Action Button (Camera) ────────────────────────── */
.fab-camera {
    position: fixed;
    bottom: calc(24px + var(--safe-bottom));
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(11, 132, 196, 0.4);
    z-index: 90;
    transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.fab-camera:active {
    transform: scale(0.92);
}

.fab-camera:hover {
    box-shadow: 0 6px 24px rgba(11, 132, 196, 0.5);
}

.fab-camera svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

.fab-camera.uploading {
    opacity: 0.7;
    pointer-events: none;
}

/* Spinner im FAB */
.fab-camera .fab-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ── Pending Uploads Section ────────────────────────────────── */
.pending-uploads {
    margin-bottom: 16px;
}

.pending-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 140px));
    gap: 8px;
    padding: 12px;
}

.pending-item {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-muted);
}

.pending-thumb {
    width: 100%;
    height: 90px;
    object-fit: cover;
    display: block;
}

.pending-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 4px 6px;
    font-size: 0.7rem;
    font-weight: 600;
    text-align: center;
}

.pending-status.status-pending {
    background: var(--warning-soft);
    color: #92400E;
}

.pending-status.status-uploading {
    background: var(--info-soft);
    color: #3730A3;
}

.pending-status.status-uploaded {
    background: var(--success-soft);
    color: #065F46;
}

.pending-status.status-failed {
    background: var(--danger-soft);
    color: #991B1B;
}

.pending-status svg {
    width: 12px;
    height: 12px;
    fill: currentColor;
    flex-shrink: 0;
}

/* ── OCR-Scan-Indikator ─────────────────────────────────────── */
/* Leuchtender Rand ums Zähler-Bild während OCR läuft — non-blockierend,
   Monteur kann den Wert parallel abtippen falls das Netz lahm ist. */
@keyframes ocr-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(76, 167, 255, 0); }
    50%      { box-shadow: 0 0 0 8px rgba(76, 167, 255, 0.55); }
}
.ocr-scanning {
    animation: ocr-pulse 1.6s ease-in-out infinite;
}
.ocr-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    pointer-events: none;
}
@keyframes ocr-spin { to { transform: rotate(360deg); } }
.ocr-spinner {
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: ocr-spin 0.9s linear infinite;
}

/* ── Print ───────────────────────────────────────────────────── */
@media print {
    .app2-header,
    .app2-sidebar,
    .sidebar-overlay {
        display: none !important;
    }

    .app2-content {
        margin: 0;
        padding: 0;
        max-width: 100%;
    }
}
