:root {
    --bg-soft: #f3f8f7;
    --bg-accent: #d9efe8;
    --text-main: #102127;
    --text-muted: #4f6470;
    --card-bg: #ffffff;
    --card-border: #c8d9d3;
    --brand: #0d8f83;
    --brand-deep: #0a6d64;
    --warning: #d14f3e;
    --shadow: 0 18px 48px rgba(16, 33, 39, 0.12);
    --surface: rgba(255, 255, 255, 0.86);
    --pill-bg: #ffffff;
    --pill-border: #bdd7cf;
    --pill-hover: #f6fffc;
    --welcome-bg: rgba(226, 247, 241, 0.86);
    --welcome-border: rgba(129, 189, 172, 0.45);
    --welcome-text: #0b655d;
    --row-head: #e9f5f1;
    --row-alt: #f7fcfa;
    --field-bg: #fbfdfc;
    --danger-bg: #ffe9e5;
    --danger-border: #f2c4bb;
    --danger-hover: #ffd8d1;
    --success-bg: #dcf4eb;
    --success-hover: #c8ecdf;
    --pages-cols: minmax(11rem, 1.35fr) minmax(13rem, 1.7fr) minmax(11rem, 1.25fr) minmax(8.5rem, 0.9fr) minmax(10.5rem, 1fr);
    --users-cols: minmax(7rem, 0.9fr) minmax(12rem, 1.6fr) minmax(8.5rem, 1fr) minmax(10.5rem, 1fr);
    --details-bg: #f4fbf8;
    --chip-bg: #d8efe7;
    --chip-text: #0f5d55;
    --input-focus: rgba(13, 143, 131, 0.32);
    --scroll-track: rgba(16, 33, 39, 0.08);
    --scroll-thumb: color-mix(in srgb, var(--brand) 62%, #ffffff 38%);
    --scroll-thumb-hover: color-mix(in srgb, var(--brand-deep) 68%, #ffffff 32%);
}

html[data-theme="dark"] {
    --bg-soft: #0f171c;
    --bg-accent: #162228;
    --text-main: #e8f0f1;
    --text-muted: #a0b2bb;
    --card-bg: #172229;
    --card-border: #2b3c46;
    --brand: #58c3af;
    --brand-deep: #76d4c2;
    --warning: #ff8f82;
    --shadow: 0 20px 44px rgba(0, 0, 0, 0.42);
    --surface: rgba(20, 31, 38, 0.82);
    --pill-bg: #1a2830;
    --pill-border: #324651;
    --pill-hover: #22333d;
    --welcome-bg: rgba(27, 54, 59, 0.8);
    --welcome-border: rgba(78, 134, 138, 0.55);
    --welcome-text: #9ee3d3;
    --row-head: #1e2d36;
    --row-alt: #1a2830;
    --field-bg: #121c23;
    --danger-bg: #4f2825;
    --danger-border: #7a3e39;
    --danger-hover: #67322e;
    --success-bg: #1e4038;
    --success-hover: #255149;
    --details-bg: #18252d;
    --chip-bg: #264b43;
    --chip-text: #b5ece0;
    --input-focus: rgba(118, 212, 194, 0.4);
    --scroll-track: rgba(232, 240, 241, 0.14);
    --scroll-thumb: color-mix(in srgb, var(--brand) 78%, #ffffff 22%);
    --scroll-thumb-hover: color-mix(in srgb, var(--brand-deep) 82%, #ffffff 18%);
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

*::-webkit-scrollbar {
    width: 11px;
    height: 11px;
}

*::-webkit-scrollbar-track {
    background: var(--scroll-track);
    border-radius: 999px;
}

*::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--scroll-thumb), var(--scroll-thumb-hover));
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, var(--scroll-thumb-hover), var(--scroll-thumb));
    border: 2px solid transparent;
    background-clip: content-box;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text-main);
    font-family: "Space Grotesk", "Segoe UI", sans-serif;
    overflow-x: hidden;
    background:
        radial-gradient(80rem 30rem at -10% -20%, rgba(255, 255, 255, 0.92) 10%, transparent 55%),
        radial-gradient(60rem 30rem at 110% -10%, rgba(200, 235, 226, 0.85) 8%, transparent 60%),
        repeating-linear-gradient(120deg, rgba(255, 255, 255, 0.08) 0 2px, transparent 2px 20px),
        linear-gradient(160deg, var(--bg-soft), var(--bg-accent));
}

