/* ==========================================================================
   The Potter's Workshop — admin panel
   ========================================================================== */

:root {
    --purple:      #603472;
    --purple-dark: #45244f;
    --purple-soft: #f3eef6;
    --gold:        #dcad47;
    --gold-dark:   #b98d2e;
    --ink:         #1a1420;
    --body:        #4c4753;
    --muted:       #8b8b95;
    --line:        #e5e1ea;
    --bg:          #f6f4f8;
    --ok:          #2e7d43;
    --err:         #d93025;
    --font: 'Poppins', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --radius: 10px;
    --shadow: 0 2px 14px rgba(26, 20, 32, .07);
}

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

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.65;
    color: var(--body);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font); color: var(--ink); margin: 0 0 .55em; line-height: 1.3; }
h1 { font-size: 1.55rem; font-weight: 600; }
h2 { font-size: 1.2rem;  font-weight: 600; }
h3 { font-size: 1rem;    font-weight: 600; }
p { margin: 0 0 1em; }
a { color: var(--purple); text-decoration: none; }
a:hover { color: var(--gold-dark); }
img { max-width: 100%; display: block; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.ico { width: 1em; height: 1em; fill: currentColor; flex: none; }

/* ------------------------------------------------------------------ login -- */
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 40px 20px;
    background: linear-gradient(rgba(69, 36, 79, .93), rgba(30, 12, 42, .95));
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 14px;
    padding: 40px 38px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
}
.login-card__brand { text-align: center; margin-bottom: 28px; }
.login-card__brand img { width: 76px; height: 76px; margin: 0 auto 12px; object-fit: contain; }
.login-card__brand strong { display: block; font-size: 1.1rem; color: var(--purple); }
.login-card__brand span { font-size: .82rem; color: var(--muted); font-style: italic; }
.login-card h1 { font-size: 1.25rem; text-align: center; margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--muted); font-size: .88rem; margin-bottom: 26px; }
.login-back { display: block; text-align: center; margin-top: 22px; font-size: .86rem; color: var(--muted); }

/* ------------------------------------------------------------------ shell -- */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }

.sidebar {
    background: var(--purple-dark);
    color: rgba(255, 255, 255, .72);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.sidebar__brand {
    display: flex; align-items: center; gap: 11px;
    padding: 20px 22px; border-bottom: 1px solid rgba(255, 255, 255, .1);
}
.sidebar__brand img { width: 40px; height: 40px; background: rgba(255,255,255,.92); border-radius: 8px; padding: 3px; }
.sidebar__brand b { color: #fff; font-size: .92rem; font-weight: 600; line-height: 1.25; }
.sidebar__brand span { display: block; font-size: .72rem; color: rgba(255,255,255,.55); font-style: italic; }

.sidebar nav { padding: 14px 12px; flex: 1; }
.sidebar nav a {
    display: flex; align-items: center; gap: 11px;
    padding: 11px 14px; margin-bottom: 3px;
    border-radius: 7px;
    color: rgba(255, 255, 255, .72);
    font-size: .88rem;
    transition: background .18s, color .18s;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, .09); color: #fff; }
.sidebar nav a.is-current { background: var(--gold); color: #3a2410; font-weight: 600; }
.sidebar nav a .ico { width: 18px; height: 18px; }
.sidebar nav .group {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .14em;
    color: rgba(255,255,255,.38); padding: 18px 14px 7px;
}
.sidebar__foot { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.1); font-size: .8rem; }
.sidebar__foot a { color: rgba(255,255,255,.72); }
.sidebar__foot a:hover { color: var(--gold); }

.content { min-width: 0; display: flex; flex-direction: column; }

.topbar {
    background: #fff; border-bottom: 1px solid var(--line);
    padding: 16px 32px;
    display: flex; align-items: center; justify-content: space-between; gap: 18px;
    position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 1.25rem; }
.topbar__right { display: flex; align-items: center; gap: 14px; font-size: .86rem; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--purple); color: #fff;
    display: grid; place-items: center; font-weight: 600; font-size: .85rem;
}

.page { padding: 30px 32px 60px; flex: 1; }

.menu-btn { display: none; width: 42px; height: 38px; padding: 9px; background: var(--purple); border: 0; border-radius: 7px; cursor: pointer; }
.menu-btn span { display: block; height: 2px; background: #fff; border-radius: 2px; }
.menu-btn span + span { margin-top: 5px; }

/* ------------------------------------------------------------------ cards -- */
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card__head {
    padding: 18px 24px; border-bottom: 1px solid var(--line);
    display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
}
.card__head h2 { margin: 0; }
.card__body { padding: 24px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 18px; margin-bottom: 28px; }
.stat {
    background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--purple);
    border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow);
    display: flex; align-items: center; gap: 16px;
}
.stat--gold { border-left-color: var(--gold); }
.stat--ok   { border-left-color: var(--ok); }
.stat__icon {
    width: 46px; height: 46px; border-radius: 10px; display: grid; place-items: center;
    background: var(--purple-soft); color: var(--purple); flex: none;
}
.stat__icon .ico { width: 22px; height: 22px; }
.stat b { display: block; font-size: 1.7rem; line-height: 1.1; color: var(--ink); }
.stat span { font-size: .8rem; color: var(--muted); }

