/* =====================================================================
   VLYX Ressourcenplanung – Anwendungsstile
   ---------------------------------------------------------------------
   Eigenstaendige Umsetzung ohne externe CSS-Bibliothek. Die Optik folgt
   dem Erscheinungsbild der VLYX-Anwendungen (Digitale Vorgangsakte).
   Alle Farben, Abstaende und Schriften kommen aus den Variablen im
   :root-Block und lassen sich dort zentral austauschen.
   ===================================================================== */

/* ===== 1. Zentrale Theme-Konfiguration ============================== */
:root {
    /* Pflichtvariablen des Corporate Designs */
    --color-primary:    #2563eb;
    --color-secondary:  #1e293b;
    --color-accent:     #0891b2;
    --color-background: #f1f5f9;
    --color-surface:    #ffffff;
    --color-text:       #1e293b;
    --color-muted:      #64748b;
    --color-success:    #16a34a;
    --color-warning:    #d97706;
    --color-error:      #dc2626;
    --font-primary:     -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                        "Helvetica Neue", Arial, sans-serif;
    --font-secondary:   var(--font-primary);
    --border-radius:    0.5rem;
    --spacing-base:     1rem;

    /* Abgeleitete Farbtoene */
    --color-primary-dark:  #1d4ed8;
    --color-primary-light: #dbeafe;
    --color-info:          #0891b2;
    --color-border:        #e2e8f0;
    --color-border-strong: #cbd5e1;

    /* Flaechen */
    --surface-muted:   #f8fafc;
    --surface-hover:   #f1f5f9;

    /* Seitenleiste */
    --sidebar-width:       260px;
    --sidebar-bg:          #1e293b;
    --sidebar-hover:       #334155;
    --sidebar-text:        #cbd5e1;
    --sidebar-text-active: #ffffff;
    --sidebar-border:      rgba(255, 255, 255, 0.1);

    /* Kopfleiste */
    --topbar-height: 56px;
    --topbar-bg:     #ffffff;

    /* Typografie */
    --font-size-base: 0.9rem;
    --font-size-sm:   0.8rem;
    --font-size-xs:   0.72rem;
    --heading-weight: 600;

    /* Sonstiges */
    --radius-sm: 0.375rem;
    --radius-lg: 0.75rem;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 2px 8px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 10px 40px rgba(15, 23, 42, 0.15);
    --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.35);
}

/* ===== 2. Grundlagen =============================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--font-primary);
    font-size: var(--font-size-base);
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-background);
}

h1, h2, h3, h4, h5 {
    font-family: var(--font-secondary);
    font-weight: var(--heading-weight);
    margin: 0 0 0.5rem;
    line-height: 1.25;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: 0.95rem; }

p { margin: 0 0 0.75rem; }

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

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

hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 1.25rem 0;
}

:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.icon {
    vertical-align: -0.125em;
    flex-shrink: 0;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Sprungmarke für Tastaturbedienung */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 2000;
    background: var(--color-primary);
    color: #fff;
    padding: 0.75rem 1.25rem;
    border-radius: 0 0 var(--radius-sm) 0;
}

.skip-link:focus {
    left: 0;
    color: #fff;
}

/* ===== 3. Grundlayout ============================================== */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    margin-left: var(--sidebar-width);
}

.app-content {
    flex: 1;
    padding: 1.5rem;
}

/* ===== 4. Seitenleiste ============================================= */
.app-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 1040;
    transition: transform 0.25s ease;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.9rem 1.25rem;
    border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    min-width: 0;
}

.sidebar-brand:hover {
    color: #fff;
    text-decoration: none;
}