html[data-theme="dark"] body {
    background:
        radial-gradient(80rem 30rem at -10% -20%, rgba(103, 145, 158, 0.14) 10%, transparent 55%),
        radial-gradient(60rem 30rem at 110% -10%, rgba(63, 115, 102, 0.2) 8%, transparent 60%),
        repeating-linear-gradient(120deg, rgba(145, 170, 184, 0.06) 0 2px, transparent 2px 20px),
        linear-gradient(160deg, var(--bg-soft), var(--bg-accent));
}

.hidden {
    display: none !important;
}

.page-shell {
    width: min(1240px, 93vw);
    margin: 2rem auto 3rem;
}

#bar {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 1.1rem 1.25rem;
    border: 1px solid var(--card-border);
    border-radius: 1.2rem;
    background: var(--surface);
    backdrop-filter: blur(8px);
    box-shadow: var(--shadow);
}

.brand-block {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.brand-kicker {
    margin: 0;
    font-size: 0.8rem;
    letter-spacing: 0.12rem;
    text-transform: uppercase;
    color: var(--text-muted);
}

.brand-title {
    margin: 0;
    font-family: "Fraunces", Georgia, serif;
    font-size: clamp(1.4rem, 2.1vw, 2rem);
    line-height: 1;
}

#welcome {
    justify-self: end;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--welcome-border);
    background: var(--welcome-bg);
    color: var(--welcome-text);
    font-weight: 600;
    white-space: nowrap;
}

.quick-actions {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    justify-content: flex-end;
}

#admin,
#logout {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.25rem;
    padding: 0 1rem;
    border-radius: 999px;
    border: 1px solid var(--pill-border);
    background: var(--pill-bg);
    color: var(--text-main);
    font-size: 0.92rem;
    font-weight: 600;
    transition: transform 180ms ease, box-shadow 180ms ease, background-color 180ms ease;
    cursor: pointer;
}

#admin:hover,
#logout:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 20px rgba(13, 143, 131, 0.16);
    background: var(--pill-hover);
}

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

#logout {
    border-color: rgba(255, 143, 130, 0.45);
    color: var(--warning);
}

#theme-toggle {
    position: fixed;
    right: clamp(0.8rem, 2vw, 1.25rem);
    bottom: clamp(0.8rem, 2vw, 1.25rem);
    width: 2.85rem;
    height: 2.85rem;
    border-radius: 50%;
    border: 1px solid var(--pill-border);
    background: var(--surface);
    color: var(--text-main);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 12px 24px rgba(8, 18, 22, 0.22);
    backdrop-filter: blur(8px);
    transition: transform 170ms ease, box-shadow 170ms ease, background-color 170ms ease;
    z-index: 30;
}

#theme-toggle:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 16px 30px rgba(8, 18, 22, 0.3);
    background: var(--pill-hover);
}

#all {
    display: grid;
    gap: 1rem;
}

.admin-card {
    border: 1px solid var(--card-border);
    border-radius: 1.2rem;
    background: color-mix(in srgb, var(--card-bg) 88%, transparent);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.card-head {
    padding: 1rem 1.15rem;
    border-bottom: 1px solid var(--card-border);
    background: color-mix(in srgb, var(--surface) 90%, transparent);
}

.card-head h2 {
    margin: 0;
    font-family: "Fraunces", Georgia, serif;
    font-size: 1.35rem;
}

.card-head p {
    margin: 0.35rem 0 0;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.listitem {
    display: grid;
    grid-template-columns: var(--pages-cols);
    align-items: center;
    min-height: 3rem;
    border-bottom: 1px solid var(--card-border);
}

#pages .listitem {
    grid-template-columns: var(--pages-cols);
}

#users .listitem,
.user-grid {
    grid-template-columns: var(--users-cols);
}

.listitem > * {
    padding: 0.55rem 0.7rem;
    min-width: 0;
    border-right: 1px solid var(--card-border);
    text-align: center;
    overflow-wrap: break-word;
}

.listitem > *:last-child {
    border-right: 0;
}

.row-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border-right: 0;
    white-space: nowrap;
    flex-wrap: nowrap;
    min-width: 0;
}

