:root {
    --nav-bg: #16161e;
    --bg:     #f0f2f5;
    --card:   #ffffff;
    --accent:       #e63946;
    --accent2:      #c1121f;
    --accent-light: #fff1f2;
    --text:   #1a1a2e;
    --muted:  #6b7280;
    --border: #e5e7eb;
    --ok:     #16a34a;
    --ok-bg:  #dcfce7;
    --err:    #dc2626;
    --err-bg: #fee2e2;
    --radius: 10px;
    --ease:   0.2s ease;
}

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

/* Global hidden override — any class that sets `display` will normally beat the
   browser's built-in [hidden]{display:none}. This restores the intended behavior:
   if an element has the `hidden` attribute, it stays hidden, no matter what. */
[hidden] { display: none !important; }

body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }

/* ── TOP NAV (Creation tools only) ─────────────────────────────────────── */
.admin-nav {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; gap: 0.5rem;
    background: var(--nav-bg);
    padding: 0 1.25rem;
    height: 56px;
    overflow-x: auto;
    white-space: nowrap;
    border-bottom: 3px solid var(--accent);
}
.admin-nav::-webkit-scrollbar { display: none; }

.admin-brand {
    font-weight: 800; font-size: 1rem;
    letter-spacing: 1px; color: var(--accent);
    display: flex; align-items: center; gap: 0.5rem;
    margin-right: 1.25rem; white-space: nowrap;
}

.admin-nav-label {
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: rgba(255,255,255,0.35);
    margin-right: 0.6rem;
}

.admin-nav-links { display: flex; gap: 0.3rem; flex: 1; }

.admin-nav-links a {
    display: flex; align-items: center; gap: 0.4rem;
    padding: 0.42rem 0.85rem;
    border-radius: 6px;
    color: rgba(255,255,255,0.7);
    font-size: 0.84rem; font-weight: 600;
    transition: background var(--ease), color var(--ease);
    white-space: nowrap;
}
.admin-nav-links a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.admin-nav-links a.active { background: var(--accent); color: #fff; }

.admin-nav-right { display: flex; align-items: center; gap: 0.4rem; margin-left: auto; }

.admin-nav-right a {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
    padding: 0.4rem 0.7rem;
    border-radius: 6px;
    background: rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.75);
    font-size: 0.78rem; white-space: nowrap;
    transition: background var(--ease), color var(--ease);
}
.admin-nav-right a:hover { background: rgba(255,255,255,0.18); color: #fff; }
.admin-nav-right a.icon-only { width: 32px; padding: 0; height: 32px; }

.view-site {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.4rem 0.9rem;
    border-radius: 6px;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.75);
    font-size: 0.8rem; white-space: nowrap;
    transition: background var(--ease), color var(--ease);
}
.view-site:hover { background: rgba(255,255,255,0.2); color: #fff; }

/* ── SIDEBAR (Site Management) ────────────────────────────────────────── */
.admin-shell { display: flex; min-height: calc(100vh - 56px); }

.admin-sidebar {
    flex: 0 0 230px;
    background: #fff;
    border-right: 1px solid var(--border);
    padding: 1rem 0 2rem;
    position: sticky;
    top: 56px;
    height: calc(100vh - 56px);
    overflow-y: auto;
}
.admin-sidebar::-webkit-scrollbar { width: 6px; }
.admin-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.sb-section { padding: 0.4rem 0 0.6rem; }
.sb-section + .sb-section { border-top: 1px solid var(--border); margin-top: 0.4rem; }

.sb-section-title {
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--muted);
    padding: 0.5rem 1.25rem 0.4rem;
}