.sidebar-brand .brand-mark {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    background: var(--color-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.sidebar-brand .brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sidebar-brand .brand-title {
    font-size: 0.95rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-brand .brand-subtitle {
    font-size: 0.68rem;
    font-weight: 400;
    color: var(--sidebar-text);
    opacity: 0.75;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    padding: 0.35rem;
    border-radius: var(--radius-sm);
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
}

.sidebar-section-label {
    padding: 0.5rem 1.25rem 0.2rem;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.5;
    user-select: none;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.25rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.875rem;
    border-left: 3px solid transparent;
    transition: background-color 0.15s, color 0.15s;
}

.sidebar-nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
    text-decoration: none;
}

.sidebar-nav-item.active {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
    border-left-color: var(--color-primary);
    font-weight: 500;
}

.sidebar-nav-item .nav-badge {
    margin-left: auto;
    background: var(--color-error);
    color: #fff;
    border-radius: 999px;
    font-size: 0.68rem;
    padding: 0.1rem 0.45rem;
    font-weight: 600;
}

.sidebar-divider {
    border-top: 1px solid var(--sidebar-border);
    margin: 0.5rem 1.25rem;
}

.sidebar-footer {
    padding: 0.9rem 1.25rem;
    border-top: 1px solid var(--sidebar-border);
    font-size: 0.8rem;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--sidebar-text);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 1035;
}

.sidebar-overlay.show {
    display: block;
}

/* ===== 5. Kopfleiste =============================================== */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 1.5rem;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--color-border);
}

.topbar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--color-text);
    cursor: pointer;
    padding: 0.4rem;
    border-radius: var(--radius-sm);
}

.topbar-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    color: var(--color-primary);
    flex-shrink: 0;
    transition: background-color 0.15s, color 0.15s;
}

.topbar-back:hover {
    background: var(--color-primary);
    color: #fff;
    text-decoration: none;
}

.topbar-breadcrumb {
    display: flex;
    align-items: center;
    min-width: 0;
    overflow: hidden;
}

.topbar-breadcrumb-link {
    font-size: 0.875rem;
    white-space: nowrap;
}

.topbar-breadcrumb-sep {
    color: var(--color-muted);
    margin: 0 0.4rem;
    display: flex;
}

.topbar-breadcrumb-current {
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Benutzermenü ohne JavaScript (details/summary) */
.user-menu {
    position: relative;
}

.user-menu > summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--color-text);
}

.user-menu > summary::-webkit-details-marker {
    display: none;
}

.user-menu > summary:hover {
    background: var(--surface-hover);
}

.user-menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 220px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    padding: 0.4rem;
    z-index: 1050;
}

.user-menu-panel .menu-label {
    padding: 0.4rem 0.6rem;
    font-size: var(--font-size-xs);
    color: var(--color-muted);
}

.user-menu-panel a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-size: 0.875rem;
}

.user-menu-panel a:hover {
    background: var(--surface-hover);
    text-decoration: none;
}

/* ===== 6. Seitenkopf =============================================== */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.page-header h1 {
    margin: 0;
}

.page-header .page-subtitle {
    color: var(--color-muted);
    font-size: var(--font-size-sm);
    margin: 0.25rem 0 0;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* ===== 7. Schaltflächen ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 0.9rem;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.25;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.btn:hover {
    text-decoration: none;
}

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
    color: #fff;
}

.btn-secondary {
    background: var(--color-surface);
    border-color: var(--color-border-strong);
    color: var(--color-text);
}

.btn-secondary:hover {
    background: var(--surface-hover);
    color: var(--color-text);
}

.btn-danger {
    background: var(--color-error);
    border-color: var(--color-error);
    color: #fff;
}

.btn-danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
    color: #fff;
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--color-primary);
}

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

.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

.btn-block {
    width: 100%;
}

.btn-group {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

/* Umschalter, z. B. Zeitraumauswahl im Board */
.segmented {
    display: inline-flex;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--color-surface);
}

.segmented a {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    color: var(--color-text);
    border-right: 1px solid var(--color-border);
}

.segmented a:last-child {
    border-right: none;
}

.segmented a:hover {
    background: var(--surface-hover);
    text-decoration: none;
}

.segmented a.active {
    background: var(--color-primary);
    color: #fff;
}

/* ===== 8. Karten =================================================== */
.content-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    margin-bottom: 1.25rem;
}

