/* HTStore Admin */

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('/fonts/inter-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
        U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
        U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('/fonts/inter-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
        U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF,
        U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ─── Tokens ─── */
:root {
    /* Surfaces — a near-black ramp, each step one notch lighter */
    --bg: #08080a;
    --surface: #0e0e11;
    --surface-2: #141418;
    --surface-3: #1b1b21;
    --surface-hover: #1f1f26;

    /* Lines */
    --line: #212127;
    --line-strong: #2c2c34;

    /* Ink */
    --ink: #ececf1;
    --ink-2: #a6a6b2;
    --ink-3: #74747f;
    --ink-4: #52525c;

    /* Accent */
    --accent: #6d5efc;
    --accent-hi: #8577ff;
    --accent-ghost: rgba(109, 94, 252, 0.13);
    --accent-line: rgba(109, 94, 252, 0.32);

    /* Semantic */
    --ok: #34d399;
    --ok-ghost: rgba(52, 211, 153, 0.12);
    --warn: #fbbf24;
    --warn-ghost: rgba(251, 191, 36, 0.12);
    --bad: #f87171;
    --bad-ghost: rgba(248, 113, 113, 0.12);

    /* Type */
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;

    /* Radius */
    --r-sm: 6px;
    --r-md: 9px;
    --r-lg: 13px;
    --r-xl: 18px;
    --r-pill: 999px;

    /* Space */
    --s1: 4px;
    --s2: 8px;
    --s3: 12px;
    --s4: 16px;
    --s5: 22px;
    --s6: 30px;
    --s7: 44px;

    /* Elevation — a dark UI reads depth from light, not shadow alone */
    --e1: 0 1px 2px rgba(0, 0, 0, 0.5);
    --e2: 0 4px 16px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.5);
    --e3: 0 18px 50px rgba(0, 0, 0, 0.62), 0 2px 8px rgba(0, 0, 0, 0.5);

    --sidebar-w: 236px;
    --topbar-h: 60px;
}

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

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

button {
    background: none;
    border: none;
    cursor: pointer;
}

svg {
    display: block;
}

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

/* Money and counts must align on the decimal down a column. */
.num,
.money,
.stat-value,
.cell-amount {
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum' 1;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--surface-3);
    border-radius: var(--r-pill);
    border: 2px solid var(--bg);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--line-strong);
}

/* Visible focus everywhere — this is a money console, not a landing page. */
:focus-visible {
    outline: 2px solid var(--accent-hi);
    outline-offset: 2px;
    border-radius: var(--r-sm);
}

:focus:not(:focus-visible) {
    outline: none;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ═══ Login ═══ */
.login-wrapper {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--s4);
    background: var(--bg);
    z-index: 100;
}

/* Two offset radial washes give the backdrop depth without an image. */
.login-mesh {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(680px circle at 22% 18%, rgba(109, 94, 252, 0.16), transparent 62%),
        radial-gradient(520px circle at 82% 78%, rgba(52, 211, 153, 0.07), transparent 58%);
    pointer-events: none;
}

.login-card {
    position: relative;
    width: 100%;
    max-width: 384px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-xl);
    padding: var(--s6);
    box-shadow: var(--e3);
}

.login-brand-logo {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    background: var(--accent);
    color: #fff;
    border-radius: var(--r-md);
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.02em;
    margin-bottom: var(--s5);
    box-shadow: 0 0 0 1px var(--accent-line), 0 8px 22px rgba(109, 94, 252, 0.3);
}

.login-card h1 {
    font-size: 21px;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: var(--s1);
}

.login-card .subtitle {
    color: var(--ink-3);
    font-size: 13px;
    margin-bottom: var(--s6);
}

.login-error {
    display: none;
    align-items: center;
    gap: var(--s2);
    background: var(--bad-ghost);
    border: 1px solid rgba(248, 113, 113, 0.28);
    color: #fca5a5;
    padding: var(--s3);
    border-radius: var(--r-md);
    font-size: 13px;
    margin-bottom: var(--s4);
}

.login-error.visible {
    display: flex;
}