.expand-entry {
    border: 1px solid var(--pill-border);
    border-radius: 0.55rem;
    background: var(--pill-bg);
    color: var(--text-main);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1;
    min-height: 2.1rem;
    min-width: 5.7rem;
    padding: 0.3rem 0.55rem;
    margin: 0.25rem 0;
    cursor: pointer;
    transition: transform 130ms ease, background-color 130ms ease;
    white-space: nowrap;
}

.expand-user-entry {
    display: none;
    border: 1px solid var(--pill-border);
    border-radius: 0.55rem;
    background: var(--pill-bg);
    color: var(--text-main);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1;
    min-height: 2.1rem;
    min-width: 5.7rem;
    padding: 0.3rem 0.55rem;
    margin: 0.25rem 0;
    cursor: pointer;
    transition: transform 130ms ease, background-color 130ms ease;
    white-space: nowrap;
}

.expand-user-entry:hover {
    transform: translateY(-1px);
    background: var(--pill-hover);
}

.expand-entry:hover {
    transform: translateY(-1px);
    background: var(--pill-hover);
}

.pagehead {
    font-weight: 700;
    color: var(--text-main);
    background: var(--row-head);
}

#pages .listitem.toDel:nth-of-type(even),
#users .listitem.toDel:nth-of-type(even) {
    background: var(--row-alt);
}

#pages .listitem.toDel:nth-of-type(odd),
#users .listitem.toDel:nth-of-type(odd) {
    background: var(--card-bg);
}

.entry-details {
    border-bottom: 1px solid var(--card-border);
    background: var(--details-bg);
    padding: 0.7rem 0.9rem 0.9rem;
}

.details-grid {
    display: grid;
    grid-template-columns: 1.25fr 1fr;
    gap: 0.75rem;
}

.details-field {
    display: flex;
    flex-direction: column;
    gap: 0.36rem;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.details-field span {
    font-weight: 700;
    color: var(--text-main);
}

.details-field textarea,
.tag-input {
    width: 100%;
    border: 1px solid var(--card-border);
    border-radius: 0.55rem;
    background: var(--field-bg);
    color: var(--text-main);
    font: inherit;
    padding: 0.55rem 0.65rem;
}

.details-field textarea {
    resize: vertical;
    min-height: 6.3rem;
}

.details-field textarea:focus,
.tag-input:focus {
    outline: 2px solid var(--input-focus);
    outline-offset: 0;
}

.tags-editor {
    border: 1px solid var(--card-border);
    border-radius: 0.55rem;
    background: var(--field-bg);
    padding: 0.45rem;
    min-height: 6.3rem;
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.38rem;
    margin-bottom: 0.45rem;
}

.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border-radius: 999px;
    background: var(--chip-bg);
    color: var(--chip-text);
    font-size: 0.78rem;
    font-weight: 700;
    padding: 0.2rem 0.25rem 0.2rem 0.55rem;
}

.tag-remove {
    border: 0;
    background: transparent;
    color: inherit;
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
}

