:root {
    --bg: #0a0f14;
    --bg-elevated: #111820;
    --bg-card: #151d27;
    --border: rgba(255, 255, 255, .08);
    --text: #f4f6f8;
    --muted: #9aa5b1;
    --gold: #d6a14a;
    --gold-light: #f0c06a;
    --danger: #e85d5d;
    --radius: 10px;
    --font: "Plus Jakarta Sans", system-ui, sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

body.sidebar-open {
    overflow: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

/* Login */
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(400px, 100%);
    padding: 40px 36px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 4px);
    text-align: center;
}

.login-logo {
    height: 72px;
    width: auto;
    margin: 0 auto 24px;
}

.login-card h1 {
    margin: 0 0 8px;
    font-size: 1.5rem;
}

.login-sub {
    margin: 0 0 28px;
    color: var(--muted);
    font-size: .92rem;
}

.login-card label {
    display: block;
    text-align: left;
    margin-bottom: 6px;
    font-size: .82rem;
    font-weight: 600;
    color: var(--muted);
}

.login-card input {
    width: 100%;
    margin-bottom: 16px;
    padding: 12px 14px;
    background: rgba(0, 0, 0, .25);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    outline: none;
}

.login-card input:focus {
    border-color: var(--gold);
}

.back-link {
    display: inline-block;
    margin-top: 20px;
    font-size: .88rem;
    color: var(--muted);
}

.back-link:hover {
    color: var(--gold-light);
}

/* Admin layout */
.admin-page {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
}

.sidebar-logo img {
    height: 56px;
    width: auto;
    margin: 0 auto 32px;
    display: block;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.nav-item {
    padding: 12px 14px;
    background: transparent;
    border: 0;
    border-radius: var(--radius);
    color: var(--muted);
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: background .2s, color .2s;
}

.nav-item:hover,
.nav-item.active {
    background: rgba(214, 161, 74, .12);
    color: var(--gold-light);
}

.sidebar-foot {
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.user-badge {
    margin: 0 0 10px;
    font-size: .82rem;
    color: var(--muted);
}

.admin-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.admin-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 24px 32px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.topbar-start {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
    flex: 1;
}

.admin-menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    cursor: pointer;
    flex-shrink: 0;
}

.admin-menu-toggle span {
    display: block;
    width: 18px;
    height: 2px;
    margin: 0 auto;
    background: var(--text);
    border-radius: 2px;
    transition: transform .2s, opacity .2s;
}

.admin-menu-toggle[aria-expanded="true"] span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.admin-menu-toggle[aria-expanded="true"] span:nth-child(2) {
    opacity: 0;
}

.admin-menu-toggle[aria-expanded="true"] span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.sidebar-backdrop {
    display: none;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.admin-topbar h1 {
    margin: 0;
    font-size: 1.5rem;
    line-height: 1.2;
    min-width: 0;
}

.admin-content {
    padding: 28px 32px 40px;
    flex: 1;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: 999px;
    font-size: .88rem;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: transform .15s, background .15s, border-color .15s;
}

.btn-primary {
    background: var(--gold);
    color: #fff;
    width: 100%;
}

.btn-primary:hover {
    background: #e0ae58;
    transform: translateY(-1px);
}

.topbar-actions .btn-primary {
    width: auto;
}

.btn-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}

.btn-ghost:hover {
    border-color: var(--gold);
    color: var(--gold-light);
}

.btn-sm {
    padding: 8px 14px;
    font-size: .8rem;
    width: 100%;
}

.btn-danger {
    background: transparent;
    border-color: rgba(232, 93, 93, .4);
    color: var(--danger);
    padding: 6px 12px;
    font-size: .78rem;
}

.btn-danger:hover {
    background: rgba(232, 93, 93, .12);
}

.btn-edit {
    background: transparent;
    border-color: var(--border);
    color: var(--muted);
    padding: 6px 12px;
    font-size: .78rem;
    margin-right: 6px;
}

.btn-edit:hover {
    color: var(--text);
    border-color: var(--gold);
}

/* Table */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}

.data-table th,
.data-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    font-size: .75rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
    background: rgba(0, 0, 0, .2);
}

.data-table tr:last-child td {
    border-bottom: 0;
}

.data-table td:last-child {
    text-align: right;
    white-space: nowrap;
}

.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
}

.badge-published {
    background: rgba(74, 180, 110, .15);
    color: #6dd49a;
}

.badge-draft {
    background: rgba(154, 165, 177, .15);
    color: var(--muted);
}

.badge-admin {
    background: rgba(214, 161, 74, .15);
    color: var(--gold-light);
}

.badge-editor {
    background: rgba(100, 140, 200, .15);
    color: #8eb8f0;
}

.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 40px;
}

/* Form */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.span-2 {
    grid-column: span 2;
}

.form-field label {
    font-size: .82rem;
    font-weight: 600;
    color: var(--muted);
}