.login-foot {
    margin-top: var(--s5);
    padding-top: var(--s4);
    border-top: 1px solid var(--line);
    font-size: 11.5px;
    color: var(--ink-4);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ═══ Layout ═══ */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
}

.sidebar-brand {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    padding: 0 var(--s4);
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.brand-logo-container {
    display: flex;
    align-items: center;
    gap: var(--s3);
}

.brand-logo-square {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    background: var(--accent);
    color: #fff;
    border-radius: var(--r-sm);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}

.sidebar-brand-content h2 {
    font-size: 13.5px;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.brand-sub {
    font-size: 10.5px;
    color: var(--ink-4);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-weight: 500;
}

.sidebar-nav {
    list-style: none;
    padding: var(--s3) var(--s2);
    flex: 1;
    overflow-y: auto;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--ink-4);
    padding: var(--s4) var(--s3) var(--s2);
}

.sidebar-nav li:first-child .nav-section-label {
    padding-top: var(--s1);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--s3);
    padding: 8px var(--s3);
    border-radius: var(--r-sm);
    color: var(--ink-2);
    font-size: 13.5px;
    cursor: pointer;
    width: 100%;
    text-align: left;
    position: relative;
    transition: background 0.12s ease, color 0.12s ease;
}

.nav-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.72;
}

.nav-item:hover {
    background: var(--surface-2);
    color: var(--ink);
}

.nav-item:hover svg {
    opacity: 1;
}

.nav-item.active {
    background: var(--accent-ghost);
    color: var(--ink);
    font-weight: 500;
}

.nav-item.active svg {
    opacity: 1;
    color: var(--accent-hi);
}

/* Left rail marker — faster to scan than a full-bleed highlight. */
.nav-item.active::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 2px;
    height: 17px;
    background: var(--accent-hi);
    border-radius: 0 2px 2px 0;
}

.nav-badge {
    margin-left: auto;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--ink-3);
    background: var(--surface-3);
    padding: 1px 6px;
    border-radius: var(--r-pill);
    font-variant-numeric: tabular-nums;
}

.sidebar-footer {
    padding: var(--s3);
    border-top: 1px solid var(--line);
    flex-shrink: 0;
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: var(--s3);
    width: 100%;
    padding: 8px var(--s3);
    border-radius: var(--r-sm);
    color: var(--ink-3);
    font-size: 13px;
    transition: background 0.12s ease, color 0.12s ease;
}

.logout-btn:hover {
    background: var(--bad-ghost);
    color: #fca5a5;
}

