/* Status colors follow the customer-visible group; text labels carry the meaning. */
:root {
    --status-new-bg: #dbeafe;
    --status-new-fg: #1e40af;
    --status-needs-info-bg: #fef3c7;
    --status-needs-info-fg: #92400e;
    --status-in-progress-bg: #ede9fe;
    --status-in-progress-fg: #5b21b6;
    --status-resolved-bg: #dcfce7;
    --status-resolved-fg: #166534;
    --status-closed-bg: #e5e7eb;
    --status-closed-fg: #374151;
    --notice-error-bg: #fee2e2;
    --notice-error-fg: #991b1b;
}
/* Pico switches to dark mode with the OS setting; keep badges readable there too. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --status-new-bg: rgba(59, 130, 246, 0.2);
        --status-new-fg: #93c5fd;
        --status-needs-info-bg: rgba(245, 158, 11, 0.2);
        --status-needs-info-fg: #fcd34d;
        --status-in-progress-bg: rgba(139, 92, 246, 0.2);
        --status-in-progress-fg: #c4b5fd;
        --status-resolved-bg: rgba(34, 197, 94, 0.2);
        --status-resolved-fg: #86efac;
        --status-closed-bg: rgba(156, 163, 175, 0.2);
        --status-closed-fg: #d1d5db;
        --notice-error-bg: rgba(239, 68, 68, 0.2);
        --notice-error-fg: #fca5a5;
    }
}

.muted {
    color: var(--pico-muted-color);
}
.nowrap {
    white-space: nowrap;
}

/* Header: product name left, user and logout right. */
body > header.app-header {
    padding-block: 0;
    border-bottom: var(--pico-border-width) solid var(--pico-muted-border-color);
}
.app-header nav {
    flex-wrap: wrap;
}
.app-brand {
    font-weight: 700;
    color: var(--pico-color);
}
.app-user {
    color: var(--pico-muted-color);
}
.app-header form {
    margin: 0;
}
.app-header button {
    width: auto;
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
}
.app-wide {
    max-width: 1600px;
}

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    margin-bottom: var(--pico-spacing);
}
.page-head h1 {
    margin-bottom: 0;
}
.back-link {
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

/* Tabs for quick filters and customer list tabs; the current one is underlined. */
nav.tabs {
    flex-wrap: wrap;
    justify-content: flex-start;
    column-gap: 1.5rem;
    margin-bottom: var(--pico-spacing);
    border-bottom: var(--pico-border-width) solid var(--pico-muted-border-color);
}
nav.tabs a {
    margin-bottom: calc(var(--pico-border-width) * -1);
    padding-block: 0.5rem;
    border-bottom: 0.125rem solid transparent;
    color: var(--pico-muted-color);
    text-decoration: none;
}
nav.tabs a:hover {
    color: var(--pico-primary);
}
nav.tabs a[aria-current="page"] {
    border-bottom-color: var(--pico-primary);
    color: var(--pico-primary);
    font-weight: 600;
}

/* Staff filters in one row; every control keeps Pico's bottom spacing for alignment. */
.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    column-gap: var(--pico-spacing);
}
.filters > * {
    flex: 1 1 9rem;
    min-width: 0;
    margin-bottom: 0;
}
.filters legend {
    margin-bottom: calc(var(--pico-spacing) * 0.25);
}
.filters .filter-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: var(--pico-spacing);
    padding-bottom: var(--pico-spacing);
}
.filters .filter-actions button {
    width: auto;
    margin-bottom: 0;
}
/* Without Pico's click-catching overlay, "Filtern" submits on the first click; app.js closes the dropdown. */
.filters details.dropdown[open] > summary::before {
    display: none;
}

/* Ticket tables: compact cells so all columns fit without horizontal scrolling. */
.ticket-table :is(th, td) {
    padding-inline: 0.5rem;
    vertical-align: middle;
}
.ticket-table .ticket-title {
    color: var(--pico-color);
    text-decoration: none;
}
.ticket-table .ticket-title:hover {
    color: var(--pico-primary);
    text-decoration: underline;
}

.badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 1rem;
    background-color: var(--status-closed-bg);
    color: var(--status-closed-fg);
    font-size: 0.875em;
    line-height: 1.4;
    white-space: nowrap;
}
.status-new {
    background-color: var(--status-new-bg);
    color: var(--status-new-fg);
}
.status-needs_info {
    background-color: var(--status-needs-info-bg);
    color: var(--status-needs-info-fg);
}
.status-in_progress {
    background-color: var(--status-in-progress-bg);
    color: var(--status-in-progress-fg);
}
.status-resolved {
    background-color: var(--status-resolved-bg);
    color: var(--status-resolved-fg);
}
.status-closed {
    background-color: var(--status-closed-bg);
    color: var(--status-closed-fg);
}

