/* ================================================================
   app.css — shared base for all themes.
   Uses CSS custom properties defined in each theme's theme.json.
   ================================================================ */

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { color: var(--color-primary-alt); }
img { max-width: 100%; display: block; }
ul, ol { list-style: none; }
button { font-family: var(--font-sans); cursor: pointer; }

/* ── Public layout ─────────────────────────────────────────────── */
.page-wrap     { display: flex; flex-direction: column; min-height: 100vh; }
.main-content  { flex: 1; padding: 2rem 0; }
.container     { max-width: 1100px; margin: 0 auto; padding: 0 1.25rem; }
.container-sm  { max-width: 580px;  margin: 0 auto; padding: 0 1.25rem; }

/* ── Topbar (public nav) ───────────────────────────────────────── */
.topbar          { background: var(--color-surface); border-bottom: 1px solid var(--color-border); position: sticky; top: 0; z-index: 50; }
.topbar-inner    { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1.25rem; max-width: 1100px; margin: 0 auto; }
.topbar-brand    { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1rem; color: var(--color-text); }
.topbar-brand-icon { color: var(--color-primary); font-size: 1rem; }
.topbar-nav      { display: flex; gap: 1rem; align-items: center; }
.topbar-link     { font-size: .85rem; font-weight: 500; color: var(--color-text-muted); padding: .3rem .5rem; border-radius: var(--radius-sm); transition: color .15s; }
.topbar-link:hover, .topbar-link.active { color: var(--color-text); }

/* ── App shell (admin sidebar layout) ──────────────────────────── */
.sidebar {
    width: 188px;
    flex-shrink: 0;
    background: var(--color-sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 200;
    border-right: 1px solid var(--color-sidebar-border);
    transition: transform .25s cubic-bezier(.4,0,.2,1);
    overflow: hidden;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .6rem .85rem;
    border-bottom: 1px solid var(--color-sidebar-border);
    flex-shrink: 0;
}
.sidebar-logo a {
    display: flex;
    align-items: center;
    gap: .4rem;
    color: var(--color-text);
    font-size: .82rem;
    font-weight: 700;
    min-width: 0;
}
.sidebar-logo-icon { color: var(--color-primary); flex-shrink: 0; }
.sidebar-logo-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: .9rem;
    padding: .15rem;
    line-height: 1;
    flex-shrink: 0;
    cursor: pointer;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: .25rem 0 .75rem;
}
.sidebar-section {
    padding: .6rem .85rem .18rem;
    font-size: .6rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--color-sidebar-section);
}
.sidebar-group { margin-bottom: .05rem; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .3rem .85rem;
    color: var(--color-sidebar-text);
    font-size: .76rem;
    font-weight: 500;
    transition: background .12s, color .12s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-radius: 5px;
    margin: 0 5px;
}
.sidebar-nav a:hover { background: var(--color-sidebar-hover); color: var(--color-text); }
.sidebar-nav a.active { background: rgba(129,140,248,.1); color: var(--color-sidebar-active); }
.nav-icon { width: 13px; height: 13px; flex-shrink: 0; opacity: .65; }
.sidebar-nav a.active .nav-icon,
.sidebar-nav a:hover .nav-icon { opacity: 1; }

.sidebar-footer {
    padding: .55rem .85rem;
    border-top: 1px solid var(--color-sidebar-border);
    flex-shrink: 0;
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: .5rem;
    min-width: 0;
}
.sidebar-user-avatar {
    width: 24px; height: 24px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: .65rem; font-weight: 700;
    flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
    font-size: .72rem;
    font-weight: 600;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-role { font-size: .63rem; color: var(--color-text-muted); }
.sidebar-logout {
    flex-shrink: 0;
    color: var(--color-text-muted);
    opacity: .5;
    transition: opacity .15s;
    display: flex;
}
.sidebar-logout:hover { opacity: 1; color: var(--color-danger); }

/* Sidebar overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.65);
    z-index: 199;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.open { display: block; }

/* Main content area */
.app-content {
    margin-left: 188px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Admin top bar */
.admin-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .6rem 1.25rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 50;
    gap: 1rem;
}
.admin-topbar-right { display: flex; align-items: center; gap: .75rem; margin-left: auto; }
.topbar-user-chip {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .3rem .6rem .3rem .3rem;
    border-radius: 999px;
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    font-size: .8rem;
    font-weight: 500;
    transition: border-color .15s;
}
.topbar-user-chip:hover { border-color: var(--color-border-focus); color: var(--color-text); }
.topbar-user-avatar {
    width: 24px; height: 24px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: .7rem; font-weight: 700;
    flex-shrink: 0;
}
.topbar-user-name { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Hamburger */
.hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    background: none;
    border: none;
    padding: .4rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
}
.hamburger span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--color-text-muted);
    border-radius: 2px;
    transition: background .15s;
}
.hamburger:hover span,
.hamburger.active span { background: var(--color-text); }

