/* ============================================================
   VARIABLEN & RESET
   ============================================================ */
:root {
    --bg: #f7f5f0;
    --bg-soft: #ffffff;
    --bg-softer: #fbfaf7;
    --border: #e7e1d8;

    --text: #1f2937;
    --text-muted: #6b7280;
    --text-soft: #4b5563;

    --accent-yellow: #d9a400;
    --accent-yellow-strong: #b88200;
    --accent-yellow-soft: rgba(217, 164, 0, 0.12);

    --accent-red: #b0453c;
    --accent-red-strong: #8f352e;
    --accent-red-soft: rgba(176, 69, 60, 0.12);

    --accent: var(--accent-yellow);
    --accent-soft: var(--accent-yellow-soft);
    --accent-strong: var(--accent-yellow-strong);

    --danger: var(--accent-red);
    --danger-soft: var(--accent-red-soft);

    --radius: 0.75rem;
    --radius-lg: 1.1rem;

    --shadow-soft: 0 8px 24px rgba(31, 41, 55, 0.06);
    --shadow-strong: 0 18px 45px rgba(31, 41, 55, 0.08);

    /* Topbar-Höhe für sticky-offset-Berechnungen */
    --topbar-h: 52px;
}

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

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

body {
    min-height: 100dvh;
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: radial-gradient(circle at top left, #fbfaf7, #f7f5f0 55%, #ece6dc 100%);
    line-height: 1.5;
}

a {
    color: inherit;
    text-decoration: none;
}

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

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

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.92em;
    color: #7a4f00;
    background: rgba(217, 164, 0, 0.08);
    padding: 0.08rem 0.35rem;
    border-radius: 0.35rem;
}

:focus-visible {
    outline: 2px solid rgba(217, 164, 0, 0.55);
    outline-offset: 2px;
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.6rem 1.25rem;
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(10px);
    min-height: var(--topbar-h);
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* Topbar-left darf wachsen, right bleibt kompakt */
.topbar-left {
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: wrap;
}

.logo {
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-size: 0.84rem;
    padding: 0.32rem 0.8rem;
    border-radius: 999px;
    border: 1px solid rgba(184, 130, 0, 0.18);
    color: #5d4a1f;
    background: radial-gradient(circle at top left, rgba(217, 164, 0, 0.16), transparent 58%), #fffdfa;
    white-space: nowrap;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    font-size: 0.9rem;
}

.nav-link {
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    color: var(--text-muted);
    border: 1px solid transparent;
    transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
    white-space: nowrap;
}

.nav-link:hover {
    background: rgba(107, 114, 128, 0.08);
    color: var(--text);
}

.nav-link-active {
    background: var(--accent-soft);
    border-color: rgba(217, 164, 0, 0.4);
    color: var(--text);
}

.user-chip {
    font-size: 0.82rem;
    padding: 0.28rem 0.75rem;
    border-radius: 999px;
    background: #fffdfa;
    border: 1px solid var(--border);
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    padding: 0.42rem 0.95rem;
    border-radius: 999px;
    border: 1px solid transparent;
    cursor: pointer;
    background: transparent;
    color: var(--text);
    transition: background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, transform 0.08s ease, color 0.18s ease;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: linear-gradient(135deg, #f5d56a, var(--accent-yellow));
    border-color: rgba(184, 130, 0, 0.35);
    color: #3f3210;
    box-shadow: 0 8px 20px rgba(217, 164, 0, 0.22);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #f1cf57, var(--accent-yellow-strong));
}

.btn-ghost {
    border-color: var(--border);
    background: #ffffff;
    color: var(--text);
}

.btn-ghost:hover {
    background: #faf8f3;
}

.btn-small {
    padding: 0.3rem 0.7rem;
    font-size: 0.78rem;
}

.btn-danger {
    border-color: rgba(176, 69, 60, 0.28);
    background: var(--danger-soft);
    color: #7c2d28;
}

.btn-danger:hover {
    background: rgba(176, 69, 60, 0.18);
}

/* ============================================================
   SEITEN-LAYOUT
   .page        → zentriert, max 1100px (z.B. Login, kleine Seiten)
   .page-wide   → volle Browserbreite mit seitlichem Padding
   ============================================================ */
.page {
    max-width: 1100px;
    margin: 1.5rem auto 2.5rem;
    padding: 0 1.5rem;
}

/* Volle Breite für Tabellen- und Admin-Seiten */
.page.page-wide {
    max-width: 100%;
    width: 100%;
    margin: 1rem 0 2rem;
    padding: 0 1.5rem;
}

.page-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 2fr);
    gap: 1.5rem;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: linear-gradient(135deg, #ffffff, #fcfbf8);
    border-radius: 1.25rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-soft);
    padding: 1.25rem 1.5rem 1.5rem;
    position: relative;
    overflow: hidden;
}

.card::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 0% 0%, rgba(217, 164, 0, 0.16), transparent 70%);
    opacity: 0.7;
    pointer-events: none;
}

.card > * {
    position: relative;
    z-index: 1;
}

.card-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.card-title {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text);
}