.form-field input,
.form-field select,
.form-field textarea {
    padding: 12px 14px;
    background: rgba(0, 0, 0, .25);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    outline: none;
    resize: vertical;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
    border-color: var(--gold);
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.form-actions .btn-primary {
    width: auto;
}

.form-error {
    color: var(--danger);
    font-size: .88rem;
    margin: 12px 0 0;
}

#pw-hint {
    font-weight: 400;
    color: var(--muted);
}

/* Editor & Upload */
.admin-form {
    max-width: 900px;
}

.editor-toolbar-extra {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.image-size-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
    padding: 10px 12px;
    background: rgba(214, 161, 74, .1);
    border: 1px solid rgba(214, 161, 74, .28);
    border-radius: var(--radius);
}

.image-size-bar[hidden] {
    display: none !important;
}

.image-size-label {
    font-size: .82rem;
    font-weight: 600;
    color: var(--gold-light);
    margin-right: 4px;
}

.image-size-bar input[type="range"] {
    width: 140px;
    accent-color: var(--gold);
    cursor: pointer;
}

.image-size-value {
    min-width: 42px;
    font-size: .82rem;
    font-weight: 600;
    color: var(--muted);
}

.image-size-divider {
    width: 1px;
    height: 28px;
    background: var(--border);
    margin: 0 4px;
}

.image-size-bar .btn.active {
    border-color: var(--gold);
    color: var(--gold-light);
    background: rgba(214, 161, 74, .14);
}

.ql-editor img {
    cursor: pointer;
    border-radius: 8px;
    transition: outline-color .15s;
}

.ql-editor img.editor-image-selected {
    outline: 2px solid var(--gold);
    outline-offset: 3px;
}

.btn-upload {
    cursor: pointer;
    margin: 0;
}

.btn-upload input {
    display: none;
}

#post-editor {
    min-height: 320px;
    background: rgba(0, 0, 0, .25);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
}

.ql-toolbar.ql-snow {
    border: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    background: var(--bg-elevated);
}

.ql-container.ql-snow {
    border: 1px solid var(--border);
    border-top: 0;
    border-radius: 0 0 var(--radius) var(--radius);
    font-family: var(--font);
    font-size: 1rem;
}

.ql-editor {
    min-height: 280px;
}

.ql-snow .ql-stroke {
    stroke: #c5ccd3;
}

.ql-snow .ql-fill {
    fill: #c5ccd3;
}

.ql-snow .ql-picker {
    color: #c5ccd3;
}

.ql-snow .ql-picker-options {
    background: var(--bg-card);
    border-color: var(--border);
}

.upload-box {
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 16px;
    background: rgba(0, 0, 0, .15);
}

/* Titelbild Upload */
.cover-upload {
    border: 2px dashed rgba(214, 161, 74, .45);
    border-radius: calc(var(--radius) + 2px);
    background: rgba(0, 0, 0, .2);
    overflow: hidden;
    transition: border-color .2s, background .2s, box-shadow .2s;
}

.cover-upload.dragover {
    border-color: var(--gold);
    background: rgba(214, 161, 74, .1);
    box-shadow: 0 0 0 4px rgba(214, 161, 74, .12);
}

.cover-upload.has-cover {
    border-style: solid;
    border-color: var(--border);
    background: rgba(0, 0, 0, .15);
}

.cover-upload.has-cover.dragover {
    border-color: var(--gold);
}

.cover-drop {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 220px;
    padding: 32px 24px;
    cursor: pointer;
    text-align: center;
    color: var(--text);
    transition: background .2s;
}

.cover-drop:hover {
    background: rgba(214, 161, 74, .06);
}

.cover-drop-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    margin-bottom: 4px;
    border-radius: 50%;
    background: rgba(214, 161, 74, .14);
    color: var(--gold-light);
}

.cover-drop-icon svg {
    width: 44px;
    height: 44px;
}

.cover-drop strong {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--gold-light);
}

.cover-drop span {
    font-size: .92rem;
    color: var(--muted);
}

.cover-drop small {
    margin-top: 4px;
    font-size: .78rem;
    color: var(--muted);
    opacity: .9;
}

.cover-preview {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 14px;
}

.cover-preview[hidden],
.cover-drop[hidden] {
    display: none !important;
}

.cover-preview-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    background: #0c1117;
}

.cover-preview-frame img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

.cover-preview-frame img:not([src]) {
    display: none;
}

.cover-preview-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.cover-preview-hint {
    margin: 0;
    font-size: .78rem;
    color: var(--muted);
}

.cover-preview-actions .btn-sm {
    width: auto;
}

.upload-drop {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 28px 16px;
    cursor: pointer;
    text-align: center;
    color: var(--muted);
    border-radius: var(--radius);
    transition: border-color .2s, background .2s;
}

.upload-drop:hover,
.upload-drop.dragover {
    background: rgba(214, 161, 74, .08);
    color: var(--text);
}