.logout-btn svg {
    width: 15px;
    height: 15px;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* ═══ Topbar ═══ */
.topbar {
    height: var(--topbar-h);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: var(--s4);
    padding: 0 var(--s5);
    background: rgba(14, 14, 17, 0.82);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar-title {
    font-size: 14.5px;
    font-weight: 600;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.topbar-search {
    position: relative;
    margin-left: auto;
    width: min(300px, 34vw);
}

.topbar-search svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    color: var(--ink-4);
    pointer-events: none;
}

.topbar-search input {
    width: 100%;
    height: 32px;
    padding: 0 42px 0 32px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    font-size: 13px;
    color: var(--ink);
    transition: border-color 0.12s ease, background 0.12s ease;
}

.topbar-search input::placeholder {
    color: var(--ink-4);
}

.topbar-search input:focus {
    outline: none;
    border-color: var(--accent-line);
    background: var(--surface-3);
}

.kbd-hint {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-family: var(--mono);
    font-size: 10.5px;
    color: var(--ink-4);
    background: var(--surface-3);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    padding: 1px 5px;
    pointer-events: none;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: var(--s3);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    font-weight: 500;
    padding: 3px 9px;
    border-radius: var(--r-pill);
    white-space: nowrap;
    background: var(--surface-3);
    color: var(--ink-2);
    border: 1px solid var(--line);
}

.status-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.status-pill.active {
    background: var(--ok-ghost);
    color: var(--ok);
    border-color: rgba(52, 211, 153, 0.24);
}

.status-pill.expired {
    background: var(--bad-ghost);
    color: var(--bad);
    border-color: rgba(248, 113, 113, 0.24);
}

.status-pill.maxed {
    background: var(--warn-ghost);
    color: var(--warn);
    border-color: rgba(251, 191, 36, 0.24);
}

.status-pill.neutral {
    background: var(--surface-3);
    color: var(--ink-3);
}

.status-pill.active .status-dot {
    box-shadow: 0 0 0 3px var(--ok-ghost);
}

/* ═══ Sections ═══ */
.section {
    display: none;
    padding: var(--s5);
    width: 100%;
}

.section.active {
    display: block;
    animation: rise 0.22s ease both;
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

.page-header {
    margin-bottom: var(--s5);
}

.page-header h1 {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 2px;
}

.page-header p {
    color: var(--ink-3);
    font-size: 13px;
}

/* ═══ Stat cards ═══ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
    gap: var(--s3);
    margin-bottom: var(--s5);
}

.stat-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: var(--s4);
    overflow: hidden;
    transition: border-color 0.14s ease, transform 0.14s ease;
}

.stat-card:hover {
    border-color: var(--line-strong);
    transform: translateY(-1px);
}

.stat-head {
    display: flex;
    align-items: center;
    gap: var(--s2);
    margin-bottom: var(--s3);
}

.stat-icon {
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border-radius: var(--r-sm);
    font-size: 13px;
    flex-shrink: 0;
    background: var(--surface-3);
}

.stat-icon.purple {
    background: var(--accent-ghost);
}

.stat-icon.green {
    background: var(--ok-ghost);
}

.stat-icon.red {
    background: var(--bad-ghost);
}

.stat-icon.amber {
    background: var(--warn-ghost);
}

.stat-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--ink-3);
}

.stat-value {
    font-size: 27px;
    font-weight: 600;
    letter-spacing: -0.03em;
    line-height: 1.1;
    margin-bottom: var(--s2);
}

.stat-trend {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    color: var(--ink-4);
}

.stat-trend.positive {
    color: var(--ok);
}

.stat-trend.negative {
    color: var(--bad);
}

/* Sparkline strip pinned to the card's bottom edge */
.stat-spark {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 22px;
    margin-top: var(--s3);
    margin-bottom: -2px;
}

.spark-bar {
    flex: 1;
    min-height: 2px;
    background: var(--accent-ghost);
    border-radius: 1px;
    transition: background 0.14s ease;
}

.stat-card:hover .spark-bar {
    background: var(--accent-line);
}

.spark-bar.hot {
    background: var(--accent);
}

/* ═══ Panels ═══ */
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    overflow: hidden;
}

.panel+.panel {
    margin-top: var(--s4);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s3);
    padding: var(--s3) var(--s4);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

.panel-header h2 {
    font-size: 13.5px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.panel-body {
    padding: var(--s4);
}

.caption {
    font-size: 11.5px;
    color: var(--ink-4);
}

.header-right-actions,
.table-search-bar {
    display: flex;
    align-items: center;
    gap: var(--s2);
    margin-left: auto;
}

/* ═══ Buttons ═══ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 32px;
    padding: 0 var(--s3);
    border-radius: var(--r-md);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    border: 1px solid transparent;
    transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}

.btn:active {
    transform: translateY(1px);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hi);
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--ink-2);
    border-color: var(--line);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--surface-hover);
    color: var(--ink);
    border-color: var(--line-strong);
}

.btn-danger {
    background: var(--bad-ghost);
    color: var(--bad);
    border-color: rgba(248, 113, 113, 0.24);
}

.btn-danger:hover:not(:disabled) {
    background: rgba(248, 113, 113, 0.2);
}

.btn-ghost {
    background: transparent;
    color: var(--ink-3);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--surface-2);
    color: var(--ink);
}

.btn-sm {
    height: 27px;
    padding: 0 10px;
    font-size: 12.5px;
}

.btn-block {
    width: 100%;
    height: 38px;
}

/* ═══ Forms ═══ */
.form-group {
    margin-bottom: var(--s4);
}

.form-group label {
    display: block;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--ink-2);
    margin-bottom: 6px;
}

.form-hint {
    font-size: 11.5px;
    color: var(--ink-4);
    margin-top: 5px;
}

.form-input {
    width: 100%;
    min-height: 36px;
    padding: 8px 11px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    font-size: 13.5px;
    color: var(--ink);
    transition: border-color 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}

.form-input::placeholder {
    color: var(--ink-4);
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--surface-3);
    box-shadow: 0 0 0 3px var(--accent-ghost);
}

textarea.form-input {
    resize: vertical;
    min-height: 80px;
    line-height: 1.55;
}

select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%2374747f' stroke-width='1.5'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 12px;
    padding-right: 30px;
}