.card-header-custom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding: 0.85rem 1.15rem;
    border-bottom: 1px solid var(--color-border);
    font-weight: 600;
    font-size: 0.95rem;
}

.card-header-custom .card-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-body-custom {
    padding: 1.15rem;
}

.card-body-flush {
    padding: 0;
}

.card-footer-custom {
    padding: 0.85rem 1.15rem;
    border-top: 1px solid var(--color-border);
    background: var(--surface-muted);
    border-radius: 0 0 var(--border-radius) var(--border-radius);
}

/* Kennzahlenkarten */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: var(--spacing-base);
    margin-bottom: 1.25rem;
}

.kpi-card {
    display: flex;
    align-items: flex-start;
    gap: 0.9rem;
    padding: 1.1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    color: var(--color-text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

a.kpi-card:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-md);
    text-decoration: none;
    color: var(--color-text);
}

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

.kpi-icon.success { background: #dcfce7; color: var(--color-success); }
.kpi-icon.warning { background: #fef3c7; color: var(--color-warning); }
.kpi-icon.danger  { background: #fee2e2; color: var(--color-error); }
.kpi-icon.info    { background: #cffafe; color: var(--color-info); }

.kpi-value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.1;
}

.kpi-label {
    font-size: var(--font-size-sm);
    color: var(--color-muted);
    margin-top: 0.15rem;
}

.kpi-card.is-danger { border-color: var(--color-error); }
.kpi-card.is-danger .kpi-value { color: var(--color-error); }

/* ===== 9. Tabellen ================================================= */
.table-container {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
}

table.data-table th {
    background: var(--surface-muted);
    color: var(--color-muted);
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    text-align: left;
    padding: 0.7rem 1rem;
    white-space: nowrap;
    border-bottom: 1px solid var(--color-border);
}

table.data-table td {
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

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

table.data-table tbody tr:hover {
    background: var(--surface-muted);
}

table.data-table .cell-right { text-align: right; }
table.data-table .cell-center { text-align: center; }
table.data-table .cell-actions {
    text-align: right;
    white-space: nowrap;
    width: 1%;
}

.table-empty {
    padding: 2.5rem 1.25rem;
    text-align: center;
    color: var(--color-muted);
}

.table-empty .icon {
    color: var(--color-border-strong);
    margin-bottom: 0.5rem;
}

/* ===== 10. Abzeichen und Kennzeichen =============================== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2em 0.55em;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}

.badge-muted {
    background: var(--surface-muted);
    color: var(--color-muted);
    border: 1px solid var(--color-border);
}

.badge-primary { background: var(--color-primary-light); color: var(--color-primary-dark); }
.badge-success { background: #dcfce7; color: #14532d; }
.badge-warning { background: #fef3c7; color: #78350f; }
.badge-danger  { background: #fee2e2; color: #7f1d1d; }
.badge-info    { background: #cffafe; color: #164e63; }

.badge-type {
    border: 1px solid transparent;
}

.font-normal      { font-style: normal; font-weight: 400; }
.font-bold        { font-style: normal; font-weight: 700; }
.font-italic      { font-style: italic; font-weight: 400; }
.font-bold_italic { font-style: italic; font-weight: 700; }

.dot {
    display: inline-block;
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ===== 11. Meldungen =============================================== */
.flash-area {
    margin-bottom: 1.25rem;
}

.alert {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.8rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
}

.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #14532d; }
.alert-error   { background: #fef2f2; border-color: #fecaca; color: #7f1d1d; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #78350f; }
.alert-info    { background: #eff6ff; border-color: #bfdbfe; color: #1e3a8a; }

.alert .alert-title {
    font-weight: 600;
    margin-bottom: 0.15rem;
}

.alert ul {
    margin: 0.4rem 0 0;
    padding-left: 1.1rem;
}

/* ===== 12. Formulare =============================================== */
.form-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1rem;
}

.form-field { grid-column: span 6; }
.form-field.half  { grid-column: span 3; }
.form-field.third { grid-column: span 2; }

.form-label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: 0.3rem;
}

.form-label .required {
    color: var(--color-error);
    margin-left: 0.15rem;
}

.form-control,
.form-select {
    display: block;
    width: 100%;
    padding: 0.5rem 0.7rem;
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.4;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--color-primary);
    box-shadow: var(--focus-ring);
    outline: none;
}

.form-control[readonly],
.form-control:disabled,
.form-select:disabled {
    background: var(--surface-muted);
    color: var(--color-muted);
}

textarea.form-control {
    min-height: 90px;
    resize: vertical;
}

input[type="color"].form-control {
    padding: 0.2rem;
    height: 38px;
    cursor: pointer;
}

.form-help {
    font-size: var(--font-size-xs);
    color: var(--color-muted);
    margin-top: 0.25rem;
}

.form-error {
    font-size: var(--font-size-xs);
    color: var(--color-error);
    margin-top: 0.25rem;
}

.has-error .form-control,
.has-error .form-select {
    border-color: var(--color-error);
}

.form-check {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
    width: 1.05rem;
    height: 1.05rem;
    margin-top: 0.15rem;
    accent-color: var(--color-primary);
    flex-shrink: 0;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.fieldset-block {
    border: none;
    padding: 0;
    margin: 0 0 1.5rem;
}

.fieldset-block > legend {
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0;
    margin-bottom: 0.75rem;
    color: var(--color-text);
}

/* Filterleiste */
.filter-bar {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: 1rem 1.15rem;
    margin-bottom: 1.25rem;
}

.filter-bar .form-grid {
    gap: 0.75rem;
}

.filter-bar .form-label {
    font-size: var(--font-size-xs);
    color: var(--color-muted);
}

.filter-toggle {
    display: none;
}

/* ===== 13. Beschreibungslisten ===================================== */
.detail-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.9rem 1.5rem;
    margin: 0;
}

.detail-list .detail-item {
    min-width: 0;
}

.detail-list dt {
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-muted);
    font-weight: 600;
    margin-bottom: 0.15rem;
}

.detail-list dd {
    margin: 0;
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}

/* ===== 14. Zeitleiste / Historie =================================== */
.timeline {
    list-style: none;
    margin: 0;
    padding: 0;
}

.timeline li {
    position: relative;
    padding: 0 0 1rem 1.4rem;
    border-left: 2px solid var(--color-border);
}

.timeline li:last-child {
    border-left-color: transparent;
    padding-bottom: 0;
}

.timeline li::before {
    content: "";
    position: absolute;
    left: -0.32rem;
    top: 0.35rem;
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    background: var(--color-primary);
}

.timeline li.is-override::before { background: var(--color-warning); }

.timeline .timeline-meta {
    font-size: var(--font-size-xs);
    color: var(--color-muted);
}

.timeline .timeline-text {
    font-size: 0.875rem;
}

/* ===== 15. Dialoge ================================================= */
dialog.app-dialog {
    border: none;
    border-radius: var(--border-radius);
    padding: 0;
    width: min(560px, calc(100vw - 2rem));
    box-shadow: var(--shadow-lg);
    color: var(--color-text);
}

dialog.app-dialog::backdrop {
    background: rgba(15, 23, 42, 0.55);
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    font-weight: 600;
}

.dialog-body {
    padding: 1.25rem;
    max-height: 65vh;
    overflow-y: auto;
}

.dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0.9rem 1.25rem;
    border-top: 1px solid var(--color-border);
    background: var(--surface-muted);
}

.dialog-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-muted);
    padding: 0.25rem;
    border-radius: var(--radius-sm);
}

