/* ============================================================
   550A Dashboard
   Panel-based monitoring dashboard with CRT effects
   ============================================================ */

/* --- Reset & Foundation --- */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
    height: 100%;
    font-family: 'SF Mono', 'Cascadia Code', 'JetBrains Mono', 'Fira Code', Menlo, Consolas, monospace;
    font-size: 13px;
}
body {
    display: flex;
    flex-direction: column;
    background: #0c0c0c;
    color: #999;
    animation: fadein 0.4s ease;
    overflow: hidden;
}
#root {
    flex: 1;
    min-height: 0;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}
.command-page-shell {
    flex: 1;
    min-height: 0;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
}
.command-page-main {
	flex: 1;
	min-height: 0;
	display: flex;
	flex-direction: column;
}
[x-cloak] { display: none !important; }

@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

:root {
    --accent: #e55;
    --accent-dim: #b44;
    --accent-glow: rgba(238, 85, 85, 0.3);
    --green: #5a5;
    --yellow: #aa3;
    --fail: #86e;
    --border: #1e1e1e;
    --border-panel: #252525;
    --text: #999;
    --text-dim: #555;
    --text-bright: #ccc;
    --bg: #0c0c0c;
    --bg-panel: #111;
    --bg-input: #0a0a0a;
    --bg-hover: #181818;
    --panel-radius: 3px;
}

/* --- CRT Scanline (dark mode only) --- */
body::after { content: none; }
body.dark-mode::after {
    content: '';
    position: fixed;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0,0,0,0.06) 2px,
        rgba(0,0,0,0.06) 4px
    );
    pointer-events: none;
    z-index: 9999;
}

