/* ============================================================
   Design tokens
   ============================================================ */

:root {
    --bg: #f5f6fb;
    --bg-glow: radial-gradient(80rem 40rem at 15% -10%, rgba(79, 70, 229, 0.08), transparent 60%);
    --surface: #ffffff;
    --surface-2: #fbfbfe;
    --border: #e6e8f0;
    --ink: #14161f;
    --ink-muted: #6b7080;
    --ink-faint: #9297a8;

    --accent: #4f46e5;
    --accent-ink: #ffffff;
    --accent-soft: #eef0fe;

    --danger: #e11d48;
    --danger-soft: #fdecef;

    --photo: #0d9668;
    --photo-soft: #e7f8f1;
    --quote: #b45f06;
    --quote-soft: #fdf3e3;
    --link-c: #7c3aed;
    --link-soft: #f3eefe;
    --text-c: #2f6fce;
    --text-soft: #eaf2fc;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;

    --shadow-sm: 0 1px 2px rgba(20, 22, 31, 0.06);
    --shadow-md: 0 8px 24px -8px rgba(20, 22, 31, 0.14);
    --shadow-lg: 0 24px 48px -16px rgba(20, 22, 31, 0.22);

    --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

    --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b0d14;
        --bg-glow: radial-gradient(80rem 40rem at 15% -10%, rgba(99, 102, 241, 0.14), transparent 60%);
        --surface: #12141c;
        --surface-2: #171a24;
        --border: #262a38;
        --ink: #f1f2f6;
        --ink-muted: #9297ab;
        --ink-faint: #6b7080;

        --accent: #6366f1;
        --accent-ink: #ffffff;
        --accent-soft: rgba(99, 102, 241, 0.16);

        --danger: #fb7185;
        --danger-soft: rgba(251, 113, 133, 0.14);

        --photo: #34d399;
        --photo-soft: rgba(52, 211, 153, 0.14);
        --quote: #f0b054;
        --quote-soft: rgba(240, 176, 84, 0.14);
        --link-c: #a78bfa;
        --link-soft: rgba(167, 139, 250, 0.14);
        --text-c: #7fb2ee;
        --text-soft: rgba(127, 178, 238, 0.14);

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 8px 24px -8px rgba(0, 0, 0, 0.5);
        --shadow-lg: 0 24px 48px -16px rgba(0, 0, 0, 0.6);
    }
}

/* ============================================================
   Base
   ============================================================ */

* { box-sizing: border-box; }

body.dash {
    margin: 0;
    min-height: 100vh;
    background: var(--bg-glow), var(--bg);
    color: var(--ink);
    font-family: var(--font-ui);
    -webkit-font-smoothing: antialiased;
}

.dash a { color: inherit; }

.dash :focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

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

/* ============================================================
   Shell / topbar
   ============================================================ */

.shell {
    max-width: 920px;
    margin: 0 auto;
    padding: 28px 24px 80px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 16px;
    margin-bottom: 28px;
    background: color-mix(in srgb, var(--surface) 70%, transparent);
    backdrop-filter: blur(14px) saturate(1.4);
    -webkit-backdrop-filter: blur(14px) saturate(1.4);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 16px;
    z-index: 20;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.topbar-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.topbar-avatar-placeholder {
    display: inline-block;
    background: var(--accent-soft);
}

.topbar-titles {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    min-width: 0;
}

.topbar-name {
    font-weight: 700;
    font-size: 0.92rem;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-eyebrow {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-faint);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    background: var(--accent-soft);
    color: var(--accent);
    transition: background 0.15s var(--ease), transform 0.15s var(--ease);
}

.btn:hover { background: color-mix(in srgb, var(--accent-soft) 60%, var(--accent) 10%); }
.btn:active { transform: translateY(1px); }

.btn-primary {
    background: var(--accent);
    color: var(--accent-ink);
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }

.icon-btn {
    padding: 8px;
    background: transparent;
    color: var(--ink-muted);
}

.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.chevron { transition: transform 0.15s var(--ease); }
details[open] > summary .chevron { transform: rotate(180deg); }

summary.btn { list-style: none; }
summary.btn::-webkit-details-marker { display: none; }

/* ============================================================
   Dropdown menus (native <details>, zero JS required to function;
   dashboard.js only adds outside-click / Escape-to-close polish)
   ============================================================ */

.menu {
    position: relative;
}

.menu-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 180px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;

    opacity: 0;
    transform: translateY(-4px) scale(0.98);
    transition: opacity 0.14s var(--ease), transform 0.14s var(--ease);
}