/* Mark required customer replies with a border and a label, not color alone.
   Selectors match Pico's striped rows in specificity so the highlight wins by order. */
table.striped tbody tr.ticket-needs-info td {
    background-color: var(--status-needs-info-bg);
}
table.striped tbody tr.ticket-needs-info td:first-child {
    border-inline-start: 0.25rem solid var(--status-needs-info-fg);
}
table.ticket-table tbody tr:hover td {
    background-color: color-mix(in srgb, var(--pico-primary) 8%, var(--pico-background-color));
}

.notice {
    padding: 0.75rem 1rem;
    border-inline-start: 0.25rem solid;
    border-radius: var(--pico-border-radius);
}
.notice-success {
    background-color: var(--status-resolved-bg);
    color: var(--status-resolved-fg);
}
.notice-error {
    background-color: var(--notice-error-bg);
    color: var(--notice-error-fg);
}

.ticket-number {
    color: var(--pico-muted-color);
    font-weight: 400;
}
.ticket-details {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: 0.25rem 1rem;
}
.ticket-details dt {
    color: var(--pico-muted-color);
    font-weight: 400;
}
.ticket-details dd {
    margin: 0;
    overflow-wrap: anywhere;
}

/* Staff ticket page: sidebar with controls; below the heading on narrow screens. */
.ticket-layout h2 {
    font-size: 1.125rem;
}
.ticket-sidebar .assign-me {
    width: auto;
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
}
.ticket-sidebar [role="group"] button {
    flex: 0 0 auto;
    --pico-form-element-spacing-horizontal: 1rem;
}
/* Every save swaps the panel, so it holds only the heading and the sidebar. display: contents
   makes both cells of the page grid, next to the description and comments outside the panel. */
@media (min-width: 1024px) {
    .ticket-layout {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 26rem;
        column-gap: 2rem;
        align-items: start;
    }
    #support-ticket-panel {
        display: contents;
    }
    .ticket-head {
        grid-column: 1 / -1;
        grid-row: 1;
    }
    .ticket-main {
        grid-column: 1;
        grid-row: 2;
        /* Same offset as the sidebar card's padding, so both first headings line up. */
        padding-top: var(--pico-block-spacing-vertical);
    }
    .ticket-sidebar {
        grid-column: 2;
        grid-row: 2;
    }
}

/* Preserve entered line breaks without bypassing HTML escaping. */
.ticket-description,
.comment-body {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* A thin line separates the sections below the description, as in the file list. */
.comments,
.attachments {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: var(--pico-border-width) solid var(--pico-muted-border-color);
}
/* File list: one row per file, the delete button at the end of the row. */
.attachment-list {
    padding-left: 0;
}
.attachment-list li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.5rem;
    padding-block: 0.375rem;
    border-bottom: var(--pico-border-width) solid var(--pico-muted-border-color);
    list-style: none;
    overflow-wrap: anywhere;
}
/* The collapsed player takes its own row below the file's line. */
.attachment-player {
    flex: 0 0 100%;
    margin: 0;
}
.attachment-video {
    display: block;
    width: 100%;
    max-width: 32rem;
    max-height: 20rem;
    background-color: #000;
}
.attachments form button {
    width: auto;
}
/* Own line without a <br>: the ticket test rejects that tag anywhere on the page. */
.upload-warning {
    display: block;
}
/* Upload form and video players open on demand; the summary reads like a link, with Pico's chevron next to it. */
.attachment-upload summary,
.attachment-player summary {
    display: inline-block;
}
/* Pico colors summaries with more specific selectors, also when open; match them to keep the link color. */
:is(.attachment-upload, .attachment-player) > summary:not([role]),
:is(.attachment-upload, .attachment-player)[open] > summary:not([role]):not(:focus) {
    color: var(--pico-primary);
}
.attachment-delete {
    margin: 0 0 0 auto;
}
.attachment-delete button {
    margin: 0;
    padding: 0.125rem 0.5rem;
    font-size: 0.875rem;
}
.comment header {
    font-size: 0.875rem;
}
/* Internal notes: tint, border and an "Intern" label, not color alone. */
.comment-internal {
    --pico-card-background-color: var(--status-needs-info-bg);
    --pico-card-sectioning-background-color: transparent;
    border-inline-start: 0.25rem solid var(--status-needs-info-fg);
}
.comment-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--pico-spacing);
}
.comment-actions button {
    width: auto;
}

.login-card {
    max-width: 26rem;
    margin: 2rem auto;
}
