/* ============================================================
   ATIME LIVE METER — Design System
   Dark Mode | โทนสีแดง-ดำ | Inter Font
   ============================================================ */

/* ── Variables ─────────────────────────────────────────── */
:root {
    /* Background */
    --bg-base:      #0B0B0B;
    --bg-surface:   #111111;
    --bg-card:      #181818;
    --bg-card-2:    #202020;
    --bg-input:     #141414;

    /* Primary Red */
    --red-500:      #E5212A;
    --red-700:      #B71C1C;
    --red-900:      #7B0000;
    --red-grad:     linear-gradient(135deg, #E5212A 0%, #8B0000 100%);
    --red-grad-h:   linear-gradient(135deg, #FF3B45 0%, #A00000 100%);
    --red-glow:     rgba(229, 33, 42, 0.18);
    --red-glow-lg:  rgba(229, 33, 42, 0.32);

    /* Text */
    --text-1:       #F2F2F2;
    --text-2:       #C0C0C0;
    --text-3:       #7A7A7A;
    --text-4:       #484848;

    /* Border */
    --border:       rgba(255, 255, 255, 0.07);
    --border-red:   rgba(229, 33, 42, 0.28);
    --border-focus: rgba(229, 33, 42, 0.55);

    /* Status */
    --green:        #22c55e;
    --green-bg:     rgba(34, 197, 94, 0.1);
    --green-border: rgba(34, 197, 94, 0.25);

    /* Layout */
    --sidebar-w:    265px;
    --topbar-h:     60px;

    /* Spacing / Radius */
    --r-sm:  8px;
    --r-md:  12px;
    --r-lg:  16px;
    --r-xl:  20px;

    /* Shadows */
    --shadow:      0 4px 24px rgba(0, 0, 0, 0.5);
    --shadow-red:  0 4px 20px rgba(229, 33, 42, 0.22);
    --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.35);

    /* Transitions */
    --t-fast:  0.18s cubic-bezier(0.4, 0, 0.2, 1);
    --t-med:   0.28s cubic-bezier(0.4, 0, 0.2, 1);
    --t-slow:  0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-base);
    color: var(--text-1);
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

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

/* ── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar              { width: 5px; height: 5px; }
::-webkit-scrollbar-track        { background: var(--bg-surface); }
::-webkit-scrollbar-thumb        { background: #2C2C2C; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover  { background: var(--red-900); }

/* ══════════════════════════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════════════════════════ */
.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0; top: 0;
    z-index: 1000;
    transition: transform var(--t-med);
}

/* Logo */
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 22px 18px 22px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.logo-icon {
    width: 38px; height: 38px;
    background: var(--red-grad);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: var(--shadow-red);
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}
.logo-icon::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 60%);
}
.logo-letter {
    font-size: 19px; font-weight: 900;
    color: #fff; letter-spacing: -1px;
    position: relative; z-index: 1;
}

.logo-text { display: flex; flex-direction: column; line-height: 1; }
.logo-title {
    font-size: 13px; font-weight: 800;
    color: var(--text-1); letter-spacing: 2.5px;
}
.logo-sub {
    font-size: 9.5px; font-weight: 500;
    color: var(--text-3); letter-spacing: 1.8px;
    margin-top: 3px;
}

/* Nav Items */
.sidebar-nav {
    list-style: none;
    padding: 14px 12px;
    flex: 1;
    overflow-y: auto;
}
.nav-item { margin-bottom: 3px; }

.sidebar-nav .nav-link,
.sidebar-footer .nav-link {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 13px;
    border-radius: var(--r-sm);
    color: var(--text-3);
    font-size: 13.5px; font-weight: 500;
    transition: var(--t-fast);
    position: relative;
    white-space: nowrap;
    overflow: hidden;
}
.sidebar-nav .nav-link i,
.sidebar-footer .nav-link i {
    width: 17px; text-align: center;
    font-size: 14px; flex-shrink: 0;
    transition: var(--t-fast);
}