/* ----------------------------------------------------------------- tables -- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .89rem; }
table.data th {
    text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .09em;
    color: var(--muted); font-weight: 600; padding: 12px 14px;
    border-bottom: 2px solid var(--line); white-space: nowrap; background: #fbfafc;
}
table.data td { padding: 13px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #fbfafc; }
table.data .thumb { width: 76px; height: 54px; object-fit: cover; border-radius: 6px; background: var(--purple-soft); }
table.data .strong { color: var(--ink); font-weight: 600; }
table.data .dim { color: var(--muted); font-size: .82rem; }
table.data .row-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
table.data audio { height: 34px; width: 230px; max-width: 100%; }

/* ---------------------------------------------------------------- buttons -- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    font-family: var(--font); font-size: .84rem; font-weight: 500;
    padding: 10px 18px; border-radius: 7px; cursor: pointer;
    border: 1px solid var(--purple); background: var(--purple); color: #fff;
    transition: background .18s, border-color .18s, color .18s;
    white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--purple-dark); border-color: var(--purple-dark); color: #fff; }
.btn .ico { width: 16px; height: 16px; }
.btn--gold  { background: var(--gold); border-color: var(--gold); color: #3a2410; }
.btn--gold:hover { background: var(--gold-dark); border-color: var(--gold-dark); color: #2c1b09; }
.btn--ghost { background: #fff; color: var(--purple); }
.btn--ghost:hover { background: var(--purple-soft); color: var(--purple); border-color: var(--purple); }
.btn--danger { background: #fff; border-color: #f0c3bf; color: var(--err); }
.btn--danger:hover { background: var(--err); border-color: var(--err); color: #fff; }
.btn--sm { padding: 6px 13px; font-size: .78rem; }
.btn--block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ------------------------------------------------------------------ forms -- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field--full { grid-column: 1 / -1; }
.field label { font-size: .82rem; font-weight: 600; color: var(--ink); }
.field .req { color: var(--purple); }
.field input, .field select, .field textarea {
    font-family: var(--font); font-size: .92rem; padding: 11px 13px; width: 100%;
    border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--body);
    transition: border-color .18s, box-shadow .18s;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: 0; border-color: var(--purple); box-shadow: 0 0 0 3px rgba(96, 52, 114, .12);
}
.field textarea { min-height: 130px; resize: vertical; line-height: 1.7; }
.field textarea.tall { min-height: 300px; }
.field small { color: var(--muted); font-size: .78rem; }
.field input[type="file"] { padding: 9px; background: #fbfafc; cursor: pointer; }

.form-actions {
    display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
    margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--line);
}

/* ------------------------------------------------ per-file upload progress -- */
.up-progress { margin: 16px 0 4px; }
.up-progress__bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.up-progress__bar b { display: block; height: 100%; width: 0; background: var(--gold); transition: width .25s ease; }
.up-progress__status { margin: 10px 0 0; font-size: .86rem; color: var(--body); }