.tag-remove:hover {
    background: color-mix(in srgb, var(--chip-bg) 65%, #000000 8%);
}

.details-actions {
    margin-top: 0.65rem;
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.save-meta {
    border: 1px solid color-mix(in srgb, var(--brand) 45%, transparent);
    border-radius: 0.55rem;
    background: color-mix(in srgb, var(--brand) 20%, var(--field-bg));
    color: var(--brand-deep);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 700;
    min-height: 2.1rem;
    padding: 0.35rem 0.7rem;
    cursor: pointer;
    transition: transform 130ms ease, filter 130ms ease;
}

.save-meta:hover {
    transform: translateY(-1px);
    filter: brightness(0.97);
}

.cancel-meta {
    border: 1px solid var(--pill-border);
    border-radius: 0.55rem;
    background: var(--pill-bg);
    color: var(--text-main);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 700;
    min-height: 2.1rem;
    padding: 0.35rem 0.7rem;
    cursor: pointer;
    transition: transform 130ms ease, background-color 130ms ease;
}

.cancel-meta:hover {
    transform: translateY(-1px);
    background: var(--pill-hover);
}

.save-status {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.save-status.success {
    color: var(--brand-deep);
}

.save-status.error {
    color: var(--warning);
}

.listitem input[type="text"],
.listitem input[type="file"],
.listitem select {
    width: calc(100% - 0.5rem);
    border: 1px solid var(--card-border);
    border-radius: 0.55rem;
    background: var(--field-bg);
    color: var(--text-main);
    font: inherit;
    padding: 0.42rem 0.5rem;
    margin: 0.25rem;
}

.listitem select {
    cursor: pointer;
}

.listitem input[type="file"] {
    padding: 0.24rem 0.32rem;
}

.listitem input[type="file"]::file-selector-button {
    border: 1px solid var(--pill-border);
    border-radius: 0.5rem;
    background: var(--pill-bg);
    color: var(--text-main);
    font: inherit;
    font-size: 0.84rem;
    font-weight: 600;
    margin-right: 0.5rem;
    padding: 0.28rem 0.55rem;
    cursor: pointer;
    transition: background-color 140ms ease, transform 140ms ease;
}

.listitem input[type="file"]::file-selector-button:hover {
    background: var(--pill-hover);
    transform: translateY(-1px);
}

.deleteuser,
.deletepage,
#addpage {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.1rem;
    min-height: 2.1rem;
    border-radius: 0.6rem;
    cursor: pointer;
    margin: 0.25rem auto;
    transition: background-color 140ms ease, transform 140ms ease;
}

.deleteuser,
.deletepage {
    background: var(--danger-bg) !important;
    border: 1px solid var(--danger-border);
}

.deleteuser:hover,
.deletepage:hover {
    background: var(--danger-hover) !important;
    transform: translateY(-1px);
}

#addpage {
    background: var(--success-bg) !important;
    border: 1px solid color-mix(in srgb, var(--brand) 40%, transparent);
    font-weight: 700;
    color: var(--brand-deep);
}

#addpage:hover {
    background: var(--success-hover) !important;
    transform: translateY(-1px);
}

.deleteuser img,
.deletepage img {
    height: 18px;
    width: 18px;
    object-fit: contain;
}

@media (max-width: 980px) {
    #bar {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    #welcome {
        justify-self: flex-start;
    }

    .quick-actions {
        justify-content: flex-start;
        flex-wrap: wrap;
    }
}

