:root {
    --bg: #f3f5f9;
    --card-bg: #ffffff;
    --surface: #f8fafc;
    --border: #e2e8f0;
    --primary: #2563eb;
    --primary-hover: #1e4fc7;
    --primary-soft: rgba(37, 99, 235, 0.10);
    --text: #1f2937;
    --text-light: #64748b;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 4px 14px rgba(15, 23, 42, 0.06);
    --shadow-hover: 0 2px 4px rgba(15, 23, 42, 0.06), 0 10px 24px rgba(15, 23, 42, 0.10);

    --offen: #dc2626;
    --offen-bg: #fee2e2;
    --offen-fg: #991b1b;
    --bearbeitung: #b45309;
    --bearbeitung-bg: #fef3c7;
    --bearbeitung-fg: #92400e;
    --wartet: #2563eb;
    --wartet-bg: #dbeafe;
    --wartet-fg: #1e40af;
    --erledigt: #047857;
    --erledigt-bg: #d1fae5;
    --erledigt-fg: #065f46;
}

:root.dark {
    --bg: #0f1115;
    --card-bg: #1a1d23;
    --surface: #22262e;
    --border: #2d323c;
    --text: #e5e7eb;
    --text-light: #9ca3af;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-soft: rgba(59, 130, 246, 0.18);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-hover: 0 6px 18px rgba(0, 0, 0, 0.5);

    --offen-bg: rgba(220, 38, 38, 0.20);
    --offen-fg: #fca5a5;
    --bearbeitung-bg: rgba(217, 119, 6, 0.22);
    --bearbeitung-fg: #fcd34d;
    --wartet-bg: rgba(37, 99, 235, 0.25);
    --wartet-fg: #93c5fd;
    --erledigt-bg: rgba(5, 150, 105, 0.22);
    --erledigt-fg: #6ee7b7;
}

@media (prefers-color-scheme: dark) {
    :root:not(.light) {
        --bg: #0f1115;
        --card-bg: #1a1d23;
        --surface: #22262e;
        --border: #2d323c;
        --text: #e5e7eb;
        --text-light: #9ca3af;
        --primary: #3b82f6;
        --primary-hover: #60a5fa;
        --primary-soft: rgba(59, 130, 246, 0.18);
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow-hover: 0 6px 18px rgba(0, 0, 0, 0.5);

        --offen-bg: rgba(220, 38, 38, 0.20);
        --offen-fg: #fca5a5;
        --bearbeitung-bg: rgba(217, 119, 6, 0.22);
        --bearbeitung-fg: #fcd34d;
        --wartet-bg: rgba(37, 99, 235, 0.25);
        --wartet-fg: #93c5fd;
        --erledigt-bg: rgba(5, 150, 105, 0.22);
        --erledigt-fg: #6ee7b7;
    }
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

a {
    color: var(--primary);
}

h1, h2, h3 {
    line-height: 1.25;
}

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

.container {
    max-width: 1000px;
    margin: 2rem auto;
    padding: 0 1rem;
}

/* Kopfzeile und Navigation */

header {
    background: var(--card-bg);
    padding: .75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
}

header h1 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -.01em;
}

.brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    flex-shrink: 0;
    color: inherit;
    text-decoration: none;
}

.brand img {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.brand h1 {
    white-space: nowrap;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: .25rem;
    margin-left: auto;
}

.main-nav a {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem .6rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-light);
    font-weight: 500;
    font-size: .95rem;
    white-space: nowrap;
    transition: background .15s, color .15s;
}

.main-nav a svg,
.icon-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.main-nav a:hover {
    background: var(--primary-soft);
    color: var(--primary);
}

.main-nav a[aria-current="page"] {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: .4rem;
    flex-shrink: 0;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin: 0;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-light);
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, color .15s;
}

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

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

/* Karten */