.form-input-sm {
    min-height: 28px;
    padding: 4px 9px;
    font-size: 12.5px;
    width: auto;
    min-width: 180px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--s3);
}

/* ═══ Tables ═══ */
.table-wrap {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    text-align: left;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--ink-4);
    padding: var(--s3) var(--s4);
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
    background: var(--surface);
}

.data-table td {
    padding: 11px var(--s4);
    border-bottom: 1px solid var(--line);
    color: var(--ink-2);
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background 0.1s ease;
}

.data-table tbody tr:hover {
    background: var(--surface-2);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table td strong {
    color: var(--ink);
    font-weight: 600;
}

.cell-mono {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--ink-2);
    letter-spacing: -0.01em;
}

.cell-amount {
    font-weight: 600;
    color: var(--ink);
}

.cell-amount.pos {
    color: var(--ok);
}

.cell-amount.neg {
    color: var(--bad);
}

.cell-muted {
    color: var(--ink-4);
}

.cell-truncate {
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.action-cell {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.data-table th.col-right,
.data-table td.col-right {
    text-align: right;
}

/* Usage meter for promo consumption */
.usage-meter {
    display: flex;
    align-items: center;
    gap: var(--s2);
    min-width: 108px;
}

.usage-track {
    flex: 1;
    height: 4px;
    background: var(--surface-3);
    border-radius: var(--r-pill);
    overflow: hidden;
}

.usage-fill {
    height: 100%;
    background: var(--accent);
    border-radius: var(--r-pill);
    transition: width 0.3s ease;
}

.usage-fill.full {
    background: var(--warn);
}

.usage-text {
    font-size: 11.5px;
    color: var(--ink-3);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Inline balance editor — stays on the right edge of a right-aligned column. */
.inline-edit {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
}

.inline-edit-input {
    width: 92px;
    height: 27px;
    padding: 0 8px;
    background: var(--surface-3);
    border: 1px solid var(--accent);
    border-radius: var(--r-sm);
    color: var(--ink);
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
}

.inline-edit-input:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-ghost);
}

/* ═══ Empty + loading states ═══ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--s3);
    padding: var(--s7) var(--s4);
    text-align: center;
}

.empty-icon {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    font-size: 17px;
}

.empty-state p {
    color: var(--ink-3);
    font-size: 13px;
}

.empty-state .empty-title {
    color: var(--ink);
    font-weight: 600;
    font-size: 13.5px;
}

.skeleton {
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.3s ease infinite;
    border-radius: var(--r-sm);
    height: 11px;
}

@keyframes shimmer {
    from {
        background-position: 100% 50%;
    }

    to {
        background-position: 0 50%;
    }
}

.spinner {
    display: inline-block;
    width: 13px;
    height: 13px;
    border: 2px solid rgba(255, 255, 255, 0.28);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ═══ Modals ═══ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(4, 4, 6, 0.72);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--s4);
    z-index: 200;
}

.modal-overlay.visible {
    display: flex;
    animation: fade 0.15s ease both;
}

@keyframes fade {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal {
    width: 100%;
    max-width: 448px;
    max-height: calc(100vh - 2 * var(--s5));
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--r-xl);
    box-shadow: var(--e3);
    animation: pop 0.17s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes pop {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.985);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s3);
    padding: var(--s4);
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.modal-header h3 {
    font-size: 14.5px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.modal-close {
    width: 27px;
    height: 27px;
    display: grid;
    place-items: center;
    border-radius: var(--r-sm);
    color: var(--ink-3);
    font-size: 19px;
    line-height: 1;
    transition: background 0.12s ease, color 0.12s ease;
}

.modal-close:hover {
    background: var(--surface-2);
    color: var(--ink);
}

.modal-body {
    padding: var(--s4);
    overflow-y: auto;
    flex: 1;
}

.modal-body .form-group:last-child {
    margin-bottom: 0;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--s2);
    padding: var(--s3) var(--s4);
    border-top: 1px solid var(--line);
    background: var(--surface-2);
    flex-shrink: 0;
}

.modal-sm {
    max-width: 388px;
}

.confirm-text {
    font-size: 13.5px;
    color: var(--ink-2);
    line-height: 1.6;
}

.confirm-text strong {
    color: var(--ink);
}

.confirm-warning {
    display: flex;
    gap: var(--s3);
    margin-top: var(--s3);
    padding: var(--s3);
    background: var(--bad-ghost);
    border: 1px solid rgba(248, 113, 113, 0.22);
    border-radius: var(--r-md);
    font-size: 12.5px;
    color: #fca5a5;
}

/* ═══ Toasts ═══ */
.toast-container {
    position: fixed;
    bottom: var(--s5);
    right: var(--s5);
    display: flex;
    flex-direction: column;
    gap: var(--s2);
    z-index: 300;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--s3);
    min-width: 232px;
    max-width: 380px;
    padding: 11px var(--s4);
    background: var(--surface-3);
    border: 1px solid var(--line-strong);
    border-radius: var(--r-md);
    box-shadow: var(--e2);
    font-size: 13px;
    animation: toast-in 0.22s cubic-bezier(0.16, 1, 0.3, 1) both;
    pointer-events: auto;
}