.sidebar-nav .nav-link:hover {
    background: var(--red-grad);
    color: #fff;
    box-shadow: var(--shadow-red);
}
.sidebar-nav .nav-link:hover i { color: #fff; }

.nav-item.active .nav-link {
    background: var(--red-grad);
    color: #fff;
    box-shadow: var(--shadow-red);
}

/* Sidebar Section Label */
.sidebar-section {
    font-size: 10px; font-weight: 700;
    color: var(--text-4); letter-spacing: 1.5px;
    text-transform: uppercase;
    padding: 12px 13px 6px;
    margin-top: 4px;
}

/* Footer */
.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.nav-link-danger { color: #f87171 !important; }
.nav-link-danger:hover {
    background: rgba(239,68,68,0.12) !important;
    box-shadow: none !important;
    color: #fca5a5 !important;
}

/* ══════════════════════════════════════════════════════════
   MAIN CONTENT
   ══════════════════════════════════════════════════════════ */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left var(--t-med);
    min-width: 0;
}

/* ── Top Bar ────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 24px; gap: 14px;
    position: sticky; top: 0; z-index: 500;
    flex-shrink: 0;
}

.sidebar-toggle {
    display: none;
    background: none; border: none;
    color: var(--text-3); font-size: 17px;
    cursor: pointer; padding: 6px 8px;
    border-radius: var(--r-sm);
    transition: var(--t-fast);
    line-height: 1;
}
.sidebar-toggle:hover { color: var(--red-500); background: var(--red-glow); }

.topbar-title {
    flex: 1;
    font-size: 16px; font-weight: 700;
    color: var(--text-1);
}

.topbar-right { display: flex; align-items: center; gap: 10px; }

/* Live Status Badge */
.live-badge {
    display: flex; align-items: center; gap: 7px;
    padding: 5px 13px;
    background: var(--green-bg);
    border: 1px solid var(--green-border);
    border-radius: 20px;
    font-size: 11.5px; font-weight: 600;
    color: var(--green);
}
.live-dot {
    width: 7px; height: 7px;
    background: var(--green);
    border-radius: 50%;
    animation: pulse-live 2s ease-in-out infinite;
}
@keyframes pulse-live {
    0%, 100% { box-shadow: 0 0 0 0   rgba(34,197,94,0.5); }
    50%       { box-shadow: 0 0 0 5px rgba(34,197,94,0);   }
}

/* ── Page Content ───────────────────────────────────────── */
.page-content { padding: 26px 28px; flex: 1; }

/* ══════════════════════════════════════════════════════════
   COMPONENTS
   ══════════════════════════════════════════════════════════ */

/* ── Section Header ─────────────────────────────────────── */
.section-header {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 18px;
}
.section-bar {
    width: 3px; height: 20px;
    background: var(--red-grad);
    border-radius: 2px;
    flex-shrink: 0;
}
.section-title {
    font-size: 15px; font-weight: 700;
    color: var(--text-1);
}
.section-sub {
    font-size: 12px; font-weight: 500;
    color: var(--text-3);
    margin-left: auto;
}

/* ── Cards ──────────────────────────────────────────────── */
.card-dark {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    transition: var(--t-fast);
}
.card-dark:hover {
    border-color: var(--border-red);
    box-shadow: 0 6px 30px rgba(229,33,42,0.09);
}

/* ── Station Card ───────────────────────────────────────── */
.station-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    overflow: hidden;
    transition: var(--t-med);
    display: flex; flex-direction: column;
}
.station-card:hover {
    border-color: var(--border-red);
    box-shadow: 0 8px 40px rgba(229,33,42,0.13);
    transform: translateY(-2px);
}

.station-card-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 22px 14px;
    border-bottom: 1px solid var(--border);
}
.station-name {
    font-size: 15px; font-weight: 700;
    color: var(--text-1); letter-spacing: 0.3px;
}
.station-tag {
    padding: 3px 10px;
    background: var(--red-grad);
    border-radius: 20px;
    font-size: 11px; font-weight: 700;
    color: #fff; letter-spacing: 0.5px;
    box-shadow: var(--shadow-red);
}