@media (max-width: 780px) {
    .listitem,
    .user-grid {
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }

    .listitem > * {
        border-right: 0;
        border-bottom: 1px solid var(--card-border);
        text-align: left;
        width: 100%;
    }

    .listitem > *:last-child {
        border-bottom: 0;
    }

    .pagehead {
        display: none;
    }

    .details-grid {
        grid-template-columns: 1fr;
    }

    .row-actions {
        justify-content: flex-start;
    }

    .listitem.toDel:not(.add-row) {
        align-items: center;
        border-bottom: 1px solid var(--card-border);
    }

    .listitem.toDel:not(.add-row) > * {
        display: none;
        width: 100%;
        border-bottom: 1px solid var(--card-border);
    }

    #pages .listitem.toDel:not(.add-row) > .pagename,
    #users .listitem.toDel > .username,
    .listitem.toDel:not(.add-row) > .row-actions {
        display: block;
    }

    #pages .listitem.toDel:not(.add-row) > .pagename,
    #users .listitem.toDel > .username {
        font-weight: 700;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .listitem.toDel:not(.add-row) > .row-actions {
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: stretch;
        gap: 0.4rem;
        border-bottom: 0;
    }

    .listitem.add-row {
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }

    .listitem.add-row > * {
        width: 100%;
    }

    .listitem.toDel:not(.add-row) > .row-actions > * {
        width: 100%;
        margin: 0;
    }

    .listitem.toDel:not(.add-row) .deletepage,
    .listitem.toDel:not(.add-row) .deleteuser {
        display: none;
    }

    .listitem.toDel.is-expanded:not(.add-row) {
        align-items: stretch;
    }

    .listitem.toDel.is-expanded:not(.add-row) > * {
        display: block;
    }

    .listitem.toDel.is-expanded:not(.add-row) > [data-label] {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 0.35rem;
        padding: 0.55rem 0.7rem;
    }

    .listitem.toDel.is-expanded:not(.add-row) > [data-label]::before {
        content: attr(data-label);
        font-size: 0.78rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04rem;
        color: var(--text-muted);
        white-space: nowrap;
    }

    .listitem.toDel.is-expanded:not(.add-row) > .pagename,
    .listitem.toDel.is-expanded:not(.add-row) > .username,
    .listitem.toDel.is-expanded:not(.add-row) > .userid,
    .listitem.toDel.is-expanded:not(.add-row) > .link {
        text-align: left;
    }

    .listitem.toDel.is-expanded:not(.add-row) > .image,
    .listitem.toDel.is-expanded:not(.add-row) > .visibility,
    .listitem.toDel.is-expanded:not(.add-row) > .role {
        width: 100%;
        margin: 0;
    }

    .listitem.toDel.is-expanded:not(.add-row) > .row-actions {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        gap: 0.5rem;
        padding: 0.55rem 0.7rem;
        border-bottom: 0;
    }

    .listitem.toDel.is-expanded:not(.add-row) > .row-actions::before {
        content: "Actions";
        font-size: 0.78rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04rem;
        color: var(--text-muted);
        white-space: nowrap;
    }

    .listitem.toDel.is-expanded:not(.add-row) > .row-actions .expand-entry,
    .listitem.toDel.is-expanded:not(.add-row) > .row-actions .expand-user-entry,
    .listitem.toDel.is-expanded:not(.add-row) > .row-actions .deletepage,
    .listitem.toDel.is-expanded:not(.add-row) > .row-actions .deleteuser {
        width: 100%;
        margin: 0;
    }

    .listitem.toDel.is-expanded:not(.add-row) .deletepage,
    .listitem.toDel.is-expanded:not(.add-row) .deleteuser {
        display: inline-flex;
    }

    .expand-entry,
    .expand-user-entry {
        min-width: 0;
        width: 100%;
    }

    .expand-user-entry {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .entry-details {
        padding-top: 0.35rem;
        border-top: 1px dashed var(--card-border);
    }

    .details-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .save-meta,
    .cancel-meta {
        width: 100%;
    }
}

@media (max-width: 430px) {
    .page-shell {
        width: 96vw;
    }

    .admin-card {
        border-radius: 1rem;
    }

    .listitem.toDel.is-expanded:not(.add-row) {
        margin: 0.25rem 0;
        border: 1px solid var(--card-border);
        border-radius: 0.85rem;
        overflow: hidden;
        background: color-mix(in srgb, var(--card-bg) 92%, transparent);
        box-shadow: 0 10px 24px rgba(16, 33, 39, 0.12);
    }

    .listitem.toDel.is-expanded:not(.add-row) > [data-label],
    .listitem.toDel.is-expanded:not(.add-row) > .row-actions {
        gap: 0.34rem;
        align-items: stretch;
    }

    .listitem.toDel.is-expanded:not(.add-row) > [data-label]::before,
    .listitem.toDel.is-expanded:not(.add-row) > .row-actions::before {
        white-space: normal;
    }

    .listitem.toDel.is-expanded:not(.add-row) > .row-actions {
        position: sticky;
        bottom: 0;
        z-index: 2;
        background: color-mix(in srgb, var(--card-bg) 95%, transparent);
        border-top: 1px solid var(--card-border);
        box-shadow: 0 -8px 18px rgba(16, 33, 39, 0.12);
    }

    .listitem.toDel.is-expanded:not(.add-row) > .row-actions > * {
        justify-self: stretch;
    }

    .listitem.toDel.is-expanded:not(.add-row) > .row-actions .expand-entry,
    .listitem.toDel.is-expanded:not(.add-row) > .row-actions .expand-user-entry,
    .listitem.toDel.is-expanded:not(.add-row) > .row-actions .deletepage,
    .listitem.toDel.is-expanded:not(.add-row) > .row-actions .deleteuser {
        width: 100%;
        min-height: 2.35rem;
        justify-content: center;
    }

    .entry-details {
        margin: 0.2rem 0 0.5rem;
        border: 1px dashed var(--card-border);
        border-radius: 0.75rem;
        padding: 0.65rem;
    }

    .details-actions {
        position: sticky;
        bottom: 0;
        z-index: 2;
        background: color-mix(in srgb, var(--details-bg) 95%, transparent);
        padding-top: 0.55rem;
    }

    .save-meta,
    .cancel-meta {
        flex: 1;
    }
}