/* --- Scrollbar --- */
body { scrollbar-color: #2a2a2a #0c0c0c; }
body::-webkit-scrollbar { width: 8px; }
body::-webkit-scrollbar-track { background: #0c0c0c; }
body::-webkit-scrollbar-thumb { background: #2a2a2a; }
body::-webkit-scrollbar-thumb:hover { background: #3a3a3a; }

/* === TOPBAR === */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    height: 40px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-panel);
    flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 0; }
.topbar-brand {
    font-size: 15px;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: 0;
    text-shadow: 0 0 12px var(--accent-glow);
}
.topbar-sep { color: var(--text-dim); margin: 0 8px; font-weight: 300; }
.topbar-user { color: var(--text-bright); font-weight: 600; font-size: 13px; }
.topbar-runcat {
    display: inline-block;
    width: 36px;
    height: 22px;
    margin-left: 6px;
    vertical-align: middle;
    position: relative;
    overflow: hidden;
}
.topbar-runcat .runcat-frame {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
}
.topbar-runcat .runcat-frame.active { opacity: 1; }
.topbar-runcat img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.dark-mode .topbar-runcat img { filter: invert(1); }
.topbar-right { display: flex; align-items: center; gap: 3px; }
.topbar-revenue {
    color: var(--accent);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
    text-shadow: 0 0 12px var(--accent-glow);
    margin-right: 6px;
    white-space: nowrap;
}

/* === BUTTONS === */
.btn {
    padding: 5px 14px;
    font-size: 11px;
    font-family: inherit;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    background: transparent;
    border: 1px solid var(--border-panel);
    border-radius: var(--panel-radius);
    cursor: pointer;
    color: var(--text-dim);
    transition: all 0.15s ease;
}
.btn:hover {
    background: var(--bg-hover);
    border-color: #444;
    color: var(--text);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.btn:active { transform: translateY(0); box-shadow: none; }
.btn-accent {
    border-color: var(--accent-dim);
    color: var(--accent);
}
.btn-accent:hover { border-color: var(--accent); background: rgba(204,68,68,0.08); }
.btn-subtle { color: var(--text-dim); border-color: transparent; }
.btn-subtle:hover { border-color: var(--border-panel); }
.btn-save { background: var(--accent-dim); color: #fff; border-color: var(--accent-dim); }
.btn-save:hover { background: var(--accent); border-color: var(--accent); }
.btn-save:disabled { background: #222; border-color: #222; color: #555; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-close { color: var(--text-dim); }
.btn-close:hover { color: var(--text); background: var(--bg-hover); }
.btn-danger { background: var(--accent-dim); color: #fff; border-color: var(--accent-dim); }
.btn-danger:hover { background: var(--accent); border-color: var(--accent); }
.btn-danger:disabled { background: rgba(187, 68, 68, 0.3); border-color: rgba(187, 68, 68, 0.3); color: rgba(255,255,255,0.4); cursor: not-allowed; transform: none; box-shadow: none; }

/* Long-press border animation */
.btn-face-wrap {
    position: relative;
    display: inline-block;
}
.btn-face-wrap .btn-face-border {
    position: absolute;
    inset: -2px;
    border-radius: calc(var(--panel-radius) + 2px);
    background: conic-gradient(var(--accent) var(--lp-progress, 0%), transparent 0%);
    opacity: 0;
    pointer-events: none;
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    padding: 2px;
    transition: opacity 0.15s;
}
.btn-face-wrap.lp-active .btn-face-border {
    opacity: 1;
}

/* Face overlay */
.face-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: #0a0a0a;
    opacity: 0;
    pointer-events: none;
}
/* iframe always in DOM but hidden */
.face-overlay .face-overlay-iframe {
    opacity: 0;
}
/* Once ready: show everything and play power-on */
.face-overlay-ready {
    opacity: 1;
    pointer-events: auto;
}
.face-overlay-ready .face-overlay-iframe {
    animation: crt-on 0.6s ease-out forwards;
}
.face-overlay-ready .face-overlay-noise {
    animation: crt-noise-on 0.6s ease-out forwards;
}
.face-overlay-ready::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0,0,0,0.35) 2px,
        rgba(0,0,0,0.35) 4px
    );
    z-index: 2;
    pointer-events: none;
    animation: crt-scanlines-on 0.6s ease-out forwards;
}
@keyframes crt-on {
    0%   { filter: brightness(3); transform: scale(0, 0); opacity: 0; }
    15%  { filter: brightness(3); transform: scale(0.008, 0.008); opacity: 0.7; }
    40%  { filter: brightness(2.2); transform: scale(0.12, 0.005); opacity: 1; }
    65%  { filter: brightness(1.8); transform: scale(1.01, 0.007); opacity: 1; }
    85%  { filter: brightness(1.3); transform: scale(1, 0.5); opacity: 1; }
    100% { filter: brightness(1); transform: scale(1, 1); opacity: 1; }
}
@keyframes crt-noise-on {
    0%   { opacity: 0; }
    15%  { opacity: 0.5; }
    60%  { opacity: 0.3; }
    100% { opacity: 0; }
}
@keyframes crt-scanlines-on {
    0%   { opacity: 1; }
    60%  { opacity: 1; }
    100% { opacity: 0; }
}
.face-overlay-closing {
    pointer-events: none;
}
/* Static noise layer (hidden until shutdown) */
.face-overlay-noise {
    position: absolute;
    inset: 0;
    filter: url(#crt-noise);
    opacity: 0;
    pointer-events: none;
    z-index: 1;
}
.face-overlay-closing .face-overlay-noise {
    animation: crt-noise-in 0.7s ease-in forwards;
}
@keyframes crt-noise-in {
    0%   { opacity: 0; }
    4%   { opacity: 0.5; }
    50%  { opacity: 0.35; }
    100% { opacity: 0; }
}
/* Scanlines over the iframe during shutdown */
.face-overlay-closing::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0,0,0,0.35) 2px,
        rgba(0,0,0,0.35) 4px
    );
    z-index: 2;
    animation: crt-scanlines 0.7s ease-in forwards;
}
@keyframes crt-scanlines {
    0%   { opacity: 0; }
    4%   { opacity: 1; }
    60%  { opacity: 1; }
    100% { opacity: 0; }
}
/* The iframe itself: flash bright then squash to line → dot → gone */
.face-overlay-closing .face-overlay-iframe {
    animation: crt-off 0.7s ease-in forwards;
}
@keyframes crt-off {
    0%   { filter: brightness(1); transform: scale(1, 1); opacity: 1; }
    6%   { filter: brightness(2.5); transform: scale(1, 1); opacity: 1; }
    30%  { filter: brightness(1.8); transform: scale(1.01, 0.007); opacity: 1; }
    55%  { filter: brightness(2.2); transform: scale(0.12, 0.005); opacity: 1; }
    75%  { filter: brightness(3); transform: scale(0.008, 0.008); opacity: 0.7; }
    100% { filter: brightness(3); transform: scale(0, 0); opacity: 0; }
}
.face-overlay-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* === DASHBOARD GRID === */
.dashboard {
	display: grid;
	grid-template-columns: minmax(0, 1fr) 420px;
	grid-template-rows: auto auto auto;
	gap: 1px;
	background: var(--border);
	min-height: 0;
	overflow: auto;
	flex: 0 1 auto;
	max-height: clamp(240px, 50dvh, 700px);
}

/* === PANELS === */
.panel {
    background: var(--bg-panel);
    overflow: hidden;
}
.panel-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-dim);
    padding: 8px 12px 0;
    user-select: none;
}
.panel-body { padding: 6px 12px 10px; }

/* Grid placement */
.panel-channels { grid-column: 1 / -1; overflow: hidden; }
.panel-usage-activity { grid-column: 1; overflow: visible; z-index: 1; }
.panel-system { grid-column: 2; display: flex; flex-direction: column; }
.panel-requests { grid-column: 2; }
.panel-usage { grid-column: 1; }
.panel-activity { grid-column: 2; }
.panel-info { grid-column: 1 / -1; }