.station-card-body { padding: 18px 22px 22px; flex: 1; }

/* Platform Tabs */
.platform-tabs {
    display: flex; gap: 3px;
    background: rgba(255,255,255,0.04);
    border-radius: var(--r-sm);
    padding: 3px;
    margin-bottom: 18px;
}
.platform-tab {
    flex: 1; padding: 7px 10px;
    border: none; background: transparent;
    color: var(--text-3); border-radius: 6px;
    font-size: 12.5px; font-weight: 600;
    cursor: pointer; transition: var(--t-fast);
    font-family: inherit;
    letter-spacing: 0.3px;
}
.platform-tab:hover:not(.active) {
    color: var(--text-2);
    background: rgba(255,255,255,0.05);
}
.platform-tab.active {
    background: var(--red-grad);
    color: #fff;
    box-shadow: var(--shadow-red);
}

/* Gauge Chart Container */
.gauge-wrap { position: relative; height: 220px; }

/* Listener Number */
.listener-big {
    font-size: 46px; font-weight: 800; line-height: 1;
    letter-spacing: -2px;
    background: var(--red-grad);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.listener-label {
    font-size: 12px; font-weight: 500;
    color: var(--text-3); margin-top: 3px;
}

/* Change Badge */
.change-badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 12px; font-weight: 600;
    margin-top: 6px;
}
.change-badge.up   { background: rgba(34,197,94,0.1);   color: #4ade80; border: 1px solid rgba(34,197,94,0.25); }
.change-badge.down { background: rgba(229,33,42,0.1);   color: #f87171; border: 1px solid rgba(229,33,42,0.25); }
.change-badge.nc   { background: rgba(255,255,255,0.05);color: var(--text-3); border: 1px solid var(--border); }

/* Station Mini Grid (Web/App split) */
.station-split {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 10px; margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.split-item { text-align: center; }
.split-label {
    font-size: 10px; font-weight: 700;
    color: var(--text-4); letter-spacing: 1px;
    text-transform: uppercase; margin-bottom: 4px;
}
.split-value {
    font-size: 20px; font-weight: 700;
    color: var(--text-1);
}

/* ── Summary Cards (Dashboard) ──────────────────────────── */
.summary-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 20px 22px;
    transition: var(--t-fast);
    position: relative; overflow: hidden;
}
.summary-card:hover {
    border-color: var(--border-red);
    transform: translateY(-1px);
    box-shadow: 0 8px 24px rgba(229,33,42,0.1);
}
.summary-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--red-grad);
    opacity: 0;
    transition: var(--t-fast);
}
.summary-card:hover::before { opacity: 1; }

.summary-icon {
    width: 40px; height: 40px;
    background: var(--red-glow);
    border: 1px solid var(--border-red);
    border-radius: var(--r-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; color: var(--red-500);
    margin-bottom: 14px;
}
.summary-label {
    font-size: 11px; font-weight: 600;
    color: var(--text-3); letter-spacing: 0.8px;
    text-transform: uppercase; margin-bottom: 6px;
}
.summary-value {
    font-size: 30px; font-weight: 800; line-height: 1;
    letter-spacing: -1px;
    background: var(--red-grad);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.summary-sub {
    font-size: 11.5px; color: var(--text-3);
    margin-top: 5px;
}

/* ── Filter Bar ─────────────────────────────────────────── */
.filter-bar {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px 22px;
    margin-bottom: 22px;
    display: flex; flex-wrap: wrap;
    gap: 14px; align-items: flex-end;
}
.filter-group { display: flex; flex-direction: column; gap: 5px; }
.filter-label-text {
    font-size: 10.5px; font-weight: 700;
    color: var(--text-4); letter-spacing: 0.8px;
    text-transform: uppercase;
}

/* Custom Select */
.custom-select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-1); border-radius: var(--r-sm);
    padding: 8px 32px 8px 12px;
    font-size: 13px; font-family: 'Inter', sans-serif; font-weight: 500;
    cursor: pointer; outline: none;
    transition: var(--t-fast);
    appearance: none; -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23555' fill='none' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 11px center;
    min-width: 190px;
}
.custom-select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--red-glow);
}
.custom-select option { background: var(--bg-card); }

