/* ==========================================================================
   PCPEC UI — design system
   RTL-first, mobile-first, no framework, no external network dependency.
   Layout: header + drawer nav + main + footer.  All classes are pcpec-* or
   semantic single words used only by this file.
   ========================================================================== */

/* ---------- fonts (local) ---------- */
@font-face {
    font-family: 'IRANYekan';
    src: url('../fonts/iranyekan/woff/iranyekanweblight.woff') format('woff'),
         url('../fonts/iranyekan/ttf/iranyekanweblight.ttf') format('truetype');
    font-weight: 300;
    font-display: swap;
}
@font-face {
    font-family: 'IRANYekan';
    src: url('../fonts/iranyekan/woff/iranyekanwebregular.woff') format('woff'),
         url('../fonts/iranyekan/ttf/iranyekanwebregular.ttf') format('truetype');
    font-weight: 400;
    font-display: swap;
}
@font-face {
    font-family: 'IRANYekan';
    src: url('../fonts/iranyekan/woff/iranyekanwebmedium.woff') format('woff'),
         url('../fonts/iranyekan/ttf/iranyekanwebmedium.ttf') format('truetype');
    font-weight: 500;
    font-display: swap;
}
@font-face {
    font-family: 'IRANYekan';
    src: url('../fonts/iranyekan/woff/iranyekanwebbold.woff') format('woff'),
         url('../fonts/iranyekan/ttf/iranyekanwebbold.ttf') format('truetype');
    font-weight: 700;
    font-display: swap;
}
@font-face {
    font-family: 'IRANYekan';
    src: url('../fonts/iranyekan/woff/iranyekanwebblack.woff') format('woff'),
         url('../fonts/iranyekan/ttf/iranyekanwebblack.ttf') format('truetype');
    font-weight: 900;
    font-display: swap;
}

/* ---------- tokens ---------- */
:root {
    --font: 'IRANYekan', 'Vazirmatn', system-ui, 'Segoe UI', Tahoma, sans-serif;
    --mono: 'JetBrains Mono', 'Fira Code', Consolas, 'Courier New', monospace;

    --primary: #4f46e5;
    --primary-soft: #eef0ff;
    --primary-strong: #4338ca;
    --success: #16a34a;
    --success-soft: #e6f7ec;
    --warning: #d97706;
    --warning-soft: #fdf3e3;
    --danger: #dc2626;
    --danger-soft: #fdeaea;
    --info: #0284c7;
    --info-soft: #e6f4fd;
    --gold: #f0b429;

    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e3e8f0;
    --text: #1c2431;
    --muted: #64748b;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px -12px rgba(16, 24, 40, .14);
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
    --radius: 14px;
    --radius-sm: 10px;
    --radius-xs: 8px;
    --header-h: 60px;
    --page-max: 1180px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --primary: #8b8cf7;
        --primary-soft: #23233a;
        --primary-strong: #a5a6ff;
        --success: #4ade80;
        --success-soft: #16281d;
        --warning: #fbbf24;
        --warning-soft: #2b2314;
        --danger: #f87171;
        --danger-soft: #2c1919;
        --info: #38bdf8;
        --info-soft: #12242e;
        --bg: #0f1420;
        --surface: #171d2b;
        --surface-2: #1d2434;
        --border: #2a3346;
        --text: #e7ecf5;
        --muted: #98a3b8;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px -14px rgba(0, 0, 0, .6);
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
    }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.75;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

