/* ============================================================
   Radio Monitor – Dark Monitoring Theme
   ============================================================ */

:root {
    --bg-base:      #0f1117;
    --bg-surface:   #1a1d27;
    --bg-elevated:  #222536;
    --bg-hover:     #2a2e42;

    --border:       #2e3348;
    --border-light: #3a3f58;

    --text-primary:   #e8eaf0;
    --text-secondary: #8b91a8;
    --text-muted:     #5c6280;

    --accent:       #3b82f6;
    --accent-hover: #2563eb;
    --accent-light: #1d3a6e;

    --green:  #22c55e;
    --red:    #ef4444;
    --yellow: #f59e0b;
    --orange: #f97316;
    --purple: #a855f7;

    --green-bg: rgba(34,197,94,.12);
    --red-bg:   rgba(239,68,68,.12);
    --yellow-bg:rgba(245,158,11,.12);

    --radius-sm: 6px;
    --radius:    10px;
    --radius-lg: 16px;

    --shadow: 0 4px 24px rgba(0,0,0,.35);
    --transition: .18s ease;

    --font: 'Inter', 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
img { max-width: 100%; }
input, select, textarea, button { font-family: inherit; }

/* ── Layout ── */
.app-layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.main-content {
    flex: 1;
    min-width: 0;
    padding: 24px;
    overflow-x: hidden;
}

/* ── Sidebar ── */
.sidebar-logo {
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--border);
}
.sidebar-logo .logo-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.sidebar-logo .logo-icon {
    width: 28px; height: 28px;
    background: var(--accent);
    border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
}
.sidebar-nav { padding: 8px 8px; flex: 1; }
.nav-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
    padding: 12px 8px 4px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: background var(--transition), color var(--transition);
    font-size: 13.5px;
    font-weight: 500;
    margin-bottom: 1px;
}
.nav-item:hover, .nav-item.active {
    background: var(--bg-elevated);
    color: var(--text-primary);
}
.nav-item.active { color: var(--accent); }
.nav-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 12px 8px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
}

/* ── Cards ── */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.card-header {
    padding: 16px 20px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}
.card-body { padding: 20px; }

/* ── Stat Widgets ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-widget {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}
.stat-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
}
.stat-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ── Radio Cards (dashboard overview) ── */
.radio-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.radio-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    transition: border-color var(--transition);
    text-decoration: none;
    color: inherit;
    display: block;
}
.radio-card:hover { border-color: var(--border-light); color: inherit; }
.radio-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 12px;
}
.radio-card-name {
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.radio-color-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: .06em;
}
.status-online  { background: var(--green-bg);  color: var(--green); }
.status-offline { background: var(--red-bg);    color: var(--red); }
.status-unknown { background: var(--yellow-bg); color: var(--yellow); }

.radio-card-listeners {
    font-size: 36px;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 4px;
}
.radio-card-song {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 12px;
}
.radio-card-meta {
    display: flex;
    gap: 16px;
    font-size: 12px;
}
.radio-meta-item { color: var(--text-secondary); }
.radio-meta-item strong { color: var(--text-primary); font-weight: 600; }
.radio-meta-item small { color: var(--text-muted); }

/* ── Charts ── */
.chart-wrapper {
    position: relative;
    height: 280px;
}
.chart-wrapper.tall { height: 360px; }

/* ── Tables ── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.data-table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-hover); }
.data-table td.strong { color: var(--text-primary); font-weight: 500; }
.data-table td.mono { font-family: var(--font-mono); font-size: 12px; }

/* ── Forms ── */
.form-group { margin-bottom: 18px; }
.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.form-control {
    width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 9px 12px;
    font-size: 14px;
    transition: border-color var(--transition);
    appearance: none;
}
.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.form-control::placeholder { color: var(--text-muted); }
.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
    white-space: nowrap;
    text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-secondary { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--border-light); color: var(--text-primary); }
.btn-danger  { background: rgba(239,68,68,.15); color: var(--red); border-color: rgba(239,68,68,.3); }
.btn-danger:hover { background: rgba(239,68,68,.25); }
.btn-success { background: rgba(34,197,94,.15); color: var(--green); border-color: rgba(34,197,94,.3); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 7px; }

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
}
.badge-success { background: var(--green-bg);  color: var(--green); }
.badge-error   { background: var(--red-bg);    color: var(--red); }
.badge-warning { background: var(--yellow-bg); color: var(--yellow); }
.badge-info    { background: var(--accent-light); color: var(--accent); }