.card-subtitle {
    margin-top: 0.25rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    border-radius: 0.8rem;
    padding: 0.65rem 0.85rem;
    font-size: 0.85rem;
    border: 1px solid transparent;
}

.alert-info {
    background: #fff8dc;
    border-color: rgba(217, 164, 0, 0.38);
    color: #6f5200;
}

.alert-error {
    background: rgba(176, 69, 60, 0.1);
    border-color: rgba(176, 69, 60, 0.32);
    color: #7c2d28;
}

/* ============================================================
   FORMULARE
   ============================================================ */
.form {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    margin-top: 0.75rem;
}

.form-inline {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.8rem 1rem;
}

.form-label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    min-width: 0;
}

.form-label-inline {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
}

.form-label-inline input[type="checkbox"],
.form-label-inline input[type="radio"] {
    margin: 0;
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

/* Basis-Input-Styles — ein einziger Selektor-Block */
.form-input,
.search-input,
.column-filter,
.admin-filter,
.enum-textarea {
    border: 1px solid var(--border);
    color: var(--text);
    background: #ffffff;
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

/* Placeholder */
.form-input::placeholder,
.search-input::placeholder,
.column-filter::placeholder,
.admin-filter::placeholder,
.enum-textarea::placeholder {
    color: var(--text-muted);
}

/* Focus-State */
.form-input:focus,
.search-input:focus,
.column-filter:focus,
.admin-filter:focus,
.enum-textarea:focus {
    border-color: var(--accent);
    background: #fffdf6;
    box-shadow: 0 0 0 1px rgba(217, 164, 0, 0.34);
}

/* Runde Inputs */
.form-input,
.search-input {
    border-radius: 999px;
    padding: 0.48rem 0.95rem;
    font-size: 0.85rem;
}

textarea.form-input,
.enum-textarea {
    border-radius: 0.75rem;
}

.search-input {
    width: 100%;
    max-width: 300px;
}

/* ============================================================
   TABELLE
   ============================================================ */
.table-wrapper {
    margin-top: 0.75rem;
    border-radius: 0.95rem;
    border: 1px solid var(--border);
    background: #ffffff;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    /* Verhindert Bounce-Scrolling des Body beim Tabellen-Scrollen auf iOS */
    overscroll-behavior-x: contain;
}

.table-hint {
    display: none;
    font-size: 0.72rem;
    color: var(--text-muted);
    padding: 0.35rem 0.65rem 0;
}

.data-table {
    width: 100%;
    min-width: 700px;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.data-table thead {
    background: #faf8f3;
}

.data-table th,
.data-table td {
    padding: 0.62rem 0.85rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.data-table th {
    font-weight: 600;
    font-size: 0.79rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    user-select: none;
}

.data-table thead tr:first-child th {
    cursor: pointer;
}

.data-table thead tr:first-child th:hover {
    background: rgba(217, 164, 0, 0.06);
}

.data-table tbody tr:nth-child(even) {
    background: #fcfbf8;
}

.data-table tbody tr:hover {
    background: #fff9e8;
}

.data-table td code {
    color: #7a4f00;
}

.data-table .column-filter {
    width: 100%;
    border-radius: 999px;
    padding: 0.22rem 0.58rem;
    font-size: 0.74rem;
}

.data-table .filter-row th {
    padding-top: 0.35rem;
    padding-bottom: 0.45rem;
}

.data-table .col-id {
    width: 1%;
    white-space: nowrap;
    text-align: right;
    padding-right: 0.6rem;
    font-variant-numeric: tabular-nums;
}

/* Rollenbasierte Spalten-Sichtbarkeit */
.role-hide-id .col-id {
    display: none;
}

.role-limited .col-abteilung,
.role-limited .col-ordner,
.role-limited .col-vermisst,
.role-limited .col-kommentar {
    display: none;
}

/* ============================================================
   ENUM-TEXTAREA
   ============================================================ */
.enum-textarea {
    width: 100%;
    border-radius: 0.8rem;
    padding: 0.8rem 0.9rem;
    font-size: 0.86rem;
    resize: vertical;
    min-height: 10rem;
    line-height: 1.45;
}

/* ============================================================
   AUTH / LOGIN
   ============================================================ */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 2rem 1rem;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    padding: 2rem 2.1rem;
    border-radius: 1.25rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-strong);
    background:
        radial-gradient(circle at 0% -20%, rgba(217, 164, 0, 0.22), transparent 60%),
        radial-gradient(circle at 100% 130%, rgba(176, 69, 60, 0.12), transparent 50%),
        #ffffff;
}

.auth-card h1 {
    margin: 0 0 1.2rem;
    font-size: 1.35rem;
    color: var(--text);
}

/* ============================================================
   ADMIN-LAYOUT
   ============================================================ */
.admin-layout {
    display: grid;
    gap: 1.25rem;
}

.admin-create-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 0.9rem 1rem;
}

.span-12 { grid-column: span 12; }
.span-8  { grid-column: span 8; }
.span-6  { grid-column: span 6; }
.span-4  { grid-column: span 4; }
.span-3  { grid-column: span 3; }
.span-2  { grid-column: span 2; }

.admin-create-actions {
    display: flex;
    justify-content: flex-end;
}

.admin-toolbar {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 0.75rem;
    align-items: end;
}

.admin-toolbar .toolbar-search { grid-column: span 4; }
.admin-toolbar .toolbar-filter { grid-column: span 2; }

/* Karten-Grid: passt sich an verfügbare Breite an */
.admin-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr));
    gap: 1rem;
}