.up-list { list-style: none; margin: 12px 0 0; padding: 0; max-height: 260px; overflow-y: auto; }
.up-item {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 8px 12px; border: 1px solid var(--line); border-radius: 7px;
    margin-bottom: 6px; font-size: .84rem; background: #fff;
}
.up-item__name { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-item__state { flex: none; font-family: var(--font); font-size: .76rem; font-weight: 600; }
.up-item--busy { border-color: var(--line); }
.up-item--busy .up-item__state { color: var(--muted); }
.up-item--ok   { border-color: #9ccfae; background: #f2faf5; }
.up-item--ok   .up-item__state { color: var(--ok); }
.up-item--fail { border-color: #e8a9a3; background: #fdf4f3; }
.up-item--fail .up-item__state { color: var(--err); }

/* ------------------------------------------------------- rich-text editor -- */
.rte { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.rte:focus-within { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(96, 52, 114, .12); }

.rte__toolbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 3px;
    padding: 8px 10px; background: #fbfafc; border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 2;
}
.rte__btn {
    display: inline-grid; place-items: center;
    min-width: 32px; height: 32px; padding: 0 7px;
    border: 1px solid transparent; border-radius: 6px;
    background: none; cursor: pointer; color: var(--ink);
    font-family: var(--font); font-size: .92rem; line-height: 1;
    transition: background .15s, border-color .15s, color .15s;
}
.rte__btn:hover { background: #fff; border-color: var(--line); }
.rte__btn.is-active { background: var(--purple); border-color: var(--purple); color: #fff; }
.rte__btn svg { width: 18px; height: 18px; fill: currentColor; }
.rte__btn i, .rte__btn b, .rte__btn u { font-size: 1rem; }
.rte__sep { width: 1px; height: 22px; background: var(--line); margin: 0 5px; }

.rte__area {
    min-height: 320px; max-height: 620px; overflow-y: auto;
    padding: 20px 22px; outline: none;
    font-family: var(--font-body, Georgia, serif); font-size: 1rem; line-height: 1.75; color: var(--body);
}
.rte__area:empty::before {
    content: "Start writing the article…"; color: var(--muted);
}

/* WYSIWYG: the editable area mirrors the public .prose styling. */
.rte__area h2 { font-family: var(--font); font-size: 1.5rem; color: var(--ink); margin: 1.2em 0 .5em; line-height: 1.3; }
.rte__area h3 { font-family: var(--font); font-size: 1.2rem; color: var(--ink); margin: 1.1em 0 .5em; line-height: 1.3; }
.rte__area p { margin: 0 0 1em; }
.rte__area ul, .rte__area ol { margin: 0 0 1em; padding-left: 1.6em; }
.rte__area li { margin-bottom: .4em; }
.rte__area a { color: var(--purple); text-decoration: underline; }
.rte__area blockquote {
    margin: 1.2em 0; padding: 4px 0 4px 20px;
    border-left: 3px solid var(--gold); font-style: italic; color: var(--ink);
}
.rte__area:focus { outline: none; }

/* ----------------------------------------------------------------- alerts -- */
.alert {
    border-radius: 8px; padding: 13px 18px; margin-bottom: 22px;
    font-size: .89rem; line-height: 1.55; border-left: 4px solid;
}
/* Bare inline content (a stray <strong>/<em>) must flow as normal text, not
   get split into flex columns — so the alert is a plain block. When an alert
   needs an icon beside its text, wrap the two in .alert__row. */
.alert__row { display: flex; gap: 10px; align-items: flex-start; }
.alert--success { background: #eaf7ee; border-color: var(--ok); color: #1d5a2f; }
.alert--error   { background: #fdecea; border-color: var(--err); color: #8b1a10; }
.alert--warn    { background: #fff8e6; border-color: var(--gold); color: #6b4a06; }
.alert--info    { background: var(--purple-soft); border-color: var(--purple); color: var(--purple-dark); }
.alert a { text-decoration: underline; }

/* ------------------------------------------------------------ media tiles -- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 18px; }
.tile { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; }
.tile__img { position: relative; aspect-ratio: 4 / 3; background: var(--purple-soft); }
.tile__img img { width: 100%; height: 100%; object-fit: cover; }
.tile__body { padding: 12px 14px; }
.tile__body b { display: block; font-size: .87rem; color: var(--ink); }
.tile__body span { font-size: .76rem; color: var(--muted); }

/* Album cover card in the gallery overview. */
.tile--album { display: block; text-decoration: none; transition: transform .2s, box-shadow .2s; }
.tile--album:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.tile--album:hover .tile__img img { transform: scale(1.05); }
.tile--album .tile__img img { transition: transform .5s; }
.tile__count {
    position: absolute; right: 8px; bottom: 8px;
    background: rgba(26, 20, 32, .8); color: #fff;
    font-family: var(--font); font-size: .72rem; font-weight: 600;
    padding: 3px 9px; border-radius: 999px;
}
.tile--album .tile__body span { color: var(--purple); font-weight: 600; }
.tile__actions { display: flex; gap: 7px; padding: 0 14px 13px; }

/* ------------------------------------------------------------------- misc -- */
.empty { text-align: center; padding: 56px 24px; color: var(--muted); }
.empty svg { width: 50px; height: 50px; fill: var(--line); margin-bottom: 12px; }
.empty h3 { color: var(--ink); }

.badge {
    display: inline-block; font-size: .7rem; padding: 3px 9px; border-radius: 999px;
    background: var(--purple-soft); color: var(--purple); font-weight: 600;
}
.badge--new { background: #fdecea; color: var(--err); }
.badge--ok  { background: #eaf7ee; color: var(--ok); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 20px; }
.toolbar input[type="search"], .toolbar select {
    font-family: var(--font); font-size: .88rem; padding: 9px 13px;
    border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--body); min-width: 200px;
}
.toolbar .spacer { flex: 1; }

.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 26px; flex-wrap: wrap; }
.pagination a, .pagination span {
    min-width: 38px; height: 38px; display: grid; place-items: center; padding: 0 11px;
    border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); font-size: .85rem;
}
.pagination .is-current { background: var(--purple); border-color: var(--purple); color: #fff; }

.progress { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; display: none; margin-top: 10px; }
.progress.is-active { display: block; }
.progress b { display: block; height: 100%; width: 0; background: var(--gold); transition: width .2s; }

.msg-body { white-space: pre-wrap; background: #fbfafc; border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; font-size: .89rem; }

/* ------------------------------------------------------------ responsive -- */
@media (max-width: 980px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 60;
        transform: translateX(-100%); transition: transform .25s ease;
    }
    .sidebar.is-open { transform: none; }
    .menu-btn { display: block; }
    .page { padding: 22px 18px 50px; }
    .topbar { padding: 14px 18px; }
}

@media (max-width: 640px) {
    .form-grid { grid-template-columns: 1fr; }
    .topbar__right span.who { display: none; }
    .card__body { padding: 18px; }
}

/*
 * List tables -> stacked cards on phones.
 *
 * A five- or six-column admin table cannot fit a 375px screen, and a
 * sideways-scrolling table hides its own action buttons. On a table marked
 * .data--cards each row becomes a self-contained card, and every cell shows
 * its column name (from the cell's data-label) above the value.
 */
@media (max-width: 720px) {
    .data--cards,
    .data--cards tbody,
    .data--cards tr,
    .data--cards td { display: block; width: 100%; }

    .data--cards thead { display: none; }

    /* The wrapper no longer needs to scroll once the table is a stack. */
    .data--cards.data--cards { }              /* (specificity anchor, no-op) */
    .table-wrap:has(.data--cards) { overflow: visible; }

    .data--cards tr {
        border: 1px solid var(--line);
        border-radius: 10px;
        background: #fff;
        padding: 6px 16px 14px;
        margin-bottom: 14px;
    }
    .data--cards tbody tr:hover { background: #fff; }

    .data--cards td {
        padding: 9px 0 0;
        border: 0;
    }
    .data--cards td::before {
        content: attr(data-label);
        display: block;
        font-size: .66rem; font-weight: 600;
        text-transform: uppercase; letter-spacing: .09em;
        color: var(--muted);
        margin-bottom: 4px;
    }
    /* Cells given an empty label (thumbnail, action buttons) carry no heading. */
    .data--cards td[data-label=""]::before { display: none; }

    /* A post's featured image becomes the card's banner. */
    .data--cards td .thumb { width: 100%; height: 170px; border-radius: 8px; }

    /* The audio player fills the card width. */
    .data--cards td audio { width: 100%; }

    /* Actions sit on their own row, divided from the details above them. */
    .data--cards td.cell-actions {
        margin-top: 12px; padding-top: 14px;
        border-top: 1px solid var(--line);
    }
    .data--cards td.cell-actions .row-actions { justify-content: flex-start; }
    .data--cards td.cell-actions .btn { flex: 1 1 auto; min-width: 96px; }

    /* The search/toolbar row stacks its controls full width. */
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar form { flex-wrap: wrap; }
    .toolbar input[type="search"], .toolbar select { min-width: 0; width: 100%; }
    .toolbar .spacer { display: none; }
}
