:root {
    --bg: #0d0f14;
    --surface: #161922;
    --surface-2: #1e222d;
    --border: #2a2f3b;
    --text: #e8eaed;
    --text-dim: #939aa6;
    --accent: #6366f1;
    --accent-2: #22d3ee;
    --green: #4ade80;
    --amber: #fbbf24;
    --red: #f87171;
    --radius: 12px;
    --shadow: 0 4px 24px rgba(0,0,0,0.35);
    --mono: 'JetBrains Mono', monospace;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100vh;
}

/* Header */
.header {
    background: linear-gradient(135deg, #171a22 0%, #0f1117 100%);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 100;
}
.header-inner {
    max-width: 1320px; margin: 0 auto; padding: 15px 24px;
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
    width: 44px; height: 44px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
    border-radius: 11px; display: grid; place-items: center;
    font-size: 20px; color: #fff;
}
.brand h1 { font-size: 20px; font-weight: 800; letter-spacing: -0.4px; }
.brand p { font-size: 12.5px; color: var(--text-dim); }
.header-status { display: flex; align-items: center; gap: 16px; }
.status-badge { font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: 20px; background: var(--surface-2); color: var(--text-dim); }
.status-badge.ok { background: rgba(74,222,128,0.15); color: var(--green); }
.status-badge.err { background: rgba(248,113,113,0.15); color: var(--red); }
.doc-link { color: var(--accent-2); text-decoration: none; font-size: 13.5px; font-weight: 600; }
.doc-link:hover { text-decoration: underline; }
.admin-user { font-size: 13px; color: var(--text-dim); font-weight: 600; }
.admin-user::before { content: "● "; color: var(--green); }
.logout-btn { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-family: inherit; font-size: 13px; font-weight: 600; padding: 6px 14px; border-radius: 8px; cursor: pointer; transition: all 0.2s; }
.logout-btn:hover { background: rgba(248,113,113,0.14); color: var(--red); border-color: var(--red); }

/* Stats */
.stats-grid {
    max-width: 1320px; margin: 24px auto 0; padding: 0 24px;
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
}
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; min-height: 92px; }
.stat-card .label { font-size: 12px; color: var(--text-dim); font-weight: 500; text-transform: uppercase; letter-spacing: 0.4px; }
.stat-card .value { font-size: 30px; font-weight: 800; margin-top: 6px; letter-spacing: -1px; }
.stat-card .sub { font-size: 12px; color: var(--text-dim); margin-top: 3px; }
.stat-card .value.indigo { color: #818cf8; }
.stat-card .value.cyan { color: var(--accent-2); }
.stat-card .value.green { color: var(--green); }
.skeleton { background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; }
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

.container { max-width: 1320px; margin: 26px auto; padding: 0 24px; }

/* Tabs */
.tabs { display: flex; gap: 6px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.tab { background: none; border: none; color: var(--text-dim); font-family: inherit; font-size: 14.5px; font-weight: 600; padding: 12px 18px; cursor: pointer; position: relative; }
.tab:hover { color: var(--text); }
.tab.active { color: #a5b4fc; }
.tab.active::after { content: ''; position: absolute; bottom: -1px; left: 0; right: 0; height: 2.5px; background: var(--accent); border-radius: 2px; }

.panel { display: none; }
.panel.active { display: block; animation: fadeIn 0.3s; }
@keyframes fadeIn { from{opacity:0; transform:translateY(6px)} to{opacity:1} }

/* Section row (mini cards) */
.section-row { display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.mini-card { flex: 1; min-width: 280px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.mini-card.grow { flex: 1 1 100%; }
.mini-label { font-size: 12px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 16px; }

/* Bar chart */
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 120px; }
.bar { flex: 1; background: linear-gradient(180deg, var(--accent) 0%, #4f46e5 100%); border-radius: 4px 4px 0 0; min-height: 4px; position: relative; transition: opacity 0.2s; }
.bar:hover { opacity: 0.8; }
.bar .bar-val { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--text-dim); white-space: nowrap; }
.bar .bar-day { position: absolute; bottom: -18px; left: 50%; transform: translateX(-50%); font-size: 9px; color: var(--text-dim); white-space: nowrap; }
.bar-chart-wrap { padding-bottom: 20px; }

/* Rank list */
.rank-list { display: flex; flex-direction: column; gap: 10px; }
.rank-item { display: flex; align-items: center; justify-content: space-between; font-size: 13px; }
.rank-item .ep { font-family: var(--mono); font-size: 12px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 70%; }
.rank-item .cnt { font-weight: 700; color: #a5b4fc; }

.block-title { font-size: 15px; font-weight: 700; margin: 8px 0 14px; display: flex; align-items: center; gap: 12px; }
.refresh-note { font-size: 11px; font-weight: 500; color: var(--text-dim); background: var(--surface-2); padding: 3px 9px; border-radius: 12px; }

/* Table */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table-wrap.flat { box-shadow: none; }
table { width: 100%; border-collapse: collapse; }
thead th { background: var(--surface-2); color: var(--text-dim); font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; padding: 12px 15px; text-align: left; border-bottom: 1px solid var(--border); }
thead th.num { text-align: right; }
tbody td { padding: 11px 15px; font-size: 13.5px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono, .mono-text { font-family: var(--mono); font-size: 12px; }
.pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 6px; }
.pill.s200 { background: rgba(74,222,128,0.14); color: var(--green); }
.pill.s401, .pill.s429 { background: rgba(251,191,36,0.14); color: var(--amber); }
.pill.s500, .pill.failed { background: rgba(248,113,113,0.14); color: var(--red); }
.pill.success { background: rgba(74,222,128,0.14); color: var(--green); }
.pill.src { background: rgba(34,211,238,0.12); color: var(--accent-2); }
.pill.on { background: rgba(74,222,128,0.14); color: var(--green); }
.pill.off { background: rgba(248,113,113,0.14); color: var(--red); }
.empty { padding: 44px; text-align: center; color: var(--text-dim); }
.dim { color: var(--text-dim); }

/* Scraper Control */
.run-status { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.run-dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.run-dot.idle { background: var(--text-dim); }
.run-dot.running { background: var(--amber); animation: pulse 1.2s infinite; }
.run-dot.done { background: var(--green); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }
.run-elapsed { font-size: 13px; color: var(--text-dim); font-weight: 500; }
.run-message { font-size: 13px; color: var(--text-dim); min-height: 18px; margin-bottom: 14px; }
.run-buttons { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-run { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-family: inherit; font-size: 13.5px; font-weight: 600; padding: 10px 16px; border-radius: 9px; cursor: pointer; transition: all 0.2s; }
.btn-run:hover:not(:disabled) { border-color: var(--accent); color: #a5b4fc; }
.btn-run.primary { background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%); color: #fff; border: none; }
.btn-run.primary:hover:not(:disabled) { opacity: 0.9; }
.btn-run:disabled { opacity: 0.5; cursor: not-allowed; }
.run-result { margin-top: 14px; font-size: 13px; }
.run-result .ok { color: var(--green); }
.run-result .err { color: var(--red); }

/* Schedule */
.switch-row { display: flex; align-items: center; gap: 10px; font-size: 14px; margin-bottom: 18px; cursor: pointer; }
.switch-row input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.times-label { font-size: 12px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 10px; }
.times-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; min-height: 30px; }
.time-chip { display: inline-flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-family: var(--mono); font-size: 13px; }
.time-chip button { background: none; border: none; color: var(--red); cursor: pointer; font-size: 15px; line-height: 1; padding: 0; }
.add-time-row { display: flex; gap: 8px; margin-bottom: 16px; }
.add-time-row input { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-family: inherit; font-size: 14px; padding: 8px 10px; border-radius: 8px; }
.btn-add { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-family: inherit; font-size: 13px; font-weight: 600; padding: 8px 14px; border-radius: 8px; cursor: pointer; }
.btn-add:hover { border-color: var(--accent); }
.btn-save { background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%); color: #fff; border: none; font-family: inherit; font-size: 14px; font-weight: 700; padding: 11px 20px; border-radius: 9px; cursor: pointer; }
.btn-save:hover { opacity: 0.9; }
.schedule-msg { margin-top: 12px; font-size: 13px; color: var(--green); min-height: 18px; }

/* API key form */
.key-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.kf-field { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 180px; }
.kf-field.small { flex: 0 0 120px; min-width: 120px; }
.kf-field label { font-size: 12px; font-weight: 600; color: var(--text-dim); }
.kf-field input { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-family: inherit; font-size: 14px; padding: 9px 12px; border-radius: 8px; outline: none; }
.kf-field input:focus { border-color: var(--accent); }
.new-key-result { margin-top: 14px; font-size: 13px; }
.new-key-result .key-box { background: #0b0d12; border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; font-family: var(--mono); font-size: 13px; color: var(--green); word-break: break-all; margin-top: 8px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.copy-btn { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-family: inherit; font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.copy-btn:hover { border-color: var(--accent); }
.domain-input { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-family: var(--mono); font-size: 12px; padding: 5px 8px; border-radius: 6px; width: 160px; }
.act-btn { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-family: inherit; font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 6px; cursor: pointer; margin-left: 4px; }
.act-btn.save:hover { border-color: var(--green); color: var(--green); }
.act-btn.del:hover { border-color: var(--red); color: var(--red); }
.act-btn.toggle:hover { border-color: var(--amber); color: var(--amber); }

.footer { text-align: center; padding: 30px 24px; color: var(--text-dim); font-size: 13px; }
.footer code { font-family: var(--mono); background: var(--surface-2); padding: 2px 7px; border-radius: 5px; color: var(--accent-2); }

@media (max-width: 900px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) {
    .stats-grid { grid-template-columns: 1fr; }
    .table-wrap { overflow-x: auto; } table { min-width: 640px; }
}