/* Admin main */
.admin-main { flex: 1; }

/* Page header */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .75rem;
    padding: 1.25rem 1.25rem 0;
}
.page-header h1 { font-size: 1.25rem; font-weight: 700; }
.page-header p  { color: var(--color-text-muted); font-size: .82rem; margin-top: .15rem; }

/* Content padding */
.content-pad { padding: 1.25rem; }

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}
.card + .card, .card.mt-2 { margin-top: .875rem; }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.card-title { font-size: .95rem; font-weight: 600; }

/* ── Stats ─────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: .875rem;
    padding: 1.25rem 1.25rem 0;
}
.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.125rem;
    box-shadow: var(--shadow-sm);
}
.stat-label { font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--color-text-muted); }
.stat-value { font-size: 1.75rem; font-weight: 700; margin-top: .2rem; line-height: 1.2; }
.stat-sub   { font-size: .75rem; color: var(--color-text-muted); margin-top: .2rem; }

/* ── Grid helpers ──────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .875rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .875rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: .875rem; }

/* ── Tables ─────────────────────────────────────────────────────── */
.table-wrap   { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table   { width: 100%; border-collapse: collapse; font-size: .82rem; }
.data-table th {
    text-align: left;
    padding: .6rem .875rem;
    font-weight: 600;
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface-alt);
    white-space: nowrap;
}
.data-table td {
    padding: .6rem .875rem;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text);
    vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--color-surface-alt); }
.data-table .mono { font-family: var(--font-mono); font-size: .75rem; }

/* ── Forms ─────────────────────────────────────────────────────── */
.form-group  { margin-bottom: 1rem; }
.form-label  { display: block; font-size: .82rem; font-weight: 500; margin-bottom: .35rem; color: var(--color-text); }
.form-hint   { font-size: .75rem; color: var(--color-text-muted); margin-top: .25rem; }