.dialog-close:hover {
    background: var(--surface-hover);
    color: var(--color-text);
}

/* ===== 16. Konfliktdarstellung ===================================== */
.conflict-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.conflict-item {
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-error);
    border-radius: var(--radius-sm);
    padding: 0.8rem 1rem;
    background: var(--color-surface);
}

.conflict-item.severity-warning { border-left-color: var(--color-warning); }
.conflict-item.is-overridden {
    border-left-color: var(--color-muted);
    background: var(--surface-muted);
}

.conflict-item .conflict-type {
    font-size: var(--font-size-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-error);
}

.conflict-item.severity-warning .conflict-type { color: var(--color-warning); }
.conflict-item.is-overridden .conflict-type { color: var(--color-muted); }

.conflict-item .conflict-message {
    font-size: 0.9rem;
    margin: 0.2rem 0 0.35rem;
}

.conflict-item .conflict-options {
    margin: 0;
    padding-left: 1.1rem;
    font-size: var(--font-size-sm);
    color: var(--color-muted);
}

/* ===== 17. Legende ================================================= */
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 0.9rem;
    align-items: center;
    font-size: var(--font-size-xs);
    color: var(--color-muted);
}

.legend .legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.legend .legend-swatch {
    width: 0.85rem;
    height: 0.85rem;
    border-radius: 3px;
    border: 1px solid rgba(15, 23, 42, 0.2);
}