.toast::before {
    content: '';
    width: 3px;
    align-self: stretch;
    border-radius: var(--r-pill);
    background: var(--accent);
    flex-shrink: 0;
}

.toast.ok::before {
    background: var(--ok);
}

.toast.bad::before {
    background: var(--bad);
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateX(16px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

.toast.leaving {
    animation: toast-out 0.18s ease both;
}

@keyframes toast-out {
    to {
        opacity: 0;
        transform: translateX(16px);
    }
}

/* ═══ Charts ═══ */
.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: var(--s4);
    margin-bottom: var(--s4);
}

.chart-box {
    position: relative;
    height: 252px;
}

/* ═══ Broadcast ═══ */
.formatting-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 6px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-bottom: none;
    border-radius: var(--r-md) var(--r-md) 0 0;
}

.formatting-toolbar+.form-input {
    border-radius: 0 0 var(--r-md) var(--r-md);
}

.format-btn {
    height: 25px;
    padding: 0 9px;
    font-size: 12px;
}

.broadcast-result {
    display: none;
    margin-top: var(--s4);
    padding: var(--s3) var(--s4);
    background: var(--ok-ghost);
    border: 1px solid rgba(52, 211, 153, 0.24);
    border-radius: var(--r-md);
    color: var(--ok);
    font-size: 13px;
}

.broadcast-result.visible {
    display: block;
}

.broadcast-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s3);
    margin-top: var(--s2);
    font-size: 11.5px;
    color: var(--ink-4);
}

.char-count {
    font-variant-numeric: tabular-nums;
}

.char-count.over {
    color: var(--bad);
}

/* ═══ Mobile ═══ */
.mobile-toggle {
    display: none;
    width: 34px;
    height: 34px;
    place-items: center;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    color: var(--ink-2);
    flex-shrink: 0;
}

.mobile-toggle svg {
    width: 17px;
    height: 17px;
}

.sidebar-scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(4, 4, 6, 0.6);
    z-index: 45;
}

.sidebar-scrim.visible {
    display: block;
}