.menu-panel-right {
    left: auto;
    right: 0;
}

.menu[open] .menu-panel {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.menu-panel a,
.menu-panel button {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    font: inherit;
    font-size: 0.86rem;
    color: var(--ink);
    text-decoration: none;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.menu-panel a:hover,
.menu-panel button:hover {
    background: var(--surface-2);
}

.menu-panel hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 4px 2px;
}

.menu-panel form { margin: 0; }

/* ============================================================
   Panel + table
   ============================================================ */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: 20px 22px;
}

.panel-header h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0;
}

.count-pill {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ink-faint);
    font-variant-numeric: tabular-nums;
}

.post-table {
    width: 100%;
    border-collapse: collapse;
}

.post-table th {
    text-align: left;
    padding: 10px 22px;
    background: var(--surface-2);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-faint);
}

.post-table td {
    padding: 14px 22px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.post-table tbody tr {
    position: relative;
    box-shadow: inset 3px 0 0 0 transparent;
    transition: background 0.12s var(--ease), box-shadow 0.12s var(--ease);
}

.post-table tbody tr:last-child td { border-bottom: none; }
.post-table tbody tr:hover { background: var(--surface-2); }

.post-table tr.row-photo:hover,
.post-table tr.row-photo { box-shadow: inset 3px 0 0 0 var(--photo); }
.post-table tr.row-quote { box-shadow: inset 3px 0 0 0 var(--quote); }
.post-table tr.row-link { box-shadow: inset 3px 0 0 0 var(--link-c); }
.post-table tr.row-text { box-shadow: inset 3px 0 0 0 var(--text-c); }

.type-pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: capitalize;
}

.type-pill.type-photo { background: var(--photo-soft); color: var(--photo); }
.type-pill.type-quote { background: var(--quote-soft); color: var(--quote); }
.type-pill.type-link { background: var(--link-soft); color: var(--link-c); }
.type-pill.type-text { background: var(--text-soft); color: var(--text-c); }

.col-title { font-size: 0.92rem; }

.col-date {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 0.8rem;
    color: var(--ink-muted);
    white-space: nowrap;
}

.col-actions {
    text-align: right;
    white-space: nowrap;
}

.col-actions form { display: inline; }

.icon-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-muted);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.12s var(--ease), color 0.12s var(--ease);
}

.icon-action:hover { background: var(--accent-soft); color: var(--accent); }
.icon-action.icon-action-danger:hover { background: var(--danger-soft); color: var(--danger); }

.empty-state {
    padding: 40px 22px;
    text-align: center;
    color: var(--ink-muted);
    font-size: 0.92rem;
}

/* ============================================================
   Pager
   ============================================================ */

.pager {
    display: flex;
    justify-content: space-between;
    margin-top: 16px;
    font-size: 0.85rem;
}

.pager a {
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
}

.pager a:hover { text-decoration: underline; }

/* ============================================================
   Forms
   ============================================================ */

.dash h1.page-title {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0 0 18px;
}

.form-error {
    color: var(--danger);
    background: var(--danger-soft);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 0.88rem;
    margin-bottom: 16px;
}

.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 26px;
    max-width: 540px;
}

.field {
    display: block;
    margin-bottom: 18px;
}

.field-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-faint);
    margin-bottom: 7px;
}

.field input[type="text"],
.field input[type="url"],
.field input[type="password"],
.field input[type="file"],
.field textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.12s var(--ease), box-shadow 0.12s var(--ease);
}

.field textarea {
    min-height: 100px;
    resize: vertical;
}

.formatting-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
}

.formatting-btn {
    padding: 4px 9px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--ink-muted);
    font-size: 0.78rem;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.12s var(--ease), color 0.12s var(--ease);
}

.formatting-btn:hover {
    border-color: var(--accent);
    color: var(--ink);
}

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

.field-checkbox {
    display: flex !important;
    align-items: center;
    gap: 8px;
    font-weight: 500 !important;
    text-transform: none !important;
    letter-spacing: normal !important;
    color: var(--ink) !important;
    margin-bottom: 22px;
}

.field-checkbox input { width: auto; }

.preview-image {
    max-width: 200px;
    display: block;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 14px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 20px;
    color: var(--ink-muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
}

.back-link:hover { color: var(--accent); }

/* ============================================================
   Login
   ============================================================ */

body.login {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-card {
    width: 100%;
    max-width: 360px;
    margin: 20px;
    padding: 32px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.login-card h1 {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0 0 20px;
}