/* ===== 18. Kartenliste (mobile Darstellung von Tabellen) =========== */
.card-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.85rem;
}

.list-card {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.85rem 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--card-accent, var(--color-primary));
    border-radius: var(--border-radius);
    color: var(--color-text);
    text-decoration: none;
}

a.list-card:hover {
    box-shadow: var(--shadow-md);
    text-decoration: none;
    color: var(--color-text);
}

.list-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
}

.list-card-title {
    font-weight: 600;
    font-size: 0.925rem;
    line-height: 1.3;
}

.list-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem 0.85rem;
    font-size: var(--font-size-sm);
    color: var(--color-muted);
}

.list-card-meta span {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

/* ===== 19. Anmeldeseite ============================================ */
.guest-layout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.25rem;
}

.login-header {
    text-align: center;
    margin-bottom: 1.75rem;
}

.login-header .brand-mark {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-sm);
    background: var(--color-primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

.login-header h1 {
    font-size: 1.2rem;
    margin-bottom: 0.25rem;
}

.login-header p {
    color: var(--color-muted);
    font-size: var(--font-size-sm);
    margin: 0;
}

.login-footer {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
    font-size: var(--font-size-xs);
    color: var(--color-muted);
    text-align: center;
}

/* ===== 20. Untere Navigation (Smartphone) ========================== */
.mobile-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1040;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    justify-content: space-around;
    padding: 0.35rem 0 calc(0.35rem + env(safe-area-inset-bottom, 0px));
}

.mobile-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    padding: 0.3rem 0.5rem;
    font-size: 0.68rem;
    color: var(--color-muted);
    min-width: 60px;
}

.mobile-nav a.active,
.mobile-nav a:hover {
    color: var(--color-primary);
    text-decoration: none;
}

/* ===== 21. Hilfsklassen ============================================ */
.text-muted   { color: var(--color-muted); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-danger  { color: var(--color-error); }
.text-small   { font-size: var(--font-size-sm); }
.text-xs      { font-size: var(--font-size-xs); }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.text-bold    { font-weight: 600; }
.text-nowrap  { white-space: nowrap; }

.flex        { display: flex; }
.flex-wrap   { flex-wrap: wrap; }
.flex-column { flex-direction: column; }
.items-center{ align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.35rem; }
.gap-2 { gap: 0.65rem; }
.gap-3 { gap: 1rem; }
.ml-auto { margin-left: auto; }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.35rem; }
.mt-2 { margin-top: 0.75rem; }
.mt-3 { margin-top: 1.25rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.35rem; }
.mb-2 { margin-bottom: 0.75rem; }
.mb-3 { margin-bottom: 1.25rem; }

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: var(--spacing-base);
}

.inline-form {
    display: inline;
}

/* ===== 22. Ressourcenkalender ====================================== */
.resource-calendar {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.5rem;
}