@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
        box-shadow: var(--e3);
    }

    .sidebar.open {
        transform: none;
    }

    .main-content {
        margin-left: 0;
    }

    .mobile-toggle {
        display: grid;
    }

    .topbar {
        padding: 0 var(--s4);
        gap: var(--s3);
    }

    .topbar-search {
        width: auto;
        flex: 1;
    }

    .kbd-hint {
        display: none;
    }

    .btn-desktop-only {
        display: none;
    }

    .section {
        padding: var(--s4);
    }

    .charts-container {
        grid-template-columns: 1fr;
    }
}

/* Below 680px tables stop being tables: each row becomes a card and every cell
   carries its own label, so nothing depends on a header row that is off-screen. */
@media (max-width: 680px) {
    .data-table thead {
        display: none;
    }

    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
        width: 100%;
    }

    .data-table tr {
        background: var(--surface-2);
        border: 1px solid var(--line);
        border-radius: var(--r-md);
        padding: var(--s3);
        margin-bottom: var(--s2);
    }

    .data-table tr:hover {
        background: var(--surface-2);
    }

    .data-table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--s3);
        padding: 5px 0;
        border: none;
        text-align: right;
    }

    .data-table td::before {
        content: attr(data-label);
        font-size: 10.5px;
        font-weight: 600;
        letter-spacing: 0.06em;
        text-transform: uppercase;
        color: var(--ink-4);
        text-align: left;
        flex-shrink: 0;
    }

    /* Cells holding an empty state or the action row need no label. */
    .data-table td.no-label::before {
        content: none;
    }

    .data-table td.no-label {
        display: block;
    }

    .action-cell {
        justify-content: flex-end;
        padding-top: var(--s2);
    }

    /* A flex container cannot ellipsize its own text, and a card is too narrow
       to truncate usefully anyway — let long values wrap under their label. */
    .data-table td.cell-truncate {
        display: block;
        max-width: none;
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        text-align: left;
    }

    .data-table td.cell-truncate::before {
        display: block;
        margin-bottom: 2px;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }

    .stat-value {
        font-size: 23px;
    }

    .toast-container {
        left: var(--s4);
        right: var(--s4);
        bottom: var(--s4);
    }

    .toast {
        min-width: 0;
        max-width: none;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .panel-header {
        align-items: stretch;
        flex-direction: column;
    }

    .header-right-actions,
    .table-search-bar {
        margin-left: 0;
    }

    .form-input-sm {
        width: 100%;
        min-width: 0;
    }
}

@media (max-width: 420px) {
    .topbar-title {
        display: none;
    }
}

/* ═══ Broadcast Feed & Card Redesign ═══ */
.broadcast-feed {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.broadcast-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: 16px 20px;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

.broadcast-card:hover {
    background: var(--surface-2);
    border-color: var(--line-strong);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
}

.broadcast-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.broadcast-card-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.broadcast-type-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: var(--r-pill);
    letter-spacing: 0.02em;
}

.broadcast-type-pill.stock {
    background: rgba(52, 211, 153, 0.12);
    color: #34d399;
    border: 1px solid rgba(52, 211, 153, 0.26);
}

.broadcast-type-pill.announcement {
    background: rgba(109, 94, 252, 0.12);
    color: #a78bfa;
    border: 1px solid rgba(109, 94, 252, 0.26);
}

.broadcast-time-text {
    font-size: 12.5px;
    color: var(--ink-3);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-weight: 500;
}

.broadcast-char-badge {
    font-size: 11px;
    color: var(--ink-3);
    background: var(--surface-3);
    padding: 2px 7px;
    border-radius: var(--r-sm);
    font-family: var(--mono);
    border: 1px solid var(--line);
}

.broadcast-card-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.broadcast-card-actions .btn {
    padding: 4px 10px;
    font-size: 12px;
    height: 30px;
}

.broadcast-card-body {
    margin-bottom: 14px;
}

.broadcast-text-content {
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--ink);
    white-space: pre-wrap;
    word-break: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.broadcast-card-footer {
    border-top: 1px solid var(--line);
    padding-top: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.broadcast-stats-group {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12.5px;
    flex-wrap: wrap;
}

.broadcast-stat-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--ink-2);
}