.sb-link {
    display: flex; align-items: center; gap: 0.65rem;
    padding: 0.5rem 1.25rem;
    font-size: 0.88rem;
    color: var(--text);
    border-left: 3px solid transparent;
    transition: background var(--ease), border-color var(--ease), color var(--ease);
}
.sb-link i { width: 18px; color: var(--muted); font-size: 0.92rem; flex-shrink: 0; transition: color var(--ease); }
.sb-link:hover { background: var(--bg); }
.sb-link.active {
    background: var(--accent-light, #fff1f2);
    border-left-color: var(--accent);
    color: var(--accent);
    font-weight: 700;
}
.sb-link.active i { color: var(--accent); }
.sb-badge {
    margin-left: auto;
    background: var(--accent);
    color: #fff;
    font-size: 0.66rem;
    font-weight: 800;
    padding: 0.05rem 0.45rem;
    border-radius: 9px;
}

.admin-sidebar-toggle {
    display: none;
    background: rgba(255,255,255,0.08);
    border: none;
    color: rgba(255,255,255,0.85);
    padding: 0.4rem 0.65rem;
    border-radius: 6px;
    font-size: 0.95rem;
    margin-right: 0.5rem;
    cursor: pointer;
}

/* ── MAIN ─────────────────────────────────────────────────────────────── */
.admin-main {
    flex: 1;
    min-width: 0;          /* prevent flex children from blowing out wide */
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.75rem 1.75rem 4rem;
    width: 100%;
}

/* Mobile-only "Create" sidebar section — hidden on desktop where the top nav
   shows the same links. */
.sb-section-create-mobile { display: none; }

/* ── Responsive — collapse sidebar on small screens ───────────────────── */
@media (max-width: 900px) {
    .admin-sidebar-toggle { display: inline-flex; }
    .admin-sidebar {
        position: fixed;
        top: 56px; left: 0; bottom: 0;
        flex-basis: 260px;
        width: 260px;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 49;
        box-shadow: 4px 0 20px rgba(0,0,0,0.1);
    }
    .admin-sidebar.open { transform: translateX(0); }
    .admin-main { padding: 1.25rem 1rem 3rem; }
    .admin-nav-label { display: none; }

    /* Top nav on mobile — flat single-row flex, no overflow, no sticky inner
       elements, no possibility of stacking into multiple bars.
       Creation tools move into the sidebar (see .sb-section-create-mobile). */
    .admin-nav {
        padding: 0 .65rem;
        gap: .25rem;
        overflow: visible;           /* kill horizontal scroll — nothing should overflow now */
        white-space: normal;
        flex-wrap: nowrap;
    }
    .admin-nav-links { display: none; }
    .admin-nav-label { display: none; }
    .sb-section-create-mobile { display: block; }

    .admin-brand { margin-right: auto; font-size: .9rem; letter-spacing: 0; }
    .admin-brand-text { display: none; }

    /* Right-side group — plain inline flex, no sticky/fixed positioning,
       no gradient background, no margin-left:auto (brand already pushes it). */
    .admin-nav-right {
        position: static !important;
        gap: .15rem;
        padding-left: 0;
        background: none !important;
        margin-left: 0;
        flex-shrink: 0;
    }
    .admin-nav-right a {
        padding: 0;
        width: 40px;
        height: 40px;
        justify-content: center;
        gap: 0;
    }
    .admin-nav-right a.view-site span { display: none; }

    .admin-sidebar-toggle { padding: .55rem .7rem; font-size: 1.05rem; flex-shrink: 0; }
}

/* FLASH */
.flash {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    display: flex; align-items: center; gap: 0.5rem;
}
.flash-ok  { background: var(--ok-bg);  color: var(--ok);  border: 1px solid #bbf7d0; }
.flash-err { background: var(--err-bg); color: var(--err); border: 1px solid #fecaca; }

/* PAGE TITLE */
.page-title {
    font-size: 1.5rem; font-weight: 800; margin-bottom: 2rem;
    display: flex; align-items: center; gap: 0.6rem;
}
.page-title i { color: var(--accent); }

/* CARD */
.card {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.card-title {
    font-size: 1rem; font-weight: 700; margin-bottom: 1.25rem;
    padding-bottom: 0.75rem; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 0.5rem;
}
.card-title i { color: var(--accent); }

/* FORM */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid.single { grid-template-columns: 1fr; }
.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { font-size: 0.82rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.form-group input,
.form-group textarea,
.form-group select {
    padding: 0.6rem 0.8rem;
    border: 1.5px solid var(--border);
    border-radius: 7px;
    font-size: 0.92rem;
    color: var(--text);
    background: #fff;
    transition: border-color var(--ease), box-shadow var(--ease);
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(230,57,70,0.1);
}
.form-group textarea { resize: vertical; min-height: 100px; }
.form-hint { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }

/* BUTTON */
.btn {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.6rem 1.25rem;
    border-radius: 7px;
    font-size: 0.88rem; font-weight: 600;
    border: none;
    transition: background var(--ease), transform var(--ease);
    cursor: pointer;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-ghost { background: var(--bg); color: var(--text); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--border); }
.btn-danger { background: #fee2e2; color: var(--err); border: none; font-size: 0.82rem; padding: 0.35rem 0.75rem; }
.btn-danger:hover { background: #fecaca; }

/* TABLE / ITEM LIST */
.item-list { display: flex; flex-direction: column; gap: 0.6rem; }

.item-row {
    display: flex; align-items: center; gap: 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    transition: border-color var(--ease);
}
.item-row:hover { border-color: #d1d5db; }

.item-thumb {
    width: 50px; height: 50px;
    border-radius: 6px; object-fit: cover;
    background: var(--border);
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    color: var(--muted); font-size: 1.1rem;
    overflow: hidden;
}
.item-thumb img { width: 100%; height: 100%; object-fit: cover; }

.item-info { flex: 1; min-width: 0; }
.item-name { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub  { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }

.item-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

/* DASHBOARD STATS */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
    text-decoration: none;
    color: var(--text);
    transition: border-color var(--ease), transform var(--ease), box-shadow var(--ease);
}
.stat-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 4px 20px rgba(0,0,0,0.07); }
.stat-num { font-size: 2rem; font-weight: 900; color: var(--accent); line-height: 1; margin-bottom: 0.25rem; }
.stat-icon { font-size: 1.3rem; color: var(--muted); margin-bottom: 0.5rem; }
.stat-label { font-size: 0.8rem; color: var(--muted); font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase; }

/* GALLERY GRID (photos admin) */
.admin-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
}
.ag-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 1;
    background: var(--bg);
    border: 1px solid var(--border);
}
.ag-item img { width: 100%; height: 100%; object-fit: cover; }
.ag-overlay {
    position: absolute; inset: 0;
    background: rgba(0,0,0,0.55);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.4rem;
    opacity: 0; transition: opacity var(--ease);
}
.ag-item:hover .ag-overlay { opacity: 1; }
.ag-title { font-size: 0.75rem; color: #fff; font-weight: 600; text-align: center; padding: 0 0.4rem; }

/* RESPONSIVE */
@media (max-width: 640px) {
    .form-grid { grid-template-columns: 1fr; }
    .form-group.full { grid-column: 1; }
    .admin-main { padding: 1rem 1rem 3rem; }

    /* iOS auto-zoom fix — every focusable text input must be ≥16px on mobile */
    .form-group input,
    .form-group textarea,
    .form-group select,
    input[type="text"],
    input[type="email"],
    input[type="url"],
    input[type="search"],
    input[type="number"],
    input[type="password"],
    input[type="tel"],
    input[type="date"],
    input[type="datetime-local"],
    input[type="time"],
    textarea,
    select {
        font-size: 16px !important;
    }

    /* Touch targets — bump icon-only buttons to 40×40 minimum */
    .admin-nav-right a.icon-only { width: 40px; height: 40px; }

    /* Item rows (music/videos/shows/photos lists) — allow wrap so action buttons
       can never get pushed off the right edge */
    .item-row { flex-wrap: wrap; row-gap: 0.6rem; }
    .item-info { flex: 1 1 100%; min-width: 0; }
    .item-name { white-space: normal; }   /* let long titles wrap instead of ellipsis */
    .item-actions { margin-left: auto; }

    /* Sidebar backdrop — when open, dim the rest of the page so taps outside close it */
    .admin-sidebar-backdrop {
        display: none;
        position: fixed; inset: 56px 0 0 0;
        background: rgba(0,0,0,0.5);
        z-index: 48;
    }
    .admin-sidebar.open ~ .admin-sidebar-backdrop,
    body.sidebar-open .admin-sidebar-backdrop { display: block; }
}

/* Mobile-friendly table wrapper — wrap any admin <table> in <div class="table-wrap">
   to get horizontal scroll instead of page overflow */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap > table { min-width: 600px; }
@media (max-width: 640px) {
    .admin-table, .audit-table, .db-table, .sub-table, .fd-history-table {
        font-size: 0.85rem;
    }
}

/* ── Merch admin extensions (integrated into main admin theme) ──────────── */
.admin-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.admin-stat {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.1rem 1.25rem;
}
.admin-stat__label {
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    margin-bottom: 0.4rem;
}
.admin-stat__value {
    font-size: 1.75rem;
    font-weight: 900;
    color: var(--text);
    line-height: 1;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
}
.admin-table th {
    text-align: left;
    padding: 0.6rem 0.9rem;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.admin-table td {
    padding: 0.65rem 0.9rem;
    font-size: 0.88rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--bg); }

.tag {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.tag--active   { background: #dcfce7; color: #15803d; }
.tag--inactive { background: #fef2f2; color: #b91c1c; }

/* Product/synced grids */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}
.product-tile {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: border-color 0.15s, transform 0.15s;
}
.product-tile:hover { border-color: var(--accent); transform: translateY(-2px); }
.product-tile img { width: 100%; aspect-ratio: 1; object-fit: cover; background: #f3f4f6; }
.product-tile .pt-body { padding: 0.7rem 0.85rem; flex: 1; display: flex; flex-direction: column; gap: 0.35rem; }
.product-tile .pt-title { font-weight: 700; font-size: 0.9rem; line-height: 1.3; }
.product-tile .pt-price { color: var(--accent); font-weight: 800; font-size: 0.85rem; }
.product-tile .pt-meta { font-size: 0.74rem; color: var(--muted); margin-top: auto; }
.product-tile .pt-actions { padding: 0.55rem 0.85rem; border-top: 1px solid var(--border); display: flex; gap: 0.35rem; flex-wrap: wrap; }

/* Compact button utility used inline */
.btn--small,
.btn-sm { padding: 0.35rem 0.75rem !important; font-size: 0.78rem !important; }