.calendar-day {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.5rem;
    background: var(--color-surface);
    min-height: 92px;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.calendar-day.is-weekend { background: var(--surface-muted); }
.calendar-day.is-today   { border-color: var(--color-primary); border-width: 2px; }
.calendar-day.has-overlap { border-color: var(--color-error); }

.calendar-day .day-label {
    font-size: var(--font-size-xs);
    color: var(--color-muted);
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    gap: 0.25rem;
}

.calendar-entry {
    font-size: var(--font-size-xs);
    padding: 0.2rem 0.35rem;
    border-radius: 3px;
    border-left: 3px solid;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.calendar-entry:hover { text-decoration: none; }

.calendar-day .day-free {
    font-size: var(--font-size-xs);
    color: var(--color-success);
    margin-top: auto;
}

/* Auslastungsbalken */
.meter {
    height: 6px;
    border-radius: 999px;
    background: var(--color-border);
    overflow: hidden;
    min-width: 60px;
}

.meter > span {
    display: block;
    height: 100%;
    background: var(--color-primary);
}

.meter.high > span { background: var(--color-warning); }
.meter.full > span { background: var(--color-error); }

/* ===== 23. Reaktionsfähiges Verhalten ============================== */

/* Tablet und darunter: Seitenleiste ausblendbar */
@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
    }

    .app-sidebar.show {
        transform: translateX(0);
    }

    .app-main {
        margin-left: 0;
    }

    .sidebar-close,
    .topbar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .app-content {
        padding: 1.15rem;
    }
}

/* Smartphone */
@media (max-width: 767.98px) {
    .app-content {
        padding: 0.9rem;
        padding-bottom: 5rem;
    }

    .app-topbar {
        padding: 0 0.9rem;
    }

    .topbar-breadcrumb .topbar-breadcrumb-link,
    .topbar-breadcrumb .topbar-breadcrumb-sep {
        display: none;
    }

    .mobile-nav {
        display: flex;
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .page-actions .btn {
        flex: 1 1 auto;
    }

    .form-field.half,
    .form-field.third {
        grid-column: span 6;
    }

    /* Berührungsflächen vergrößern und iOS-Zoom verhindern */
    .form-control,
    .form-select {
        font-size: 16px;
        min-height: 44px;
    }

    .btn {
        min-height: 44px;
    }

    .btn-sm {
        min-height: 38px;
    }

    /* Filter zusammenklappbar */
    .filter-toggle {
        display: flex;
        width: 100%;
        margin-bottom: 0.75rem;
    }

    .filter-bar[hidden] {
        display: none;
    }

    /* Tabellen auf Karten umstellen */
    .table-responsive table.data-table,
    .table-responsive table.data-table tbody,
    .table-responsive table.data-table tr,
    .table-responsive table.data-table td {
        display: block;
        width: 100%;
    }

    .table-responsive table.data-table thead {
        display: none;
    }

    .table-responsive table.data-table tr {
        border-bottom: 1px solid var(--color-border);
        padding: 0.6rem 0;
    }

    .table-responsive table.data-table td {
        border: none;
        padding: 0.2rem 1rem;
        display: flex;
        gap: 0.75rem;
        justify-content: space-between;
        align-items: baseline;
    }

    .table-responsive table.data-table td::before {
        content: attr(data-label);
        font-size: var(--font-size-xs);
        text-transform: uppercase;
        letter-spacing: 0.03em;
        color: var(--color-muted);
        font-weight: 600;
        flex-shrink: 0;
    }

    .table-responsive table.data-table td.cell-actions {
        justify-content: flex-end;
        padding-top: 0.5rem;
    }

    .table-responsive table.data-table td.cell-actions::before {
        content: "";
    }

    .detail-list {
        grid-template-columns: 1fr;
    }
}

/* Druckausgabe */
@media print {
    .app-sidebar,
    .app-topbar,
    .mobile-nav,
    .page-actions,
    .filter-bar,
    .btn {
        display: none !important;
    }

    .app-main { margin-left: 0; }
    .app-content { padding: 0; }
    body { background: #fff; }
    .content-card { break-inside: avoid; }
}

/* Bewegungsreduktion respektieren */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}