.broadcast-stat-chip strong {
    font-weight: 600;
}

.broadcast-stat-chip.success strong {
    color: var(--ok);
}

.broadcast-stat-chip.failed strong {
    color: var(--bad);
}

.broadcast-stat-chip.total strong {
    color: var(--ink);
}

.broadcast-meter-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.broadcast-progress-bar {
    width: 90px;
    height: 5px;
    background: var(--surface-3);
    border-radius: 999px;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--line);
}

.broadcast-progress-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.4s ease;
}

.broadcast-progress-fill.high {
    background: #34d399;
}

.broadcast-progress-fill.medium {
    background: #fbbf24;
}

.broadcast-progress-fill.low {
    background: #ef4444;
}

.broadcast-rate-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--r-pill);
    background: var(--surface-3);
    color: var(--ink-3);
}

.broadcast-rate-badge.high {
    color: var(--ok);
    background: var(--ok-ghost);
    border: 1px solid rgba(52, 211, 153, 0.24);
}

.broadcast-rate-badge.medium {
    color: var(--warn);
    background: var(--warn-ghost);
    border: 1px solid rgba(251, 191, 36, 0.24);
}

.broadcast-rate-badge.low {
    color: var(--bad);
    background: var(--bad-ghost);
    border: 1px solid rgba(248, 113, 113, 0.24);
}

.broadcast-view-body {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: 16px;
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--ink);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 340px;
    overflow-y: auto;
}

.broadcast-view-body blockquote {
    border-left: 3px solid var(--accent);
    margin: 8px 0;
    color: var(--ink-2);
    background: rgba(109, 94, 252, 0.06);
    padding: 8px 12px;
    border-radius: 0 var(--r-sm) var(--r-sm) 0;
}

.broadcast-view-body code {
    background: var(--surface-3);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 12.5px;
}

/* ═══ Print ═══ */
@media print {

    .sidebar,
    .topbar,
    .toast-container,
    .action-cell {
        display: none !important;
    }

    .main-content {
        margin-left: 0;
    }

    body {
        background: #fff;
        color: #000;
    }

    .panel {
        border-color: #ccc;
    }
}
/* ═══ Anti-Spam Firewall Styles ═══ */
.fw-rules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.fw-rule-card {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.fw-rule-card:hover {
    border-color: var(--line-strong);
}

.fw-rule-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.fw-icon-pill {
    width: 36px;
    height: 36px;
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.fw-rule-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.input-unit {
    position: relative;
    display: flex;
    align-items: center;
}

.input-unit input {
    padding-right: 70px !important;
}

.input-unit span {
    position: absolute;
    right: 12px;
    color: var(--ink-3);
    font-size: 13px;
    font-weight: 500;
    pointer-events: none;
    user-select: none;
}

/* Switch Component */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--surface-3);
    border: 1px solid var(--line);
    transition: .25s cubic-bezier(0.4, 0, 0.2, 1);
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.switch input:checked + .slider {
    background-color: var(--accent);
    border-color: var(--accent);
}

.switch input:focus + .slider {
    box-shadow: 0 0 1px var(--accent);
}

.switch input:checked + .slider:before {
    transform: translateX(20px);
}

.slider.round {
    border-radius: 24px;
}

.slider.round:before {
    border-radius: 50%;
}

.fw-countdown-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 600;
    background: rgba(255, 69, 58, 0.12);
    color: #ff453a;
    border: 1px solid rgba(255, 69, 58, 0.25);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.fw-gateway-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 500;
    background: var(--surface-3);
    color: var(--ink);
    border: 1px solid var(--line);
    white-space: nowrap;
}

#section-firewall .data-table th,
#section-firewall .data-table td {
    padding: 13px 18px;
}

#section-firewall .data-table th:first-child,
#section-firewall .data-table td:first-child {
    padding-left: 20px;
}

#section-firewall .data-table th:last-child,
#section-firewall .data-table td:last-child {
    padding-right: 20px;
}