h1, h2, h3, h4, h5, h6 { margin: 0 0 .6rem; line-height: 1.5; font-weight: 700; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.12rem; }
h4 { font-size: 1rem; }
h5 { font-size: .95rem; }
p { margin: 0 0 .8rem; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-strong); text-decoration: underline; }
img { max-width: 100%; height: auto; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
small { font-size: .82rem; }
button, input, select, textarea { font: inherit; color: inherit; }
ul, ol { margin: 0 0 .8rem; padding-inline-start: 1.2rem; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- layout ---------- */
.skip-link {
    position: absolute; inset-inline-start: -9999px; top: 0; z-index: 100;
    background: var(--surface); padding: .5rem 1rem; border-radius: var(--radius-xs);
}
.skip-link:focus { inset-inline-start: .5rem; top: .5rem; }

.app-header {
    position: sticky; top: 0; z-index: 50;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.app-header-inner {
    max-width: var(--page-max); margin: 0 auto;
    min-height: var(--header-h);
    display: flex; align-items: center; gap: .5rem;
    padding: .4rem 1rem;
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 900; font-size: 1.1rem; color: var(--text); }
.brand:hover { text-decoration: none; color: var(--primary); }
.brand-mark {
    width: 32px; height: 32px; border-radius: 10px; flex: 0 0 auto;
    background: linear-gradient(135deg, var(--primary), #22d3ee);
    display: grid; place-items: center; color: #fff; font-size: .85rem; font-weight: 900;
    box-shadow: var(--shadow-sm);
}
.brand-sub { font-size: .68rem; font-weight: 400; color: var(--muted); display: block; margin-top: -6px; }

.main-nav { display: flex; align-items: center; gap: .15rem; margin-inline-start: 1rem; }
.main-nav a {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .45rem .7rem; border-radius: var(--radius-xs);
    color: var(--text); font-size: .92rem; white-space: nowrap;
}
.main-nav a:hover { background: var(--surface-2); text-decoration: none; }
.main-nav a.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 500; }
.nav-count {
    font-size: .7rem; padding: 0 .35rem; border-radius: 999px;
    background: var(--primary-soft); color: var(--primary); font-weight: 700;
}

.header-actions { margin-inline-start: auto; display: flex; align-items: center; gap: .35rem; }
.icon-btn {
    display: inline-grid; place-items: center; position: relative;
    width: 38px; height: 38px; border-radius: 50%;
    background: transparent; border: 1px solid transparent; color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border); text-decoration: none; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-dot {
    position: absolute; top: 4px; inset-inline-end: 4px;
    min-width: 18px; height: 18px; padding: 0 4px; border-radius: 999px;
    background: var(--danger); color: #fff; font-size: .68rem; font-weight: 700;
    display: grid; place-items: center; line-height: 1;
}
.user-chip {
    display: inline-flex; align-items: center; gap: .5rem;
    border: 1px solid var(--border); background: var(--surface);
    border-radius: 999px; padding: .25rem .35rem .25rem .65rem; cursor: pointer; color: var(--text);
}
.user-chip:hover { border-color: var(--primary); text-decoration: none; }
.avatar {
    width: 28px; height: 28px; border-radius: 50%; flex: 0 0 auto;
    display: grid; place-items: center; font-weight: 700; font-size: .78rem;
    background: var(--primary-soft); color: var(--primary); text-transform: uppercase;
}
.user-chip-name { font-size: .85rem; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* dropdown (CSS + tiny JS) */
.dropdown { position: relative; }
.dropdown-panel {
    position: absolute; inset-inline-end: 0; top: calc(100% + 8px); z-index: 60;
    min-width: 260px; max-width: min(92vw, 380px);
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: .4rem; display: none;
}
.dropdown.is-open .dropdown-panel { display: block; }
.dropdown-item {
    display: flex; align-items: center; gap: .5rem; width: 100%;
    padding: .5rem .6rem; border-radius: var(--radius-xs);
    background: none; border: 0; text-align: start; color: var(--text); cursor: pointer; font-size: .9rem;
}
.dropdown-item:hover { background: var(--surface-2); text-decoration: none; }
.dropdown-sep { height: 1px; background: var(--border); margin: .35rem .2rem; }
.dropdown-head { padding: .4rem .6rem; font-size: .8rem; color: var(--muted); font-weight: 500; }
.dropdown-scroll { max-height: 60vh; overflow: auto; }
.notif-item { display: block; padding: .55rem .6rem; border-radius: var(--radius-xs); color: var(--text); }
.notif-item:hover { background: var(--surface-2); text-decoration: none; }
.notif-item .notif-title { font-weight: 500; font-size: .88rem; margin: 0; }
.notif-item .notif-body {
    margin: .15rem 0 0; font-size: .8rem; color: var(--muted);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.notif-item .notif-time { font-size: .72rem; color: var(--muted); }

/* mobile drawer — hidden entirely until the phone/tablet breakpoint */
.drawer-toggle { display: none; }
.drawer, .drawer-scrim { display: none; }
.drawer {
    position: fixed; inset-block: 0; inset-inline-end: 0; z-index: 80;
    width: min(80vw, 286px);
    background: var(--surface);
    border-inline-start: 1px solid var(--border);
    box-shadow: var(--shadow);
    transform: translateX(-100%);
    transition: transform .24s cubic-bezier(.22, .61, .36, 1);
    flex-direction: column; gap: .1rem;
    padding: .85rem .8rem calc(.9rem + env(safe-area-inset-bottom));
    overflow-y: auto; overscroll-behavior: contain;
}
html[dir="rtl"] .drawer { transform: translateX(100%); }
body.drawer-open .drawer { transform: translateX(0); }
body.drawer-open { overflow: hidden; }

.drawer-scrim {
    position: fixed; inset: 0; z-index: 70;
    background: rgba(15, 20, 32, .45);
    backdrop-filter: blur(2px);
    opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
body.drawer-open .drawer-scrim { opacity: 1; pointer-events: auto; }

.drawer-head {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    padding-bottom: .7rem; margin-bottom: .3rem; border-bottom: 1px solid var(--border);
}
.drawer .brand { font-size: 1rem; }
.drawer .brand-mark { width: 28px; height: 28px; border-radius: 9px; font-size: .76rem; }
.drawer .main-nav { flex-direction: column; align-items: stretch; margin: 0; gap: .1rem; }
.drawer .main-nav a,
.drawer .main-nav .dropdown-item {
    display: flex; align-items: center; gap: .6rem; width: 100%;
    padding: .55rem .5rem; border-radius: 10px; font-size: .95rem; white-space: normal;
}
.drawer .main-nav a > svg,
.drawer .main-nav .dropdown-item > svg {
    flex: 0 0 auto; width: 32px; height: 32px; padding: .34rem;
    border-radius: 9px; background: var(--surface-2); color: var(--muted);
}
.drawer .main-nav a.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.drawer .main-nav a.is-active > svg {
    background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary);
}
.drawer-section {
    font-size: .72rem; font-weight: 600; color: var(--muted);
    padding: .85rem .5rem .25rem;
}
.drawer form { margin-top: auto; padding-top: .5rem; }
.drawer .btn { width: 100%; justify-content: center; }

.page {
    width: 100%; max-width: var(--page-max); margin: 0 auto;
    padding: 1.1rem 1rem 2.5rem; flex: 1 1 auto;
}
.page-head { margin-bottom: 1rem; }
.page-head h1, .page-head h2 { margin-bottom: .15rem; }
.page-sub { color: var(--muted); font-size: .9rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .7rem; }

.breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; font-size: .84rem; color: var(--muted); margin-bottom: .8rem; }
.breadcrumb a { color: var(--muted); }
.breadcrumb span.sep { opacity: .55; }

.app-footer {
    border-top: 1px solid var(--border); background: var(--surface);
    color: var(--muted); font-size: .8rem;
}
.app-footer-inner {
    max-width: var(--page-max); margin: 0 auto; padding: .8rem 1rem;
    display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between;
}

/* ---------- grid & stack ---------- */
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.span-2 { grid-column: span 2; }
.row { display: flex; flex-wrap: wrap; gap: 1rem; }
.row > * { min-width: 0; }
.flex { display: flex; gap: .5rem; align-items: center; }
.flex-col { display: flex; flex-direction: column; gap: .5rem; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }

@media (max-width: 900px) {
    .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
    .span-2 { grid-column: span 1; }
    .page { padding: .9rem .75rem 2rem; }
}

/* ---------- card ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: clip;
}
.card-head {
    padding: .8rem 1rem; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
    background: var(--surface);
}
.card-head h2, .card-head h3, .card-head h4 { margin: 0; }
.card-head .card-head-actions { margin-inline-start: auto; display: flex; gap: .4rem; flex-wrap: wrap; }
.card-body { padding: 1rem; }
.card-body-tight { padding: .6rem .8rem; }
.card-foot { padding: .7rem 1rem; border-top: 1px solid var(--border); background: var(--surface-2); }
.card-flush > .card-body { padding: 0; }

.stat { display: flex; align-items: center; gap: .8rem; }
.stat-value { font-size: 1.5rem; font-weight: 900; line-height: 1.2; }
.stat-label { font-size: .82rem; color: var(--muted); }
.stat-icon {
    width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex: 0 0 auto;
    background: var(--primary-soft); color: var(--primary);
}
.stat-icon svg { width: 20px; height: 20px; }
.stat-icon.ok { background: var(--success-soft); color: var(--success); }
.stat-icon.warn { background: var(--warning-soft); color: var(--warning); }
.stat-icon.bad { background: var(--danger-soft); color: var(--danger); }
.stat-icon.info { background: var(--info-soft); color: var(--info); }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .5rem .9rem; border-radius: var(--radius-xs);
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    font-size: .9rem; font-weight: 500; cursor: pointer; line-height: 1.6;
    transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); color: #fff; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { color: #fff; filter: brightness(.95); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { color: #fff; filter: brightness(.95); }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn-warning:hover { color: #fff; filter: brightness(.95); }
.btn-info { background: var(--info); border-color: var(--info); color: #fff; }
.btn-info:hover { color: #fff; filter: brightness(.95); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-outline { background: transparent; border-color: var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary-soft); }
.btn-sm { padding: .25rem .55rem; font-size: .82rem; border-radius: var(--radius-xs); }
.btn-lg { padding: .7rem 1.3rem; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-icon { padding: .35rem; }
.btn-icon svg { width: 18px; height: 18px; }
.btn-group { display: inline-flex; flex-wrap: wrap; gap: .4rem; }

/* ---------- badges & pills ---------- */
.badge {
    display: inline-flex; align-items: center; gap: .25rem;
    padding: .1rem .5rem; border-radius: 999px;
    font-size: .76rem; font-weight: 500; line-height: 1.7;
    background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge-primary { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge-gold { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-lg { font-size: .85rem; padding: .25rem .7rem; }

.state {
    display: inline-block; padding: .05rem .55rem; border-radius: 999px;
    font-size: .78rem; font-weight: 500; white-space: nowrap;
}
.state-success { background: var(--success-soft); color: var(--success); }
.state-danger { background: var(--danger-soft); color: var(--danger); }
.state-info { background: var(--info-soft); color: var(--info); }
.state-warning { background: var(--warning-soft); color: var(--warning); }
.state-muted { background: var(--surface-2); color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: .6rem .7rem; text-align: start; vertical-align: top; border-bottom: 1px solid var(--border); }
.table thead th {
    background: var(--surface-2); color: var(--muted); font-weight: 500; font-size: .82rem;
    white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table-flat td, .table-flat th { border: 0; }
.table-num { font-variant-numeric: tabular-nums; }
.table-compact th, .table-compact td { padding: .35rem .5rem; }
.tr-success { background: var(--success-soft) !important; }
.tr-danger { background: var(--danger-soft) !important; }
.tr-warning { background: var(--warning-soft) !important; }
.tr-info { background: var(--info-soft) !important; }
.record { font-weight: 700; }

/* ---------- forms ---------- */
.field { margin-bottom: .9rem; }
.field > label, .label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: .3rem; }
.input, .select, .textarea,
input[type="text"], input[type="password"], input[type="email"], input[type="number"],
input[type="search"], input[type="url"], select, textarea {
    width: 100%; padding: .5rem .7rem; border: 1px solid var(--border); border-radius: var(--radius-xs);
    background: var(--surface); color: var(--text); font-family: inherit; font-size: .92rem;
}
textarea { min-height: 90px; resize: vertical; }
.input:focus, select:focus, textarea:focus, input:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.input-sm { width: auto; min-width: 4rem; padding: .25rem .45rem; font-size: .85rem; }
.hint, .help { font-size: .78rem; color: var(--muted); margin-top: .25rem; }
.error-text { font-size: .82rem; color: var(--danger); margin-top: .25rem; }
.form-inline { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.form-inline .field { margin-bottom: 0; min-width: 160px; }
.check { display: inline-flex; align-items: center; gap: .35rem; font-size: .88rem; cursor: pointer; }
.check input[type="checkbox"], .check input[type="radio"] { width: auto; margin: 0; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .8rem 1rem; margin: 0 0 .9rem; }
legend { font-size: .85rem; color: var(--muted); padding: 0 .3rem; }
.range-toggle { display: flex; flex-wrap: wrap; gap: .6rem; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.seg label { padding: .3rem .8rem; font-size: .85rem; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:checked + span { background: var(--primary); color: #fff; }
.seg span { display: inline-block; padding: .3rem .8rem; }
.multiselect { min-height: 8rem; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tabs [role="tab"] {
    padding: .5rem .85rem; border: 0; background: none; cursor: pointer;
    color: var(--muted); font-size: .92rem; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs [role="tab"]:hover { color: var(--text); }
.tabs [role="tab"][aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }
.tab-panel[hidden] { display: none; }

/* ---------- alerts & messages ---------- */
.alert {
    border: 1px solid var(--border); border-inline-start: 4px solid var(--muted);
    background: var(--surface); border-radius: var(--radius-sm);
    padding: .6rem .9rem; margin-bottom: .7rem; font-size: .9rem;
    display: flex; gap: .5rem; align-items: flex-start;
}
.alert p:last-child, .alert pre:last-child { margin-bottom: 0; }
.alert-success { border-inline-start-color: var(--success); background: var(--success-soft); }
.alert-error, .alert-danger { border-inline-start-color: var(--danger); background: var(--danger-soft); }
.alert-warning { border-inline-start-color: var(--warning); background: var(--warning-soft); }
.alert-info { border-inline-start-color: var(--info); background: var(--info-soft); }
.alert-debug { border-inline-start-color: var(--primary); background: var(--primary-soft); }
.alert-close { margin-inline-start: auto; background: none; border: 0; cursor: pointer; color: var(--muted); font-size: 1.1rem; line-height: 1; }

/* ---------- progress ---------- */
.ring {
    --p: 0;
    --ring-color: var(--primary);
    width: 128px; height: 128px; border-radius: 50%; flex: 0 0 auto;
    background: conic-gradient(var(--ring-color) calc(var(--p) * 1%), var(--border) 0);
    display: grid; place-items: center; position: relative;
}
.ring::before {
    content: ''; position: absolute; inset: 10px; border-radius: 50%; background: var(--surface);
}
.ring-inner { position: relative; text-align: center; line-height: 1.3; }
.ring-value { font-size: 1.35rem; font-weight: 900; }
.ring-label { font-size: .72rem; color: var(--muted); }
.ring-sm { width: 84px; height: 84px; }
.ring-sm::before { inset: 7px; }
.ring-sm .ring-value { font-size: 1rem; }
.ring-sm .ring-label { font-size: .62rem; }
.ring-success { --ring-color: var(--success); }
.ring-warning { --ring-color: var(--warning); }
.ring-danger { --ring-color: var(--danger); }

.meter { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width .4s ease; }
.meter-success > span { background: var(--success); }
.meter-warning > span { background: var(--warning); }
.meter-danger > span { background: var(--danger); }
.meter-row { display: flex; align-items: center; gap: .6rem; }
.meter-row .meter { flex: 1 1 auto; }

.spark { display: flex; align-items: flex-end; gap: 3px; height: 46px; }
.spark > i { display: block; flex: 1 1 0; min-width: 4px; border-radius: 3px 3px 0 0; background: var(--primary); opacity: .85; }
.spark > i.ok { background: var(--success); }
.spark > i.bad { background: var(--danger); }

/* ---------- code ---------- */
.code, pre, code, kbd {
    font-family: var(--mono); font-size: .85rem;
}
pre {
    margin: 0 0 .6rem; padding: .7rem .8rem; border-radius: var(--radius-sm);
    background: var(--surface-2); border: 1px solid var(--border);
    white-space: pre-wrap; overflow-wrap: anywhere; direction: ltr; text-align: left;
}
pre code { font-size: inherit; }
.code-dark { background: #11161f; color: #e6edf3; border-color: #11161f; }
.code-dark .dim { color: #8b98a9; }
code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: .05rem .3rem; }
.code-block { position: relative; }
.code-block .code-actions { position: absolute; top: .35rem; inset-inline-end: .35rem; }
.code-block textarea {
    font-family: var(--mono); direction: ltr; text-align: left; font-size: .85rem;
    background: #11161f; color: #e6edf3; border-color: #11161f; min-height: 200px;
}
.code-block textarea.correct-code { background: #0d2f14; color: #d8f3dc; }
.ace-host { border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); }
.ace_editor { direction: ltr; }

/* ---------- problem nav chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
    display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
    min-width: 40px; padding: .3rem .6rem; border-radius: var(--radius-xs);
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    font-size: .85rem; font-weight: 500; white-space: nowrap;
}
.chip:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.chip-success { background: var(--success); border-color: var(--success); color: #fff; }
.chip-success:hover { color: #fff; }
.chip-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.chip-danger:hover { color: #fff; }
.chip-warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.chip-warning:hover { color: #fff; }
.chip-info { background: var(--info); border-color: var(--info); color: #fff; }
.chip-info:hover { color: #fff; }
.chip-current {
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary);
    font-weight: 700;
}

/* ---------- verdict banner ---------- */
.verdict { display: flex; align-items: center; gap: .8rem; padding: .8rem 1rem; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2); }
.verdict-icon { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-size: 1.4rem; flex: 0 0 auto; background: var(--surface); }
.verdict-title { font-weight: 700; }
.verdict-note { font-size: .85rem; color: var(--muted); }
.verdict-ok { background: var(--success-soft); border-color: transparent; }
.verdict-ok .verdict-icon { background: var(--success); color: #fff; }
.verdict-bad { background: var(--danger-soft); border-color: transparent; }
.verdict-bad .verdict-icon { background: var(--danger); color: #fff; }
.verdict-work { background: var(--warning-soft); border-color: transparent; }
.verdict-work .verdict-icon { background: var(--warning); color: #fff; }
.pop { animation: pcpec-pop .35s ease; }
@keyframes pcpec-pop {
    0% { transform: scale(.96); opacity: .4; }
    60% { transform: scale(1.02); }
    100% { transform: scale(1); opacity: 1; }
}

/* ---------- feed ---------- */
.feed { list-style: none; margin: 0; padding: 0; }
.feed > li { display: flex; gap: .7rem; padding: .55rem 0; border-bottom: 1px dashed var(--border); }
.feed > li:last-child { border-bottom: 0; }
.feed-time { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.feed-body { min-width: 0; }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 1.6rem 1rem; color: var(--muted); }
.empty-icon { font-size: 2rem; display: block; margin-bottom: .4rem; }

/* ---------- auth pages ---------- */
.auth-shell {
    flex: 1 1 auto; display: grid; place-items: center; padding: 1.5rem 1rem;
    background:
        radial-gradient(1200px 500px at 100% -10%, color-mix(in srgb, var(--primary) 14%, transparent), transparent),
        radial-gradient(900px 400px at 0% 110%, color-mix(in srgb, var(--info) 12%, transparent), transparent),
        var(--bg);
}
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.6rem 1.4rem; }
.auth-brand { text-align: center; margin-bottom: 1.1rem; }
.auth-brand .brand-mark { width: 52px; height: 52px; font-size: 1.15rem; margin: 0 auto .5rem; border-radius: 16px; }
.auth-brand h1 { font-size: 1.4rem; margin-bottom: .1rem; }
.auth-brand p { color: var(--muted); font-size: .84rem; margin: 0; }
.auth-alt { text-align: center; margin-top: .9rem; font-size: .88rem; color: var(--muted); }

/* ---------- ranking ---------- */
.rank { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; font-weight: 700; font-size: .82rem; background: var(--surface-2); color: var(--muted); }
.rank-1 { background: linear-gradient(135deg, #f7c948, #f0a500); color: #3d2b00; }
.rank-2 { background: linear-gradient(135deg, #dfe6ef, #b9c4d2); color: #22303f; }
.rank-3 { background: linear-gradient(135deg, #e8bf94, #c98d4e); color: #35200a; }
.rank-me { box-shadow: 0 0 0 2px var(--primary); }
tr.is-me td { background: var(--primary-soft) !important; font-weight: 500; }

/* ---------- pager ---------- */
.pager { display: flex; flex-wrap: wrap; gap: .3rem; justify-content: center; padding: .8rem 0 .2rem; }
.pager-link {
    display: inline-grid; place-items: center; min-width: 34px; height: 34px; padding: 0 .5rem;
    border: 1px solid var(--border); border-radius: var(--radius-xs); color: var(--text); font-size: .85rem;
}
.pager-link:hover { background: var(--surface-2); text-decoration: none; }
.pager-link.is-active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }
.pager-gap { align-self: center; color: var(--muted); }

/* ---------- misc helpers ---------- */
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.tiny { font-size: .74rem; }
.bold { font-weight: 700; }
.center { text-align: center; }
.end { text-align: end; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ltr { direction: ltr; text-align: left; }
.auto { direction: auto; }
.pre-wrap { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- rendered markdown (problem statements) ---------- */
.markdown-body { white-space: normal; overflow-wrap: anywhere; }
.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body p { margin: 0 0 .7rem; }
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
    margin: 1.1rem 0 .5rem; line-height: 1.5; font-weight: 700;
}
.markdown-body h1 { font-size: 1.35rem; }
.markdown-body h2 { font-size: 1.2rem; }
.markdown-body h3 { font-size: 1.08rem; }
.markdown-body h4, .markdown-body h5, .markdown-body h6 { font-size: 1rem; }
.markdown-body h1, .markdown-body h2 {
    padding-bottom: .3rem; border-bottom: 1px solid var(--border);
}
.markdown-body ul, .markdown-body ol { margin: 0 0 .7rem; padding-inline-start: 1.6rem; }
.markdown-body li { margin: .2rem 0; }
.markdown-body li > ul, .markdown-body li > ol { margin: .2rem 0; }
.markdown-body a { color: var(--primary); text-decoration: underline; text-underline-offset: 2px; }
.markdown-body a:hover { color: var(--primary-strong); }
.markdown-body strong { font-weight: 700; }
.markdown-body blockquote {
    margin: 0 0 .7rem; padding: .4rem .9rem; color: var(--muted);
    background: var(--surface-2); border-inline-start: 3px solid var(--border);
    border-radius: var(--radius-xs);
}
.markdown-body blockquote > :last-child { margin-bottom: 0; }
.markdown-body hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
.markdown-body img { max-width: 100%; height: auto; border-radius: var(--radius-xs); }
.markdown-body table {
    width: auto; max-width: 100%; margin: 0 0 .7rem; border-collapse: collapse;
    display: block; overflow-x: auto;
}
.markdown-body th, .markdown-body td {
    padding: .35rem .6rem; border: 1px solid var(--border); text-align: start;
}
.markdown-body th { background: var(--surface-2); font-weight: 700; }
.markdown-body pre { margin: 0 0 .7rem; }
.markdown-body code { font-size: .85rem; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; }
.gap-1 { gap: .5rem; } .gap-2 { gap: 1rem; }
.hide { display: none !important; }
.scroll-x { overflow-x: auto; }
.divider { height: 1px; background: var(--border); margin: 1rem 0; }
.pill-row { display: flex; flex-wrap: wrap; gap: .35rem; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain > li { padding: .35rem 0; border-bottom: 1px dashed var(--border); }
.list-plain > li:last-child { border-bottom: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .2rem .8rem; font-size: .88rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.only-mobile { display: none; }
@media (max-width: 860px) {
    .only-desktop { display: none !important; }
    .only-mobile { display: initial; }
    .drawer-toggle { display: inline-grid; }
    .main-nav.only-desktop { display: none; }
    .brand-sub { display: none; }
}

/* ---------- mobile / touch polish ---------- */
html { -webkit-text-size-adjust: 100%; }
pre { max-width: 100%; overflow-x: auto; }

.countdown { font-variant-numeric: tabular-nums; font-weight: 600; }
.countdown.is-urgent { color: var(--danger); }
.countdown.is-over { color: var(--muted); font-weight: 400; }

/* notched phones: keep content clear of the rounded corners */
@supports (padding: max(0px)) {
    .app-header-inner, .app-footer-inner {
        padding-inline-start: max(1rem, env(safe-area-inset-right));
        padding-inline-end: max(1rem, env(safe-area-inset-left));
    }
    .page {
        padding-inline-start: max(.8rem, env(safe-area-inset-right));
        padding-inline-end: max(.8rem, env(safe-area-inset-left));
    }
}

@media (max-width: 860px) {
    /* 16px form controls stop iOS Safari from zooming the page on focus */
    input:not([type="checkbox"]):not([type="radio"]), select, textarea,
    .input-sm, .select-sm, .textarea, .ace_text-input { font-size: 16px !important; }

    /* finger-sized targets */
    .icon-btn { width: 44px; height: 44px; }
    .btn { min-height: 44px; }
    .btn-sm { min-height: 38px; padding: .45rem .7rem; }
    .main-nav a { padding: .7rem .8rem; }
    .pager-link { min-width: 40px; height: 40px; }
    .dropdown-item { padding: .7rem .6rem; }
    /* the off-canvas drawer only exists on small screens */
    .drawer { display: flex; }
    .drawer-scrim { display: block; }

    /* tab strips scroll sideways instead of wrapping into rows */
    .tabs { flex-wrap: nowrap; overflow-x: auto; }
    .tabs > * { white-space: nowrap; }

    /* denser tables so more columns fit before scrolling */
    .table { font-size: .86rem; }
    .table th, .table td { padding: .5rem .55rem; }
    .table-compact th, .table-compact td { padding: .4rem .45rem; }
    /* links inside cells need a finger-sized hit area */
    .table td a { display: inline-block; padding-block: .3rem; }

    .form-inline .field { min-width: 100%; }
    .kv { grid-template-columns: auto 1fr; }
    .row { gap: .75rem; }
}

@media (max-width: 620px) {
    /* dropdown panels become top-anchored sheets on small phones */
    .dropdown-panel {
        position: fixed; inset-inline: .5rem; top: calc(var(--header-h) + .4rem);
        min-width: 0; max-width: none; max-height: 70vh; overflow: auto;
    }
    .user-chip-name { max-width: 84px; }
    .page-head h1 { font-size: 1.25rem; }
    .card-body, .card-head, .card-foot { padding-inline: .7rem; }
    .btn-group { width: 100%; }
    .btn-group .btn { flex: 1 1 auto; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@media print {
    .app-header, .app-footer, .drawer, .drawer-scrim, .btn { display: none !important; }
    body { background: #fff; }
}