/* ============================================================
   NOTEN-CARDS (Admin)
   ============================================================ */
.note-card {
    border: 1px solid var(--border);
    border-radius: 1rem;
    background: linear-gradient(135deg, #ffffff, #fcfbf8);
    box-shadow: var(--shadow-soft);
    overflow: hidden;
}

.note-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    background: #faf8f3;
}

.note-card-head-main {
    min-width: 0;
    flex: 1 1 auto;
}

.note-id-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 3.2rem;
    padding: 0.28rem 0.6rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    background: #fffdfa;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.note-title-preview {
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.note-subtitle {
    margin-top: 0.2rem;
}

.note-card-body {
    padding: 1rem;
}

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

.note-form-grid .field-titel       { grid-column: span 12; }
.note-form-grid .field-komponist   { grid-column: span 6; }
.note-form-grid .field-arrangement { grid-column: span 6; }
.note-form-grid .field-verlag      { grid-column: span 6; }
.note-form-grid .field-abteilung   { grid-column: span 6; }
.note-form-grid .field-kommentar   { grid-column: span 12; }

.note-flags {
    grid-column: span 12;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}

.note-actions {
    grid-column: span 12;
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: flex-end;
    padding-top: 0.25rem;
    border-top: 1px solid var(--border);
    margin-top: 0.25rem;
}

/* ============================================================
   HILFKLASSEN
   ============================================================ */
.empty-state-admin {
    padding: 1.25rem;
    border: 1px dashed var(--border);
    border-radius: 1rem;
    color: var(--text-muted);
    background: #fffdfa;
}

.actions-cell {
    white-space: nowrap;
}

.hidden {
    display: none !important;
}

/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */

/* ── 1100px: Zweispalten-Grid → einspaltig ── */
@media (max-width: 1100px) {
    .page-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* ── 980px: Admin-Toolbar anpassen ── */
@media (max-width: 980px) {
    .admin-toolbar .toolbar-search { grid-column: span 12; }
    .admin-toolbar .toolbar-filter { grid-column: span 4; }
}

/* ── 820px: Allgemeine Mobile-Anpassungen ── */
@media (max-width: 820px) {
    .page,
    .page.page-wide {
        padding: 0 0.85rem;
        margin-top: 1rem;
    }

    .card {
        padding: 1rem 1rem 1.15rem;
    }

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

    .card-header .search-input {
        max-width: 100%;
    }

    .admin-cards {
        grid-template-columns: 1fr;
    }

    .span-8,
    .span-6,
    .span-4,
    .span-3,
    .span-2 {
        grid-column: span 12;
    }
}

/* ── 640px: Formular- und Toolbar-Anpassungen ── */
@media (max-width: 640px) {
    .note-form-grid .field-komponist,
    .note-form-grid .field-arrangement,
    .note-form-grid .field-verlag,
    .note-form-grid .field-abteilung {
        grid-column: span 12;
    }

    .admin-toolbar .toolbar-filter { grid-column: span 6; }

    .note-card-head {
        flex-wrap: wrap;
    }

    .note-actions {
        justify-content: stretch;
    }

    .note-actions .btn {
        flex: 1 1 auto;
        min-width: 0;
        text-align: center;
    }
}

/* ── 600px: Topbar mobile ── */
@media (max-width: 600px) {
    :root {
        --topbar-h: auto;
    }

    .topbar {
        flex-wrap: wrap;
        gap: 0.4rem;
        padding: 0.55rem 0.85rem;
    }

    .topbar-left,
    .topbar-right {
        width: 100%;
        gap: 0.5rem;
    }

    .topbar-right {
        justify-content: space-between;
    }

    .user-chip {
        max-width: none;
        flex: 1 1 auto;
    }

    .nav-link {
        padding: 0.28rem 0.65rem;
        font-size: 0.8rem;
    }

    .page,
    .page.page-wide {
        padding: 0 0.65rem;
        margin: 0.75rem 0 1.4rem;
    }

    .card-title {
        font-size: 1.05rem;
    }

    .card-subtitle {
        font-size: 0.82rem;
    }

    .data-table {
        min-width: 600px;
        font-size: 0.8rem;
    }

    .data-table th,
    .data-table td {
        padding: 0.42rem 0.55rem;
    }

    .data-table .column-filter {
        font-size: 0.7rem;
        padding: 0.16rem 0.45rem;
    }

    .table-hint {
        display: block;
    }

    .auth-card {
        padding: 1.5rem 1.2rem;
    }

    .search-input {
        max-width: 100%;
    }
}

/* ── 480px: Sehr kleine Screens ── */
@media (max-width: 480px) {
    .data-table {
        min-width: 560px;
    }

    .btn {
        font-size: 0.8rem;
    }
}