/* Custom Date Input */
.custom-date-input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-1); border-radius: var(--r-sm);
    padding: 7px 12px;
    font-size: 13px; font-family: 'Inter', sans-serif; font-weight: 500;
    outline: none; transition: var(--t-fast);
    color-scheme: dark;
}
.custom-date-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--red-glow);
}

/* Range Buttons */
.range-btns { display: flex; gap: 4px; }
.btn-range {
    padding: 8px 18px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-3); border-radius: var(--r-sm);
    font-size: 13px; font-weight: 500;
    cursor: pointer; transition: var(--t-fast);
    font-family: 'Inter', sans-serif;
}
.btn-range:hover { border-color: var(--border-red); color: var(--text-1); }
.btn-range.active {
    background: var(--red-grad);
    border-color: transparent; color: #fff;
    box-shadow: var(--shadow-red);
}

/* ── Refresh / Status Indicators ────────────────────────── */
.refresh-info {
    display: flex; align-items: center; gap: 7px;
    font-size: 12px; font-weight: 500; color: var(--text-3);
}
.refresh-info i { color: var(--red-500); font-size: 12px; }
.refresh-info strong { color: var(--red-500); font-variant-numeric: tabular-nums; }

.last-update {
    display: flex; align-items: center; gap: 6px;
    font-size: 11.5px; color: var(--text-3);
    padding: 5px 11px;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border);
    border-radius: 20px;
}
.last-update i { font-size: 11px; }

/* ── Chart Containers ───────────────────────────────────── */
.chart-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 22px;
    transition: var(--t-fast);
}
.chart-box:hover { border-color: var(--border-red); }

.chart-loading {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 12px; color: var(--text-3); font-size: 13px;
    min-height: 300px;
}
.spinner {
    width: 28px; height: 28px;
    border: 2.5px solid var(--border);
    border-top-color: var(--red-500);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.no-data {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 12px; color: var(--text-3);
    min-height: 300px;
}
.no-data i { font-size: 36px; opacity: 0.25; }
.no-data p { font-size: 13px; }

/* ── Dashboard Stats Row ────────────────────────────────── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 26px;
}

/* ── Sparkline mini chart wrapper ───────────────────────── */
.mini-chart { height: 60px; margin-top: 12px; }

/* ── Utility ────────────────────────────────────────────── */
.text-red  { color: var(--red-500); }
.text-muted { color: var(--text-3) !important; }
.fw-700 { font-weight: 700; }
.num { font-variant-numeric: tabular-nums; }

/* ══════════════════════════════════════════════════════════
   ANIMATIONS
   ══════════════════════════════════════════════════════════ */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}
.animate-in { animation: fadeInUp 0.4s var(--t-med) both; }
.animate-in-1 { animation-delay: 0.05s; }
.animate-in-2 { animation-delay: 0.10s; }
.animate-in-3 { animation-delay: 0.15s; }
.animate-in-4 { animation-delay: 0.20s; }

/* Skeleton Loading */
@keyframes shimmer {
    0%   { background-position: -600px 0; }
    100% { background-position:  600px 0; }
}
.skeleton {
    background: linear-gradient(90deg, #1A1A1A 25%, #242424 50%, #1A1A1A 75%);
    background-size: 600px 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--r-sm);
}

/* ══════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════ */
@media (max-width: 992px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .sidebar-toggle { display: flex; }

    /* Sidebar overlay */
    .sidebar-overlay {
        display: none; position: fixed; inset: 0;
        background: rgba(0,0,0,0.6); z-index: 999;
    }
    .sidebar-overlay.show { display: block; }
}

@media (max-width: 768px) {
    .page-content { padding: 16px; }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .custom-select { min-width: 100%; }
}