/* Both .input and .form-input are valid — views use both */
.input, .form-input {
    display: block;
    width: 100%;
    padding: .55rem .8rem;
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: .875rem;
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
}
.input:focus, .form-input:focus {
    outline: none;
    border-color: var(--color-border-focus);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 15%, transparent);
}
textarea.input, textarea.form-input { resize: vertical; min-height: 90px; }
select.input, select.form-input     { cursor: pointer; }
.input::placeholder, .form-input::placeholder { color: var(--color-text-muted); opacity: .7; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .55rem 1.1rem;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: .82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, opacity .15s, transform .1s, box-shadow .15s;
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.4;
}
.btn:active    { transform: translateY(1px); }
.btn-primary   { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-alt); color: #fff; box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 25%, transparent); }
.btn-accent    { background: var(--color-accent); color: #000; }
.btn-accent:hover { background: var(--color-accent-alt); color: #000; }
.btn-danger    { background: var(--color-danger); color: #fff; }
.btn-danger:hover { background: var(--color-danger-alt); color: #fff; }
.btn-ghost     { background: transparent; color: var(--color-text-muted); border: 1px solid var(--color-border); }
.btn-ghost:hover { background: var(--color-surface-alt); color: var(--color-text); border-color: var(--color-border-focus); }
.btn-sm        { padding: .35rem .7rem; font-size: .76rem; }
.btn-full      { width: 100%; justify-content: center; }

/* ── Badges ─────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: .18rem .55rem;
    border-radius: 999px;
    font-size: .67rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    white-space: nowrap;
}
.badge-primary  { background: color-mix(in srgb, var(--color-primary) 15%, transparent); color: var(--color-primary); }
.badge-accent   { background: color-mix(in srgb, var(--color-accent) 15%, transparent); color: var(--color-accent-alt); }
.badge-danger   { background: color-mix(in srgb, var(--color-danger) 15%, transparent); color: var(--color-danger); }
.badge-warning  { background: color-mix(in srgb, var(--color-warning) 15%, transparent); color: var(--color-warning); }
.badge-muted    { background: var(--color-surface-alt); color: var(--color-text-muted); }
.badge-admin    { background: color-mix(in srgb, var(--color-primary) 15%, transparent); color: var(--color-primary); }
.badge-verified { background: color-mix(in srgb, var(--color-accent) 15%, transparent); color: var(--color-accent-alt); }

/* ── Alerts ─────────────────────────────────────────────────────── */
.alert {
    padding: .75rem 1rem;
    border-radius: var(--radius-md);
    border-left: 3px solid;
    font-size: .84rem;
    margin-bottom: .875rem;
    line-height: 1.5;
}
.alert-success, .alert-ok    { background: color-mix(in srgb, var(--color-accent) 10%, transparent); border-color: var(--color-accent); color: var(--color-accent-alt); }
.alert-danger,  .alert-error { background: color-mix(in srgb, var(--color-danger) 10%, transparent); border-color: var(--color-danger); color: var(--color-danger); }
.alert-info                   { background: color-mix(in srgb, var(--color-primary) 10%, transparent); border-color: var(--color-primary); color: var(--color-primary); }
.alert-warning                { background: color-mix(in srgb, var(--color-warning) 10%, transparent); border-color: var(--color-warning); color: var(--color-warning); }

/* ── Avatar / profile ───────────────────────────────────────────── */
.avatar    { width: 36px; height: 36px; border-radius: 50%; background: var(--color-primary); display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: .85rem; flex-shrink: 0; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.25rem; }
.profile-card { display: flex; align-items: flex-start; gap: 1rem; }
.profile-info h2 { font-size: 1.1rem; font-weight: 700; }
.profile-info p  { color: var(--color-text-muted); font-size: .82rem; }
.profile-meta    { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .4rem; }

/* ── Auth pages (minimal layout) ───────────────────────────────── */
.auth-wrap   { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; background: var(--color-bg); }
.auth-box    { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-xl); padding: 2rem; width: 100%; max-width: 400px; box-shadow: var(--shadow-md); }
.auth-logo   { text-align: center; margin-bottom: 1.75rem; }
.auth-logo span { font-size: 1.25rem; font-weight: 700; color: var(--color-text); }
.auth-logo .auth-icon { font-size: 2rem; color: var(--color-primary); display: block; margin-bottom: .5rem; }
.auth-title  { font-size: 1.1rem; font-weight: 700; margin-bottom: .2rem; }
.auth-sub    { color: var(--color-text-muted); font-size: .82rem; margin-bottom: 1.5rem; }
.auth-footer { text-align: center; margin-top: 1.25rem; font-size: .82rem; color: var(--color-text-muted); }

/* ── Utility ─────────────────────────────────────────────────────── */
.text-muted   { color: var(--color-text-muted); }
.text-sm      { font-size: .875rem; }
.text-xs      { font-size: .75rem; }
.text-mono    { font-family: var(--font-mono); }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.fw-600       { font-weight: 600; }
.fw-700       { font-weight: 700; }
.d-flex       { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1  { gap: .5rem; }
.gap-2  { gap: 1rem; }
.mt-1   { margin-top: .5rem; }
.mt-2   { margin-top: 1rem; }
.mt-3   { margin-top: 1.5rem; }
.mb-1   { margin-bottom: .5rem; }
.mb-2   { margin-bottom: 1rem; }
.mb-3   { margin-bottom: 1.5rem; }
.p-0    { padding: 0 !important; }
.w-full { width: 100%; }
.divider { border: none; border-top: 1px solid var(--color-border); margin: 1.25rem 0; }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--color-text-muted); }
.empty-state h3 { font-size: .95rem; font-weight: 600; margin-bottom: .4rem; color: var(--color-text); }

/* ── Theme toggle button ─────────────────────────────────────────── */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: color .15s, border-color .15s, background .15s;
    flex-shrink: 0;
}
.theme-toggle:hover {
    color: var(--color-text);
    border-color: var(--color-border-focus);
    background: var(--color-surface-alt);
}

/* ── Footer ─────────────────────────────────────────────────────── */
.footer { padding: 1rem 1.25rem; text-align: center; font-size: .75rem; color: var(--color-text-muted); border-top: 1px solid var(--color-border); }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        width: 220px;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }
    .sidebar-close { display: block; }
    .app-content   { margin-left: 0; }
    .hamburger     { display: flex; }
    .topbar-user-name { display: none; }
}

@media (max-width: 640px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .content-pad, .page-header, .stats-grid { padding-left: 1rem; padding-right: 1rem; }
    .card { padding: 1rem; }
    .auth-box { padding: 1.5rem 1.25rem; }
    .data-table th, .data-table td { padding: .5rem .75rem; }
    .page-header h1 { font-size: 1.1rem; }
    /* Public topbar wraps to two rows on narrow phones */
    .topbar-inner { flex-wrap: wrap; gap: .4rem; padding: .6rem 1rem; }
    .topbar-nav   { flex-wrap: wrap; gap: .35rem; }
}

/* ── Impersonation banner ──────────────────────────────────────── */
.impersonate-banner {
    background: #b45309;
    color: #fff;
    padding: .6rem 1.25rem;
    font-size: .85rem;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 2px solid #92400e;
}
.impersonate-banner-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}
.impersonate-stop-btn {
    background: rgba(0,0,0,.25);
    color: #fff;
    border: 1px solid rgba(255,255,255,.4);
    border-radius: 5px;
    padding: .3rem .85rem;
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s;
}
.impersonate-stop-btn:hover {
    background: rgba(0,0,0,.45);
}