.upload-drop small {
    font-size: .75rem;
    opacity: .8;
}

/* Legacy – falls noch verwendet */
.upload-preview {
    display: none;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 20px;
    background: var(--bg-card);
    border: 1px solid var(--gold);
    border-radius: var(--radius);
    color: var(--text);
    font-size: .9rem;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .4);
    z-index: 200;
}

@media (max-width: 800px) {
    .admin-page {
        grid-template-columns: 1fr;
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 90;
        background: rgba(0, 0, 0, .55);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity .25s, visibility .25s;
        border: 0;
        padding: 0;
        cursor: pointer;
    }

    .sidebar-backdrop.open {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 100;
        width: min(280px, 88vw);
        padding: 20px 16px;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        border-right: 1px solid var(--border);
        transform: translateX(-100%);
        transition: transform .25s ease;
        overflow-y: auto;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-logo img {
        margin: 0 auto 24px;
        height: 48px;
    }

    .sidebar-nav {
        flex-direction: column;
        flex: 1;
    }

    .sidebar-foot {
        border-top: 1px solid var(--border);
        padding-top: 16px;
        margin-top: 16px;
        display: block;
    }

    .sidebar-foot .btn-sm {
        width: 100%;
    }

    .user-badge {
        margin-bottom: 12px;
    }

    .admin-menu-toggle {
        display: flex;
    }

    .admin-topbar {
        padding: 16px;
        align-items: flex-start;
    }

    .admin-topbar h1 {
        font-size: 1.2rem;
    }

    .topbar-actions {
        width: 100%;
    }

    .topbar-actions .btn-primary {
        width: 100%;
    }

    .admin-content {
        padding: 16px 16px 32px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .span-2 {
        grid-column: span 1;
    }

    .form-actions {
        flex-direction: column-reverse;
    }

    .form-actions .btn,
    .form-actions .btn-primary {
        width: 100%;
    }

    .admin-form {
        max-width: none;
    }

    .table-wrap {
        border: 0;
        background: transparent;
        overflow: visible;
    }

    .data-table thead {
        display: none;
    }

    .data-table tbody {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .data-table tr {
        display: block;
        padding: 14px;
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--radius);
    }

    .data-table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 8px 0;
        border-bottom: 0;
        white-space: normal;
        text-align: left;
    }

    .data-table td::before {
        content: attr(data-label);
        flex-shrink: 0;
        font-size: .72rem;
        font-weight: 700;
        letter-spacing: .06em;
        text-transform: uppercase;
        color: var(--muted);
    }

    .data-table td:first-child {
        display: block;
        padding-top: 0;
        padding-bottom: 10px;
        margin-bottom: 4px;
        font-size: 1rem;
        font-weight: 600;
        line-height: 1.35;
        border-bottom: 1px solid var(--border);
    }

    .data-table td:first-child::before {
        content: none;
    }

    .data-table td:last-child {
        justify-content: flex-start;
        padding-top: 12px;
        padding-bottom: 0;
    }

    .data-table td:last-child::before {
        display: none;
    }

    .table-actions {
        width: 100%;
        justify-content: stretch;
    }

    .table-actions .btn-edit,
    .table-actions .btn-danger {
        flex: 1;
        margin: 0;
        text-align: center;
        padding: 10px 12px;
    }

    .editor-toolbar-extra .btn {
        flex: 1 1 calc(50% - 4px);
        min-width: calc(50% - 4px);
    }

    .image-size-divider {
        display: none;
    }

    .image-size-bar {
        flex-direction: row;
    }

    .image-size-bar input[type="range"] {
        width: 100%;
        flex: 1 1 100%;
        order: 10;
    }

    .image-size-value {
        order: 11;
    }

    .image-size-bar .btn-sm {
        flex: 1 1 calc(33.333% - 6px);
        min-width: calc(33.333% - 6px);
    }

    .image-size-label {
        flex: 1 1 100%;
        margin: 4px 0 0;
    }

    .cover-drop {
        min-height: 180px;
        padding: 24px 16px;
    }

    .cover-preview-actions {
        flex-direction: column;
    }

    .cover-preview-actions .btn-sm {
        width: 100%;
    }

    .ql-toolbar.ql-snow {
        display: flex;
        flex-wrap: wrap;
        row-gap: 6px;
    }

    .ql-toolbar.ql-snow .ql-formats {
        margin-right: 6px;
        margin-bottom: 0;
    }

    .toast {
        left: 16px;
        right: 16px;
        bottom: 16px;
        text-align: center;
    }

    .login-card {
        padding: 32px 24px;
    }
}

@media (max-width: 480px) {
    .admin-topbar h1 {
        font-size: 1.05rem;
    }

    .image-size-bar .btn-sm {
        flex: 1 1 calc(50% - 4px);
        min-width: calc(50% - 4px);
    }
}