.card {
    background: var(--card-bg);
    padding: 1.5rem 1.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.card > h2:first-child {
    margin-top: 0;
}

.card h2 {
    font-size: 1.15rem;
    margin: 0 0 .9rem 0;
}

.card > :last-child {
    margin-bottom: 0;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.card.stat {
    --accent: var(--primary);
    position: relative;
    overflow: hidden;
    margin-bottom: 0;
    text-align: center;
    padding: 1.4rem .5rem 1.2rem;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 110px;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}

.card.stat::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 4px;
    background: var(--accent);
}

.card.stat h2 {
    margin: 0;
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.card.stat p {
    margin: .3rem 0 0 0;
    color: var(--text-light);
    font-size: .9rem;
    font-weight: 500;
}

.card.stat.stat-heute { --accent: #7c3aed; }
.card.stat.stat-offen { --accent: var(--offen); }
.card.stat.stat-bearbeitung { --accent: #d97706; }
.card.stat.stat-wartet { --accent: var(--wartet); }
.card.stat.stat-erledigt { --accent: #059669; }

.card.stat:hover,
.card.stat:focus-visible {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
    border-color: var(--accent);
    outline: none;
}

.card.stat.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent);
}

/* Formulare */

form label {
    display: block;
    margin-bottom: .9rem;
    font-weight: 600;
    font-size: .95rem;
}

form label > input,
form label > textarea,
form label > select {
    margin-top: .4rem;
}

input[type="text"],
input[type="date"],
input[type="password"],
input[type="file"],
textarea,
select {
    width: 100%;
    min-height: 46px;
    padding: .7rem .8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    background: var(--card-bg);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}

textarea {
    resize: vertical;
    line-height: 1.5;
}

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

input[readonly] {
    background: var(--surface);
    color: var(--text-light);
}

input[type="file"] {
    padding: .45rem;
    background: var(--surface);
    border-style: dashed;
}

input[type="file"]::file-selector-button {
    margin-right: .75rem;
    padding: .5rem .9rem;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary-soft);
    color: var(--primary);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

button {
    background: var(--primary);
    color: #fff;
    border: none;
    min-height: 46px;
    padding: .7rem 1.3rem;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: .5rem;
    transition: background .2s, filter .2s, transform .1s;
}

button:hover {
    background: var(--primary-hover);
}

button:active {
    transform: scale(.98);
}

.alert,
.error {
    margin: 0 0 1rem 0;
    padding: .8rem 1rem;
    border-radius: var(--radius-sm);
    background: var(--offen-bg);
    color: var(--offen-fg);
    font-weight: 500;
}

/* Ticketlisten */

.ticket-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.ticket-list li {
    margin-bottom: .7rem;
}

.ticket-list li:last-child {
    margin-bottom: 0;
}

.empty {
    color: var(--text-light);
    text-align: center;
    padding: 1.5rem 1rem;
}

.ticket-card {
    --accent: var(--primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    min-height: 64px;
    background: var(--card-bg);
    padding: .85rem 1rem;
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    color: inherit;
    text-decoration: none;
    transition: transform .15s ease, box-shadow .15s ease;
}

.ticket-card.offen { --accent: var(--offen); }
.ticket-card.bearbeitung { --accent: #d97706; }
.ticket-card.wartet { --accent: var(--wartet); }
.ticket-card.erledigt { --accent: #059669; }

/* Liste innerhalb einer Karte: flacher, damit nicht Karte in Karte entsteht */
.card .ticket-card {
    background: var(--surface);
    box-shadow: none;
}

.ticket-card:hover,
.ticket-card:focus-visible {
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
}

.ticket-card > div:first-child,
.ticket-card-content > div:first-child {
    min-width: 0;
}

.ticket-card-title {
    font-weight: 600;
    margin-bottom: .15rem;
    overflow-wrap: anywhere;
}

.ticket-card-date {
    color: var(--text-light);
    font-size: .875rem;
}

.ticket-card-compact {
    display: block;
}

.ticket-card-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.badge {
    display: inline-block;
    flex-shrink: 0;
    padding: .25rem .7rem;
    border-radius: 999px;
    font-size: .8rem;
    font-weight: 600;
    white-space: nowrap;
    text-transform: capitalize;
    background: var(--surface);
    color: var(--text-light);
}

.badge.offen { background: var(--offen-bg); color: var(--offen-fg); }
.badge.bearbeitung { background: var(--bearbeitung-bg); color: var(--bearbeitung-fg); }
.badge.wartet { background: var(--wartet-bg); color: var(--wartet-fg); }
.badge.erledigt { background: var(--erledigt-bg); color: var(--erledigt-fg); }

/* Ticket-Detail */

.ticket-head .badge {
    margin-bottom: .6rem;
}

.ticket-head h2 {
    font-size: 1.35rem;
    margin-bottom: .75rem;
    overflow-wrap: anywhere;
}

.ticket-meta {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem 1.5rem;
    margin: 0 0 1rem 0;
    color: var(--text-light);
    font-size: .925rem;
}

.ticket-meta strong {
    color: var(--text);
    font-weight: 600;
}

.ticket-description {
    margin: 0;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    overflow-wrap: anywhere;
}

.gallery-thumbs {
    display: flex;
    flex-wrap: wrap;
    gap: .7rem;
}

.gallery-thumbs a {
    display: block;
    line-height: 0;
}

.gallery-thumbs p {
    margin: 0;
    color: var(--text-light);
}

.ticket-image-thumb {
    width: 200px;
    max-width: 100%;
    height: 200px;
    object-fit: cover;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.comment-list {
    list-style: none;
    margin: 0 0 1.25rem 0;
    padding: 0;
}

.comment-list li {
    background: var(--surface);
    padding: .8rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: .6rem;
    overflow-wrap: anywhere;
}

.comment-list li strong {
    font-size: .875rem;
    color: var(--text-light);
}

.filter-form {
    display: flex;
    gap: .7rem;
    flex-wrap: wrap;
}

.filter-form input[type="text"] {
    flex: 2 1 220px;
}

.filter-form select {
    flex: 1 1 150px;
}

.filter-form button {
    margin-top: 0;
}

.status-form {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .6rem;
}

.status-form button {
    margin-top: 0;
    padding-left: .5rem;
    padding-right: .5rem;
}

.status-form .status-btn {
    color: #fff;
    border: none;
}

.status-form .status-offen {
    background: var(--offen);
}

.status-form .status-bearbeitung {
    background: var(--bearbeitung);
}

.status-form .status-wartet {
    background: #2563eb;
}

.status-form .status-erledigt {
    background: var(--erledigt);
}

.status-form .status-btn:hover {
    filter: brightness(0.92);
}

.status-form .status-btn.current {
    box-shadow: 0 0 0 2px var(--card-bg), 0 0 0 4px var(--text);
}

.danger-zone p {
    color: var(--text-light);
}

.delete-btn {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.delete-btn:hover {
    background: var(--danger);
    color: #fff;
}

.ticket-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 820px;
    margin-right: auto;
}

.ticket-form label {
    margin-bottom: 0;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem 1.25rem;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: .4rem;
}

.form-field small {
    color: var(--text-light);
    line-height: 1.4;
}

/* Login */

.login-page {
    max-width: 400px;
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 1.5rem 1rem;
}

.login-brand {
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-brand img {
    width: 64px;
    height: 64px;
    border-radius: 16px;
}

.login-brand h1 {
    margin: .75rem 0 0 0;
    font-size: 1.5rem;
}

.login-page button {
    width: 100%;
}

/* Handy: Navigation als Leiste am unteren Rand, mit dem Daumen erreichbar */

@media (max-width: 1000px) {
    body {
        padding-bottom: calc(68px + env(safe-area-inset-bottom));
    }

    body.login-body {
        padding-bottom: 0;
    }

    .container {
        margin: .75rem auto;
        padding: 0 .75rem;
    }

    header {
        padding: .5rem .5rem .5rem .75rem;
        margin-bottom: .75rem;
    }

    header h1 {
        font-size: 1.1rem;
    }

    /* Langer Programmname: schrumpfen und notfalls umbrechen statt abschneiden */
    .brand {
        flex-shrink: 1;
        min-width: 0;
    }

    .brand h1 {
        min-width: 0;
        white-space: normal;
        overflow-wrap: anywhere;
        hyphens: auto;
    }

    .main-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 100;
        margin: 0;
        gap: 0;
        padding: .3rem .25rem calc(.3rem + env(safe-area-inset-bottom));
        background: var(--card-bg);
        border-top: 1px solid var(--border);
        box-shadow: 0 -2px 12px rgba(15, 23, 42, 0.08);
    }

    .main-nav a {
        flex: 1 1 0;
        flex-direction: column;
        justify-content: center;
        gap: .15rem;
        min-height: 56px;
        padding: .3rem .2rem;
        font-size: .72rem;
    }

    .main-nav a svg {
        width: 24px;
        height: 24px;
    }

    .card {
        padding: 1rem;
        margin-bottom: .75rem;
    }

    .card-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: .5rem;
        margin-bottom: .75rem;
    }

    .card.stat {
        padding: .9rem .35rem .7rem;
        min-height: 84px;
        justify-content: flex-start;
    }

    .card.stat h2 {
        font-size: 1.5rem;
    }

    .card.stat p {
        font-size: .76rem;
        line-height: 1.25;
    }

    input[type="text"],
    input[type="date"],
    input[type="password"],
    input[type="file"],
    textarea,
    select,
    button {
        font-size: 16px;
    }

    input[type="text"],
    input[type="date"],
    input[type="password"],
    select,
    button {
        min-height: 48px;
    }

    form button,
    .filter-form button {
        width: 100%;
    }

    .filter-form {
        flex-direction: column;
    }

    .filter-form input[type="text"],
    .filter-form select {
        flex: none;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .status-form {
        grid-template-columns: 1fr 1fr;
    }

    .status-form button {
        min-height: 52px;
    }

    .ticket-card {
        padding: .8rem .85rem;
        gap: .6rem;
    }

    .ticket-card-content {
        gap: .6rem;
    }

    .gallery-thumbs a {
        width: 100%;
    }

    .ticket-image-thumb {
        width: 100%;
        height: auto;
        max-height: 280px;
    }
}

/* Schmale Handys: Logo weglassen, damit der Programmname in eine Zeile passt */
@media (max-width: 420px) {
    .brand img {
        display: none;
    }

    header h1 {
        font-size: 1.05rem;
    }

    .header-actions {
        gap: .3rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
    }
}