/* ── Alerts ── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid;
    font-size: 13.5px;
    margin-bottom: 16px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.alert-success { background: var(--green-bg);  border-color: rgba(34,197,94,.25);  color: var(--green); }
.alert-error   { background: var(--red-bg);    border-color: rgba(239,68,68,.25);  color: var(--red); }
.alert-warning { background: var(--yellow-bg); border-color: rgba(245,158,11,.25); color: var(--yellow); }
.alert-info    { background: var(--accent-light); border-color: rgba(59,130,246,.25); color: var(--accent); }

/* ── Period Tabs ── */
.period-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}
.period-tab {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    transition: all var(--transition);
    text-decoration: none;
}
.period-tab:hover, .period-tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ── Chart Toggle ── */
.chart-toggle {
    display: flex;
    gap: 4px;
}
.chart-toggle-btn {
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}
.chart-toggle-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ── Page Header ── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 4px;
}
.page-subtitle { font-size: 13px; color: var(--text-secondary); margin: 0; }

/* ── Sections ── */
.section { margin-bottom: 28px; }
.section-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── Divider ── */
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ── Login Page ── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.login-box {
    width: 100%;
    max-width: 380px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
}
.login-logo {
    text-align: center;
    margin-bottom: 28px;
}
.login-logo-icon {
    width: 48px; height: 48px;
    background: var(--accent);
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin-bottom: 12px;
}
.login-logo h1 {
    font-size: 20px;
    font-weight: 700;
    margin: 0 0 4px;
}
.login-logo p { font-size: 13px; color: var(--text-secondary); margin: 0; }

/* ── Hourly Table ── */
.hourly-table-wrap { overflow-x: auto; }
.hourly-bar {
    display: inline-block;
    height: 10px;
    border-radius: 2px;
    background: var(--accent);
    min-width: 2px;
    transition: width .3s;
}

/* ── API Test Result ── */
.test-result {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    font-size: 13px;
    font-family: var(--font-mono);
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 300px;
    overflow-y: auto;
}

/* ── Worker Log Colors ── */
.log-success { color: var(--green); }
.log-error   { color: var(--red); }
.log-timeout { color: var(--yellow); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ── */
@media (max-width: 900px) {
    .app-layout { flex-direction: column; }
    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .sidebar-logo { padding: 12px 16px; border-bottom: none; border-right: 1px solid var(--border); }
    .sidebar-nav { display: flex; flex-direction: row; align-items: center; padding: 8px; }
    .nav-section-title { display: none; }
    .sidebar-footer { display: none; }
    .main-content { padding: 16px; }
    .form-row { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .radio-cards-grid { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; }
    .stat-value { font-size: 22px; }
}

/* ── ApexCharts Overrides ── */
.apexcharts-canvas { background: transparent !important; }
.apexcharts-tooltip { font-family: var(--font) !important; }
.chart-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 60px 0;
    font-size: 13px;
}

/* ── Music Stats Tabs ── */
.tab-nav {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}
.tab-btn {
    padding: 10px 18px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: color var(--transition), border-color var(--transition);
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Btn active state ── */
.btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ── Collapsible Sidebar ── */
.sidebar {
    transition: width .22s ease;
    position: relative;
}
.sidebar.collapsed {
    width: 56px;
}
.sidebar.collapsed .sidebar-label {
    display: none;
}
.sidebar.collapsed .nav-section-title {
    display: none;
}
.sidebar.collapsed .sidebar-footer {
    display: none;
}
.sidebar.collapsed .sidebar-logo {
    justify-content: center;
    padding: 16px 0;
}
.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 10px 0;
}
.sidebar.collapsed .sidebar-toggle {
    margin: 0 auto;
}

.main-content {
    transition: margin-left .22s ease;
}

/* Toggle Button */
.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    margin: 12px 12px 4px auto;
    flex-shrink: 0;
    transition: background var(--transition), color var(--transition);
}
.sidebar-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.sidebar.collapsed .sidebar-toggle {
    margin: 12px auto 4px;
}
