:root {
    --primary: #5e5ce6;
    --primary-dark: #4f4dd1;
    --bg: #f5f7fb;
    --surface: #ffffff;
    --sidebar-bg: #1a1b3e;
    --sidebar-text: #c8c9e0;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --success: #16a34a;
    --danger: #dc2626;
    --warn: #f59e0b;
    --info: #2563eb;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3, h4 { color: var(--text); }

.muted { color: var(--muted); }
code {
    background: #f1f5f9;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: 'SF Mono', Menlo, Consolas, monospace;
}

/* ========== Login page ========== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #5e5ce6 0%, #7873e9 50%, #9d7fea 100%);
    padding: 2rem;
}

.login-card {
    background: var(--surface);
    padding: 2.5rem;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 420px;
}

.login-card__brand {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
    letter-spacing: -0.01em;
}
.login-card__logo {
    display: block;
    width: 160px;
    height: auto;
    margin: 0 auto 1.75rem;
}

.login-card h1 {
    margin: 0 0 1.5rem;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* ========== Admin layout ========== */
body.admin {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: 60px 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar main";
    min-height: 100vh;
}

.sidebar {
    grid-area: sidebar;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 1.5rem 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar__brand {
    padding: 0 1.5rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 1rem;
}
.sidebar__logo {
    display: block;
    width: 150px;
    height: auto;
}

.sidebar__nav { display: flex; flex-direction: column; }

.sidebar__nav a {
    color: var(--sidebar-text);
    padding: 0.75rem 1.5rem;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    border-left: 3px solid transparent;
    font-size: 0.9rem;
}

.sidebar__nav a:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #ffffff;
    text-decoration: none;
}

.sidebar__nav a.is-active {
    background: rgba(94, 92, 230, 0.18);
    color: #ffffff;
    border-left-color: var(--primary);
    font-weight: 600;
}

.topbar {
    grid-area: topbar;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 1.5rem;
}

.topbar__user {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.topbar__name {
    font-weight: 600;
    color: var(--text);
}

.logout-form { margin: 0; }

.content {
    grid-area: main;
    padding: 2rem;
    max-width: 1200px;
    width: 100%;
}

/* ========== Page header ========== */
.page-header { margin-bottom: 2rem; }
.page-header h1 {
    margin: 0 0 0.25rem;
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.page-header p { margin: 0; }

/* ========== Cards ========== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card h2 {
    margin: 0 0 1rem;
    font-size: 1.05rem;
    font-weight: 600;
}

/* ========== Stats grid ========== */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
}

.stat__label {
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.stat__value {
    font-size: 1.7rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}

/* ========== Forms ========== */
.form { display: flex; flex-direction: column; gap: 1rem; }

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

.field span {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

.field input,
.field select,
.field textarea {
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: var(--surface);
    color: var(--text);
    width: 100%;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(94, 92, 230, 0.15);
}

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.7rem 1.2rem;
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, opacity 0.15s, border-color 0.15s;
    line-height: 1.2;
}

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

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

.btn--ghost {
    background: transparent;
    color: var(--muted);
    border-color: var(--border);
}
.btn--ghost:hover {
    background: var(--bg);
    color: var(--text);
}

.btn--danger { background: var(--danger); color: #ffffff; }
.btn--danger:hover { background: #b91c1c; }

.btn--block { width: 100%; }
.btn--sm { padding: 0.45rem 0.85rem; font-size: 0.85rem; }

/* ========== Alerts ========== */
.alert {
    padding: 0.85rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    border: 1px solid transparent;
}

.alert--success { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.alert--danger  { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.alert--warn    { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.alert--info    { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }

/* ========== Tables ========== */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
}

th, td {
    padding: 0.85rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background: #fafbff;
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbff; }

.checklist { padding-left: 1.2rem; line-height: 1.8; color: var(--text); }
.checklist li::marker { color: var(--primary); font-weight: 700; }

/* ========== Page header row (title + actions) ========== */
.page-header__row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.page-header__actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ========== Empty state ========== */
.empty {
    text-align: center;
    padding: 2.5rem 1.5rem;
}
.empty p { margin: 0 0 1rem; color: var(--muted); }

/* ========== Badges ========== */
.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border: 1px solid transparent;
    margin-right: 0.25rem;
}
.badge--success { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.badge--danger  { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.badge--warn    { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.badge--info    { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.badge--muted   { background: #f1f5f9; color: #64748b; border-color: #e2e8f0; }

/* ========== Table actions ========== */
.actions {
    display: flex;
    gap: 0.85rem;
    align-items: center;
    white-space: nowrap;
}
.actions a { font-weight: 600; }
.actions form { margin: 0; display: inline; }
.link-danger {
    background: none;
    border: none;
    padding: 0;
    color: var(--danger);
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
}
.link-danger:hover { text-decoration: underline; }

/* ========== Form extras ========== */
.form.card {
    max-width: 720px;
}
.form__actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 0.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}
.field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}
.field__error {
    color: var(--danger);
    font-size: 0.8rem;
    font-weight: 500;
}
.field__hint {
    color: var(--muted);
    font-size: 0.8rem;
}
.fieldset {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem 1.25rem;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}
.fieldset legend {
    font-weight: 600;
    color: var(--text);
    padding: 0 0.5rem;
}
.checkbox {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    user-select: none;
}
.checkbox input { width: auto; margin: 0; }
.checkbox span { font-weight: 500; color: var(--text); }

/* ========== Filters bar ========== */
.filters {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}
.filters .field { flex: 1 1 200px; }
.filters .btn { height: fit-content; }

/* ========== Key/value list ========== */
.kv {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 0.5rem 1rem;
    margin: 0;
}
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { margin: 0; color: var(--text); }

/* ========== Misc ========== */
.truncate {
    display: inline-block;
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}
.copy-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    max-width: 480px;
}
.copy-row code {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: #f1f5f9;
    padding: 0.35rem 0.6rem;
    border-radius: 6px;
    font-size: 0.78rem;
}
.breadcrumb {
    margin: 0 0 0.5rem;
    font-size: 0.85rem;
    color: var(--muted);
}
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--primary); }
.card__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.card__head h2 { margin: 0; }

/* ========== Media library (WordPress-style compact grid) ========== */
.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 6px;
}
.media-tile {
    aspect-ratio: 1;
    background: #f1f5f9;
    border: 3px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    padding: 0;
    position: relative;
    transition: border-color 0.1s, transform 0.1s;
    font-family: inherit;
}
.media-tile:hover {
    border-color: var(--primary);
}
.media-tile:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(94, 92, 230, 0.25);
}
.media-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ========== Media dialog ========== */
dialog.media-dialog {
    border: none;
    border-radius: 14px;
    padding: 0;
    max-width: 860px;
    width: 92vw;
    max-height: 90vh;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    background: var(--surface);
}
dialog.media-dialog::backdrop {
    background: rgba(15, 23, 42, 0.6);
}
.dialog-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    min-height: 380px;
    max-height: 90vh;
}
@media (max-width: 720px) {
    .dialog-grid { grid-template-columns: 1fr; max-height: 88vh; overflow-y: auto; }
}
.dialog-preview {
    background: #1a1b3e;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow: hidden;
}
.dialog-preview img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: 4px;
    background: repeating-conic-gradient(#e5e7eb 0% 25%, #ffffff 0% 50%) 0 0 / 16px 16px;
}
.dialog-info {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    position: relative;
}
.dialog-title {
    margin: 0 0 1rem;
    padding-right: 2.5rem;
    font-size: 1.05rem;
    font-weight: 700;
    word-break: break-all;
    line-height: 1.3;
}
.dialog-info .kv {
    display: grid;
    grid-template-columns: 90px 1fr;
    gap: 0.4rem 1rem;
    margin: 0 0 1rem;
    font-size: 0.85rem;
}
.dialog-info .kv dt { color: var(--muted); font-weight: 500; }
.dialog-info .kv dd { margin: 0; color: var(--text); word-break: break-word; }
.dialog-info .field { margin-bottom: 1rem; }
.dialog-info .field input {
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 0.78rem;
    background: #f8fafc;
}
.dialog-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: auto;
}
.dialog-actions form { margin: 0; }
.dialog-actions .btn { width: 100%; }
.dialog-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: var(--bg);
    color: var(--muted);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.4rem;
    line-height: 1;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
    z-index: 1;
}
.dialog-close:hover { background: var(--danger); color: #fff; }

/* ========== Image preview (in forms) ========== */
.image-preview {
    position: relative;
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: #f1f5f9;
    max-width: 320px;
}
.image-preview img {
    display: block;
    width: 100%;
    height: auto;
}
.image-preview--banner { max-width: 100%; }
.image-preview--banner img { aspect-ratio: 16/5; object-fit: cover; }
.image-preview__remove {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}
.image-preview__remove:hover { background: var(--danger); }

/* ========== Color picker (swatch + hex input synced) ========== */
.color-field {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.color-field input[type="color"] {
    -webkit-appearance: none;
    appearance: none;
    width: 56px;
    height: 42px;
    padding: 0;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    background: transparent;
    flex-shrink: 0;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.color-field input[type="color"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(94, 92, 230, 0.15);
}
.color-field input[type="color"]::-webkit-color-swatch-wrapper { padding: 4px; border-radius: 6px; }
.color-field input[type="color"]::-webkit-color-swatch { border: none; border-radius: 5px; }
.color-field input[type="color"]::-moz-color-swatch { border: none; border-radius: 5px; }
.color-field input[type="text"] {
    flex: 1;
    min-width: 0;
    padding: 0.65rem 0.85rem;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.color-field input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(94, 92, 230, 0.15);
}
pre {
    background: #f1f5f9;
    padding: 1rem;
    border-radius: 8px;
    overflow: auto;
    font-size: 0.82rem;
    color: #334155;
    font-family: 'SF Mono', Menlo, Consolas, monospace;
}

/* ========== Mobile ========== */
@media (max-width: 768px) {
    body.admin {
        grid-template-columns: 1fr;
        grid-template-rows: 60px auto 1fr;
        grid-template-areas:
            "topbar"
            "sidebar"
            "main";
    }
    .sidebar { height: auto; position: relative; padding: 1rem 0; }
    .sidebar__nav { flex-direction: row; overflow-x: auto; }
    .sidebar__nav a { white-space: nowrap; border-left: none; border-bottom: 3px solid transparent; }
    .sidebar__nav a.is-active { border-left: none; border-bottom-color: var(--primary); }
    .content { padding: 1rem; }
}