/* === CHANNELS === */
.moss-link {
    position: absolute;
    top: 8px;
    bottom: 8px;
    right: 12px;
    aspect-ratio: 1;
    display: block;
    max-height: calc(100% - 16px);
}
.moss-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 8px;
    transition: transform 0.4s ease;
    cursor: pointer;
}
.moss-img:hover {
    transform: scale(1.05);
}
.channel-group { margin-bottom: 4px; }
.channel-group:last-child { margin-bottom: 0; }
.channel-label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-dim);
    margin-bottom: 4px;
}
.channel-switcher {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.channel-btn {
    padding: 4px 12px;
    font-size: 12px;
    font-family: inherit;
    background: var(--bg);
    border: 1px solid var(--border-panel);
    border-radius: var(--panel-radius);
    cursor: pointer;
    position: relative;
    color: var(--text-dim);
    transition: all 0.15s ease;
}
.channel-btn:hover { background: var(--bg-hover); color: var(--text); border-color: #444; }

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
    50% { box-shadow: 0 0 8px 2px var(--accent-glow); }
}
.channel-btn.current {
    background: var(--accent-dim);
    color: #fff;
    border-color: var(--accent);
    font-weight: 700;
    animation: pulse-glow 3s ease-in-out infinite;
}

/* Balance badges */
.balance-badge {
    position: absolute;
    top: -7px; right: -3px;
    background: #1a3555;
    color: #7ab;
    font-size: 9px;
    font-weight: 700;
    padding: 0 4px;
    border-radius: 2px;
    min-width: 16px;
    text-align: center;
    white-space: nowrap;
    z-index: 2;
    line-height: 1.5;
    box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.balance-badges {
    position: absolute;
    top: -7px; right: -3px;
    display: flex;
    gap: 2px;
    z-index: 2;
}
.balance-badges .balance-badge { position: static; }
.balance-badge.privacy-badge { background: #2e2545; color: #a8b; }
.balance-badge.rpm-badge { background: #1a3a28; color: #7b9; }

.panel-system .panel-body {
    display: flex;
    align-items: center;
    flex: 1;
    margin-right: 5px;
}
/* === SYSTEM INFO === */
.sys-info {
    font-family: inherit;
    font-size: 12px;
    width: 100%;
}
.sys-bar {
    color: var(--text-dim);
    line-height: 1.6;
    display: flex;
    align-items: center;
    gap: 8px;
}
.sys-label {
    display: inline-block;
    width: 3ch;
    text-align: right;
    color: var(--accent);
    font-weight: 700;
    flex-shrink: 0;
}
/* Progress bar track & fill */
.bar-track-wrap {
    flex: 1;
    min-width: 0;
}
.bar-track {
    flex: 1;
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    min-width: 0;
}
.bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.4s ease;
    background: var(--accent);
}
.bar-fill.bar-green { background: var(--green); }
.bar-fill.bar-yellow { background: var(--yellow); }
.bar-fill.bar-red { background: var(--accent); }
.skeleton-track { animation: skeleton-pulse 2s ease-in-out infinite; }
/* Keep old bar-* classes for compat (renderReqBar still uses them) */
span.bar-green { color: var(--green); text-shadow: 0 0 4px rgba(85,170,85,0.3); }
span.bar-yellow { color: var(--yellow); text-shadow: 0 0 4px rgba(170,170,51,0.3); }
span.bar-red { color: var(--accent); text-shadow: 0 0 4px var(--accent-glow); }
.bar-empty { color: #1a1a1a; }
.sys-pct {
    display: inline-block;
    width: 10ch;
    text-align: right;
    color: var(--text);
    flex-shrink: 0;
}

/* === REQUEST STATS === */
.req-stats {
    font-family: inherit;
    font-size: 12px;
    display: flex;
    flex-direction: column;
    gap: 0;
}
.req-stats-row {
    display: flex;
    align-items: center;
    gap: 0;
    color: var(--text-dim);
    line-height: 1.6;
}
.req-stats-label {
    display: inline-block;
    width: 6ch;
    text-align: right;
    color: var(--accent);
    font-weight: 700;
}
.req-stats-rate {
    display: inline-block;
    width: 4ch;
    text-align: left;
    color: var(--text);
}
.req-stats-bar { letter-spacing: -1px; }
.req-block { font-weight: 700; }
.req-block.success { color: var(--green); text-shadow: 0 0 3px rgba(85,170,85,0.25); }
.req-block.fail { color: var(--fail); text-shadow: 0 0 3px rgba(136,102,238,0.25); }
.req-block.empty { color: #1a1a1a; }

/* === USER COSTS === */
.user-costs-row {
    font-family: inherit;
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.5;
}
.user-costs-label { color: var(--accent); font-weight: 700; margin-right: 4px; text-transform: uppercase; font-size: 11px; letter-spacing: 0.05em; }
.user-cost-inline { margin-right: 10px; white-space: nowrap; }
.user-name-inline { color: var(--text-dim); }
.user-cost-value { color: var(--accent); font-weight: 700; }
.skeleton-user-costs-inline { width: 800px; height: 2em; }

/* === INFO DESC === */
.info-desc {
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.6;
    position: relative;
}
.info-desc-content { display: block; }
.info-desc:not(.expanded) .info-desc-content {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.info-desc.expanded .info-desc-content { display: block; }
.info-desc-toggle {
    display: none;
    padding: 1px 6px;
    font-size: 10px;
    font-family: inherit;
    background: var(--bg);
    border: 1px solid var(--border-panel);
    border-radius: var(--panel-radius);
    cursor: pointer;
    color: var(--text-dim);
    transition: all 0.1s;
    position: absolute;
    bottom: 0; right: 5px;
    opacity: 0;
    pointer-events: none;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.info-desc:hover .info-desc-toggle { opacity: 1; pointer-events: auto; }
.info-desc-toggle:hover { background: var(--bg-hover); color: var(--text); }
.info-desc a {
    color: var(--text-dim);
    text-decoration: none;
    border-bottom: 1px dotted var(--border-panel);
    transition: all 0.1s;
    overflow-wrap: anywhere;
    word-break: break-all;
}
.info-desc a:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* === LOG === */
.log-wrapper { flex: 1; min-height: 0; height: 100%; position: relative; display: flex; flex-direction: column; }
.log-container { width: 100%; flex: 1; min-height: 0; height: 100%; border-top: 1px solid var(--border); display: flex; flex-direction: column; }
.log-container iframe { width: 100%; height: 100%; border: none; }

/* === MODALS === */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
}
.modal-overlay.show { display: flex; }

@keyframes modal-in {
    from { opacity: 0; transform: translateY(16px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal {
    background: var(--bg-panel);
    border-radius: var(--panel-radius);
    width: 90%;
    max-width: 900px;
    height: 85%;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 0 1px var(--border-panel), 0 16px 48px rgba(0,0,0,0.6);
    animation: modal-in 0.2s ease;
}
.modal-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.modal-header h2 {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-bright);
}
.modal-header-buttons { display: flex; gap: 3px; }
.modal-body {
    flex: 1;
    padding: 12px 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.config-editor {
    flex: 1;
    width: 100%;
    font-family: inherit;
    font-size: 12px;
    line-height: 1.6;
    padding: 12px;
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent-dim);
    border-radius: 0;
    resize: none;
    tab-size: 2;
    background: var(--bg-input);
    color: #bbb;
    transition: border-color 0.15s;
}
.config-editor:focus { outline: none; border-color: var(--accent-dim); border-left-color: var(--accent); }

.form-label { margin: 0 0 4px; font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }
.form-actions { margin-top: 8px; display: flex; gap: 3px; align-items: center; flex-wrap: wrap; }

.text-input {
    width: 100%;
    font-family: inherit;
    font-size: 12px;
    line-height: 1.5;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--panel-radius);
    background: var(--bg-input);
    color: #bbb;
    transition: border-color 0.15s;
}
.text-input:focus { outline: none; border-color: var(--accent-dim); }

.metrics { margin-top: 10px; }
.metric-row { font-family: inherit; font-size: 12px; color: var(--text-dim); line-height: 1.7; }
.metric-label { display: inline-block; width: 7.5ch; text-align: right; color: var(--accent); font-weight: 700; margin-right: 8px; }
.metric-value { color: var(--text); font-weight: 700; }

.modal-status { margin-top: 8px; padding: 6px 10px; border-radius: var(--panel-radius); font-size: 11px; display: none; font-weight: 600; }
.modal-status.success { display: block; background: #0a1f0a; color: #5a5; border: 1px solid #1a3a28; }
.modal-status.error { display: block; background: #1f0a0a; color: var(--accent); border: 1px solid #3a1a1a; }

/* === SKELETON === */
@keyframes skeleton-pulse {
    0% { opacity: 0.1; }
    50% { opacity: 0.25; }
    100% { opacity: 0.1; }
}
.skeleton { background: #2a2a2a; animation: skeleton-pulse 2s ease-in-out infinite; border-radius: 2px; display: inline-block; }
.skeleton-bar { width: 32ch; height: 1em; }
.skeleton-pct { width: 8ch; height: 1em; margin-left: 4px; }
.skeleton-req-bar { width: 77ch; height: 1em; }
.skeleton-rate { width: 3ch; height: 1em; }
.skeleton-user-cost { width: 100px; height: 3em; }
.skeleton-heatmap { width: 800px; height: 100px; }

/* === TOKEN STATS (compat) === */
.token-stats { font-family: inherit; font-size: 12px; display: flex; flex-direction: column; gap: 1px; min-width: 120px; }
.token-stats-title { color: var(--accent); font-weight: 700; margin-bottom: 2px; }
.user-cost-row { display: flex; justify-content: space-between; gap: 10px; padding: 1px 0; }
.user-name { color: var(--text-dim); }
.user-cost { color: var(--accent); font-weight: 700; }
.no-data { color: var(--text-dim); font-style: italic; }

/* === HEATMAP === */
.activity-heatmap-container { width: 100%; min-width: 0; overflow: visible; }
.activity-heatmap { font-family: inherit; font-size: 11px; display: block; width: 100%; min-width: 0; }
.heatmap-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 4px; flex-wrap: wrap; }
.heatmap-title { color: var(--accent); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.heatmap-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 1px;
    padding: 1px 0;
    transition: background-color 0.1s;
    min-width: 0;
}
.heatmap-row:hover { background: var(--bg-hover); }
.heatmap-user { flex: 0 0 80px; text-align: right; color: var(--text-dim); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.heatmap-cells {
    --heatmap-columns: 24;
    display: grid;
    grid-template-columns: repeat(var(--heatmap-columns), 9px);
    gap: 1px;
    flex: 0 1 auto;
    min-width: 0;
}
.heatmap-cell { width: 9px; height: 9px; border-radius: 1px; display: inline-block; position: relative; }
.heatmap-cells .heatmap-cell { min-width: 9px; min-height: 9px; }
.heatmap-cell[data-tooltip] { cursor: pointer; }
.heatmap-cell[data-tooltip]:hover { transform: scale(1.2); z-index: 10; opacity: 1 !important; }

@keyframes tooltip-fadein { from { opacity: 0; } to { opacity: 1; } }
.heatmap-cell[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%; left: 50%;
    transform: translateX(-50%);
    margin-bottom: 4px;
    padding: 3px 8px;
    background: #1a1a1a;
    color: #bbb;
    font-size: 10px;
    white-space: nowrap;
    border-radius: 2px;
    border: 1px solid #333;
    pointer-events: none;
    z-index: 1000;
    animation: none;
}
.heatmap-cell[data-tooltip]:hover::before {
    content: '';
    position: absolute;
    bottom: 100%; left: 50%;
    transform: translateX(-50%);
    margin-bottom: -2px;
    border: 3px solid transparent;
    border-top-color: #1a1a1a;
    pointer-events: none;
    z-index: 1000;
    animation: none;
}

/* Heatmap levels */
.heatmap-cell.level-0 { background-color: #1a1a1a; }
.heatmap-cell.level-1 { background-color: var(--accent); opacity: 0.2; }
.heatmap-cell.level-2 { background-color: var(--accent); opacity: 0.4; }
.heatmap-cell.level-3 { background-color: var(--accent); opacity: 0.7; }
.heatmap-cell.level-4 { background-color: var(--accent); opacity: 1; box-shadow: 0 0 4px var(--accent-glow); }

.heatmap-legend { display: flex; align-items: center; gap: 1px; }
.heatmap-legend-label { color: var(--text-dim); font-size: 10px; margin: 0 4px; text-transform: uppercase; letter-spacing: 0.05em; }
.heatmap-legend-label:last-child { margin-right: 0; }
.heatmap-no-data { color: var(--text-dim); font-style: italic; font-size: 11px; }

/* === GUIDE MODAL === */
.guide-modal { max-width: 1000px; height: auto; max-height: 85%; }
.codex-modal { max-width: 1120px; }
.right-modal { max-width: 450px; }
.guide-body { overflow: auto; }
.guide-columns { display: flex; gap: 20px; }
.guide-column { flex: 1; min-width: 0; }
.guide-column h3 {
    font-size: 10px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}
.guide-code {
    font-family: inherit;
    font-size: 11px;
    line-height: 1.6;
    background: var(--bg-input);
    color: #999;
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent-dim);
    border-radius: 0;
    padding: 10px 12px;
    overflow-x: auto;
    white-space: pre;
    margin: 0;
}
.guide-code-block { position: relative; margin-bottom: 14px; }
.guide-code-block:last-child { margin-bottom: 0; }
.copy-btn {
    position: absolute;
    top: 6px; right: 6px;
    padding: 2px 10px;
    font-size: 10px;
    font-family: inherit;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 2px;
    cursor: pointer;
    transition: all 0.1s;
    z-index: 1;
    color: #666;
}
.copy-btn:hover { background: #252525; color: #999; border-color: #444; }
.copy-btn.copied { background: var(--accent-dim); color: #fff; border-color: var(--accent-dim); }

/* === CODEX OVERVIEW === */
.codex-overview-body {
    overflow: auto;
    gap: 10px;
}
.codex-overview-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    align-content: start;
    align-items: start;
}
.codex-card {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 11px;
    background:
        linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0)),
        var(--bg-input);
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
    transition: opacity 0.18s ease, border-color 0.18s ease, filter 0.18s ease, background 0.18s ease;
}
.codex-card-loading {
    opacity: 0.9;
}
.codex-card-disabled {
    border-color: rgba(148, 154, 165, 0.35);
    background:
        linear-gradient(180deg, rgba(205,205,205,0.03), rgba(205,205,205,0)),
        rgba(120, 126, 138, 0.12);
    opacity: 0.62;
    filter: grayscale(0.38);
}
.codex-card-error {
    border-color: rgba(187, 68, 68, 0.55);
    box-shadow: inset 0 0 0 1px rgba(187, 68, 68, 0.2);
}
.codex-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}
.codex-card-email {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-bright);
    word-break: break-word;
}
.codex-card-toggle-minimal {
    position: absolute;
    top: 10px;
    right: 11px;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.16s ease;
}
.codex-card:hover .codex-card-toggle-minimal,
.codex-card:focus-within .codex-card-toggle-minimal,
.codex-card-disabled .codex-card-toggle-minimal {
    opacity: 1;
    pointer-events: auto;
}
.codex-card-toggle-minimal input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.codex-card-toggle-slider {
    width: 28px;
    height: 16px;
    border-radius: 999px;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.42);
    position: relative;
    transition: background 0.16s ease, border-color 0.16s ease, opacity 0.16s ease;
}
.codex-card-toggle-slider::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgba(255,255,255,0.88);
    border: 1px solid rgba(0,0,0,0.18);
    box-sizing: border-box;
    transition: transform 0.16s ease;
}
.codex-card-toggle-minimal input:checked + .codex-card-toggle-slider {
    background: rgba(187, 68, 68, 0.28);
    border-color: rgba(187, 68, 68, 0.4);
}
.codex-card-toggle-minimal input:checked + .codex-card-toggle-slider::after {
    transform: translateX(12px);
}
.codex-card-toggle-minimal input:disabled {
    opacity: 0.6;
}
.codex-card-toggle-minimal input:disabled + .codex-card-toggle-slider {
    opacity: 0.6;
}
.codex-card-badge {
    flex-shrink: 0;
    padding: 3px 7px;
    border-radius: 999px;
    border: 1px solid var(--border-panel);
    background: rgba(255,255,255,0.03);
    color: var(--text);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.codex-card-body {
    display: flex;
    flex-direction: column;
    gap: 7px;
}
.codex-meter {
    border-radius: 6px;
    padding: 0;
    background: rgba(255,255,255,0.02);
}
.codex-meter-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-bright);
    white-space: nowrap;
}
.codex-meter-label {
    flex: 1 1 auto;
    min-width: 0;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.codex-meter-reset {
    flex-shrink: 0;
    color: var(--text-dim);
}
.codex-meter-percent {
    flex-shrink: 0;
    min-width: 3.5ch;
    text-align: right;
}
.codex-meter-track {
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.06);
}
.codex-meter-fill {
    height: 100%;
    border-radius: 999px;
}
.codex-meter-five-hour .codex-meter-fill {
    background: #38a34a;
    box-shadow: 0 0 10px rgba(56, 163, 74, 0.2);
}
.codex-meter-weekly .codex-meter-fill {
    background: #38a34a;
    box-shadow: 0 0 10px rgba(56, 163, 74, 0.2);
}
.codex-meter-empty .codex-meter-fill {
    background: rgba(255,255,255,0.08);
    box-shadow: none;
}
.codex-card-loading-body {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: auto;
}
.codex-loading-line,
.codex-loading-meter {
    border-radius: 999px;
    background: linear-gradient(90deg, rgba(255,255,255,0.04), rgba(255,255,255,0.12), rgba(255,255,255,0.04));
    background-size: 180% 100%;
    animation: codex-loading 1.6s linear infinite;
}
.codex-loading-line {
    height: 9px;
    width: 38%;
}
.codex-loading-meter {
    height: 30px;
}
.codex-loading-meter-alt {
    opacity: 0.8;
}
.codex-card-error-box {
    margin-top: auto;
    border: 1px solid rgba(187, 68, 68, 0.35);
    border-radius: 6px;
    padding: 10px;
    background: rgba(187, 68, 68, 0.08);
    display: flex;
    flex-direction: column;
    gap: 6px;
    justify-content: center;
}
.codex-card-error-title {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #f0a0a0;
}
.codex-card-error-message {
    color: var(--text);
    font-size: 11px;
    line-height: 1.4;
    word-break: break-word;
}
.codex-empty {
    border: 1px dashed var(--border);
    border-radius: 6px;
    padding: 24px 18px;
    text-align: center;
    color: var(--text-dim);
    font-size: 12px;
    background: rgba(255,255,255,0.02);
}
.codex-empty-error {
    color: #f0a0a0;
    border-color: rgba(187, 68, 68, 0.45);
    background: rgba(187, 68, 68, 0.08);
}

@keyframes codex-loading {
    0% { background-position: 180% 0; }
    100% { background-position: -180% 0; }
}

/* === LOG PAGE === */
/* Keep scrolling confined to the logs container */
.log-page { overflow: hidden; }
.log-page {
    height: 100%;
    display: flex;
    flex-direction: column;
    flex: 1;
    padding: 0;
    font-family: 'SF Mono', 'Cascadia Code', 'JetBrains Mono', 'Fira Code', Menlo, Consolas, monospace;
    background: #0c0c0c;
    color: #999;
    min-height: 0;
}
.log-page #logs {
    flex: 1;
    height: 100%;
    overflow-y: scroll;
    overflow-x: hidden;
    padding: 8px 12px 10px;
    scrollbar-color: #2a2a2a #0c0c0c;
    min-height: 0;
    scrollbar-gutter: stable;
}
.log-page #logs::-webkit-scrollbar { width: 8px; }
.log-page #logs::-webkit-scrollbar-track { background: #0c0c0c; }
.log-page #logs::-webkit-scrollbar-thumb { background: #2a2a2a; }
.log-page #logs::-webkit-scrollbar-thumb:hover { background: #3a3a3a; }
.log-page.light-mode { background: #f4f3ef; color: #444; }
.log-page.light-mode #logs { scrollbar-color: #c0c0b8 #f4f3ef; }
.log-page.light-mode #logs::-webkit-scrollbar-track { background: #f4f3ef; }
.log-page.light-mode #logs::-webkit-scrollbar-thumb { background: #c0c0b8; }
.log-page.light-mode #logs::-webkit-scrollbar-thumb:hover { background: #a0a098; }
.log-page p { margin: 0; line-height: 1.4; word-break: break-all; font-size: 12px; }
.log-page p.log-line-user { color: var(--log-line-color); }
.log-page:not(.light-mode) p.log-line-user { color: color-mix(in srgb, var(--log-line-color), white 50%); }

/* === COMPAT: old class names that no longer appear in HTML but keep for safety === */
.header { display: none; }
.header-top, .header-buttons, .stats-row, .combined-stats, .dashboard-left, .dashboard-right { display: contents; }

/* === LIGHT MODE === */
/* Scope to exclude .log-page since the log iframe uses light-mode class instead of dark-mode */
body:not(.dark-mode):not(.log-page) {
    background: #f4f3ef;
    color: #444;
    --accent: #c33;
    --accent-dim: #a33;
    --accent-glow: rgba(204, 51, 51, 0.15);
    --green: #3a7a3a;
    --yellow: #8a7020;
    --fail: #6b4fa0;
    --border: #ddd;
    --border-panel: #ccc;
    --text: #444;
    --text-dim: #999;
    --text-bright: #222;
    --bg: #f4f3ef;
    --bg-panel: #fff;
    --bg-input: #fafaf8;
    --bg-hover: #eee;
}
body:not(.dark-mode) .topbar { background: #fff; border-bottom-color: #ddd; }
body:not(.dark-mode) .topbar-brand,
body:not(.dark-mode) .topbar-revenue { text-shadow: none; }
body:not(.dark-mode) span.bar-green, body:not(.dark-mode) span.bar-yellow, body:not(.dark-mode) span.bar-red { text-shadow: none; }
body:not(.dark-mode) .bar-track { background: #ddd; }
body:not(.dark-mode) .req-block.success, body:not(.dark-mode) .req-block.fail { text-shadow: none; }
body:not(.dark-mode) .bar-empty { color: #ddd; }
body:not(.dark-mode) .req-block.empty { color: #e5e5e5; }
body:not(.dark-mode) .channel-btn.current { animation: none; }
body:not(.dark-mode) .heatmap-cell.level-4 { box-shadow: none; }
body:not(.dark-mode):not(.log-page) .skeleton { background: #ddd; }
body:not(.dark-mode):not(.log-page) .config-editor { background: #f0f0ec; color: #444; border-color: #ddd; border-left-color: var(--accent-dim); }
body:not(.dark-mode):not(.log-page) .guide-code { background: #f0f0ec; color: #444; border-color: #ddd; border-left-color: var(--accent-dim); }
body:not(.dark-mode):not(.log-page) .copy-btn { background: #e8e8e4; border-color: #ccc; color: #666; }
body:not(.dark-mode):not(.log-page) .copy-btn:hover { background: #ddd; color: #444; border-color: #bbb; }
body:not(.dark-mode):not(.log-page) .codex-card { background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(251,251,248,0.92)); }
body:not(.dark-mode):not(.log-page) .codex-card-disabled {
    background: linear-gradient(180deg, rgba(242,242,242,0.95), rgba(232,232,232,0.92));
}
body:not(.dark-mode):not(.log-page) .codex-card-toggle-slider {
    background: rgba(0,0,0,0.03);
    border-color: rgba(0,0,0,0.24);
}
body:not(.dark-mode):not(.log-page) .codex-card-badge { background: rgba(0,0,0,0.03); }
body:not(.dark-mode):not(.log-page) .codex-meter { background: rgba(255,255,255,0.55); }
body:not(.dark-mode):not(.log-page) .codex-meter-track { background: rgba(0,0,0,0.06); border-color: rgba(0,0,0,0.08); }
body:not(.dark-mode):not(.log-page) .codex-meter-reset { color: #666; }
body:not(.dark-mode):not(.log-page) .codex-meter-five-hour .codex-meter-fill,
body:not(.dark-mode):not(.log-page) .codex-meter-weekly .codex-meter-fill { background: #3f9a4f; box-shadow: 0 0 8px rgba(63, 154, 79, 0.14); }
body:not(.dark-mode):not(.log-page) .codex-loading-line,
body:not(.dark-mode):not(.log-page) .codex-loading-meter { background: linear-gradient(90deg, rgba(0,0,0,0.05), rgba(0,0,0,0.12), rgba(0,0,0,0.05)); }
body:not(.dark-mode):not(.log-page) .codex-empty { background: rgba(0,0,0,0.02); }
body:not(.dark-mode) .text-input { background: #fff; color: #444; }
body:not(.dark-mode) .modal { box-shadow: 0 0 0 1px #ddd, 0 16px 48px rgba(0,0,0,0.1); }
body:not(.dark-mode) .modal-status.success { background: #f0f8f0; color: #2a6a2a; border-color: #c0e0c0; }
body:not(.dark-mode) .modal-status.error { background: #fdf0f0; color: #a02020; border-color: #e0c0c0; }
body:not(.dark-mode) .balance-badge { background: #3a6a9a; color: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.15); }
body:not(.dark-mode) .balance-badge.privacy-badge { background: #5a4a80; }
body:not(.dark-mode) .balance-badge.rpm-badge { background: #2a6040; }
body:not(.dark-mode) .heatmap-cell.level-0 { background-color: #e5e5dd; }
body:not(.dark-mode) .heatmap-cell.level-4 { box-shadow: none; }
body:not(.dark-mode) .heatmap-cell[data-tooltip]:hover::after { background: #222; color: #ccc; border-color: #444; }
body:not(.dark-mode) .heatmap-cell[data-tooltip]:hover::before { border-top-color: #222; }

/* Light scrollbar */
body:not(.dark-mode):not(.log-page) { scrollbar-color: #ccc #f4f3ef; }
body:not(.dark-mode):not(.log-page)::-webkit-scrollbar-track { background: #f4f3ef; }
body:not(.dark-mode):not(.log-page)::-webkit-scrollbar-thumb { background: #ccc; }
body:not(.dark-mode):not(.log-page)::-webkit-scrollbar-thumb:hover { background: #aaa; }

/* Dark mode scrollbar for config editor */
body.dark-mode .config-editor { scrollbar-color: #2a2a2a var(--bg-input); }
body.dark-mode .config-editor::-webkit-scrollbar { width: 8px; }
body.dark-mode .config-editor::-webkit-scrollbar-track { background: var(--bg-input); }
body.dark-mode .config-editor::-webkit-scrollbar-thumb { background: #2a2a2a; }
body.dark-mode .config-editor::-webkit-scrollbar-thumb:hover { background: #3a3a3a; }
body.dark-mode { scrollbar-color: #2a2a2a #0c0c0c; }

/* === RESPONSIVE === */
@media (max-width: 1240px) {
    .dashboard {
        grid-template-columns: 1fr;
    }
    .panel-channels,
    .panel-system,
    .panel-usage-activity,
    .panel-info {
        grid-column: 1;
    }
    .moss-link { display: none; }
}

@media (max-width: 900px) {
    .topbar { padding: 0 10px; }
    .topbar-right { gap: 2px; }
    .topbar-revenue { font-size: 12px; margin-right: 4px; }
    .btn { padding: 4px 8px; font-size: 10px; }
    .info-desc-toggle { display: inline-block; }
    .sys-label { width: 6ch; }
    .req-stats-rate { width: 0; overflow: hidden; }
    .skeleton-req-bar { width: 40ch; }
    .guide-columns { flex-direction: column; gap: 12px; }
    .codex-overview-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 420px) {
    .topbar { height: 36px; padding: 0 8px; }
    .topbar-brand { font-size: 13px; }
    .topbar-revenue { display: none; }
    .btn { padding: 3px 6px; font-size: 9px; letter-spacing: 0.04em; }
    .panel-body { padding: 4px 8px 8px; }
    .channel-btn { padding: 3px 8px; font-size: 11px; }
    .codex-overview-grid { grid-template-columns: 1fr; }
    .codex-card { min-height: 0; padding: 10px; }
    .codex-meter { padding: 0; }
    .codex-meter-head { gap: 6px; font-size: 9px; }
}

/* Screensaver overlay */
.screensaver-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: #000;
    cursor: pointer;
    animation: screensaver-fadein 0.8s ease;
}
.screensaver-iframe {
    width: 100%;
    height: 100%;
    border: none;
    pointer-events: none;
}
@keyframes screensaver-fadein {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* === KIRO MANAGE === */
.kiro-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
    overflow-y: auto;
}
.kiro-card {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-input);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.kiro-card-error {
    border-color: #8b2020;
    cursor: pointer;
}
.kiro-card-error:hover {
    background: rgba(139, 32, 32, 0.1);
}
.kiro-card-selected {
    border-color: #a52a2a;
    background: rgba(139, 32, 32, 0.2);
    box-shadow: 0 0 0 1px #a52a2a;
}
.kiro-card-id {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-bright);
    letter-spacing: 0.05em;
}
.kiro-card-balance {
    font-size: 13px;
    color: var(--accent);
    font-weight: 600;
}
.kiro-card-error-msg {
    font-size: 11px;
    color: #c55;
    word-break: break-word;
}
.kiro-empty {
    padding: 24px;
    text-align: center;
    color: var(--text-dim);
    font-size: 12px;
}
