/* ── ECP Dashboard v2 — Core Layout ── */
:root {
    --teal: #00d4aa;
    --teal-dark: #00a886;
    --bg: #f8fafb;
    --sidebar-bg: #0f172a;
    --sidebar-w: 240px;
    --sidebar-collapsed: 60px;
    --topbar-h: 52px;
    --bottom-nav-h: 56px;
    --card-bg: #ffffff;
    --card-border: #e8ecf0;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --red: #dc2626;
    --orange: #f59e0b;
    --green: #16a34a;
    --blue: #3b82f6;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    overflow: hidden;
}

/* ── App Shell ── */
.app {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease;
    z-index: 100;
    flex-shrink: 0;
    overflow-y: auto;
    overflow-x: hidden;
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .brand-name,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-sub { display: none; }
.sidebar.collapsed .nav-icon { margin-right: 0; font-size: 1.3em; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 12px 0; }
.sidebar.collapsed .toggle-icon { transform: rotate(180deg); }

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.brand-logo {
    background: var(--teal);
    color: white;
    font-weight: 800;
    font-size: 0.85rem;
    padding: 4px 8px;
    border-radius: 6px;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}
.brand-name {
    color: #e2e8f0;
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
}

.sidebar-nav { flex: 1; padding: 8px 0; }
.nav-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    border-radius: 0;
    transition: all 0.15s;
    cursor: pointer;
    border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: #e2e8f0; }
.nav-item.active {
    color: var(--teal);
    background: rgba(0,212,170,0.08);
    border-left-color: var(--teal);
}
.nav-icon { margin-right: 10px; font-size: 1.1em; width: 24px; text-align: center; flex-shrink: 0; }
.nav-label { white-space: nowrap; }

.nav-group { margin-bottom: 2px; }
.nav-sub {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.2s ease;
}
.nav-group:has(.nav-item.active) .nav-sub,
.nav-group:hover .nav-sub { max-height: 500px; overflow: visible; }
.nav-sub-item {
    display: block;
    padding: 6px 16px 6px 50px;
    color: #64748b;
    text-decoration: none;
    font-size: 0.82rem;
    transition: color 0.15s;
}
.nav-sub-item:hover { color: #e2e8f0; }
.nav-sub-item.active { color: var(--teal); font-weight: 600; }

.sidebar-toggle {
    padding: 12px;
    border: none;
    background: none;
    color: #64748b;
    cursor: pointer;
    text-align: center;
    border-top: 1px solid rgba(255,255,255,0.06);
    font-size: 1.2em;
}
.sidebar-toggle:hover { color: #e2e8f0; }
.toggle-icon { transition: transform 0.2s; display: inline-block; }

/* ── Main Content ── */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* ── Top Bar ── */
.topbar {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: white;
    border-bottom: 1px solid var(--card-border);
    flex-shrink: 0;
    z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.breadcrumbs {
    font-size: 0.88rem;
    color: var(--text-secondary);
    font-weight: 500;
}
.breadcrumbs span { color: var(--text-muted); }
.freshness {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--text-muted);
}
.freshness-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
}
.freshness-dot.live, .freshness-dot.fresh {
    background: var(--green);
    box-shadow: 0 0 6px rgba(34,197,94,0.4);
    animation: pulse 2s infinite;
}
.freshness-dot.warn {
    background: var(--orange, #f59e0b);
    box-shadow: 0 0 6px rgba(245,158,11,0.4);
    animation: pulse 2s infinite;
}
.freshness-dot.stale {
    background: var(--red, #ef4444);
    box-shadow: 0 0 6px rgba(239,68,68,0.4);
    animation: pulse 1.5s infinite;
}
.freshness-refresh {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 4px;
    border-radius: 4px;
    color: var(--text-muted);
    transition: all 0.15s;
    line-height: 1;
}
.freshness-refresh:hover {
    background: #f1f5f9;
    color: var(--teal-dark, #0d9488);
}
.freshness-refresh.spinning {
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
.freshness-toast {
    position: fixed;
    top: 16px;
    right: 16px;
    background: var(--sidebar-bg, #0f172a);
    color: #e2e8f0;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 0.82rem;
    z-index: 9999;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    transition: opacity 0.3s;
}
.freshness-toast.hidden { display: none; }
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
.search-btn {
    background: #f1f5f9;
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}
.search-btn kbd {
    background: white;
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 1px 5px;
    font-size: 0.75rem;
    font-family: inherit;
}
.search-btn:hover { border-color: var(--teal); }
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.3rem;
    color: var(--text);
    cursor: pointer;
    padding: 4px 8px;
}

/* ── Page Container ── */
.page-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    -webkit-overflow-scrolling: touch;
}

/* ── Bottom Nav ── */
.bottom-nav {
    display: none;
    background: white;
    border-top: 1px solid var(--card-border);
    height: var(--bottom-nav-h);
    align-items: center;
    justify-content: space-around;
    flex-shrink: 0;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 500;
    padding: 6px 12px;
    min-width: 64px;
    min-height: 44px;
    justify-content: center;
}
.bottom-nav-item.active { color: var(--teal-dark); }
.bottom-nav-icon { font-size: 1.4em; }

/* ── Search Modal ── */
.search-modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: flex-start; justify-content: center; padding-top: 80px; }
.search-modal.hidden { display: none; }
.search-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); }
.search-box {
    position: relative;
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 540px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.search-box input {
    width: 100%;
    padding: 16px 20px;
    border: none;
    font-size: 1rem;
    outline: none;
    border-bottom: 1px solid var(--card-border);
}
.search-results { padding: 8px 0; max-height: 400px; overflow-y: auto; }
.search-group-label { padding: 8px 20px 4px; font-size: 0.7rem; text-transform: uppercase; color: var(--text-muted); font-weight: 600; letter-spacing: 0.5px; }
.search-result {
    display: block;
    padding: 10px 20px;
    text-decoration: none;
    color: var(--text);
    font-size: 0.88rem;
    transition: background 0.1s;
}
.search-result:hover { background: #f0fffe; }

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        bottom: 0;
        transition: left 0.25s ease;
        z-index: 200;
    }
    .sidebar.open { left: 0; }
    .sidebar-toggle { display: none; }
    .mobile-menu-btn { display: block; }
    .bottom-nav { display: flex; }
    .page-container { padding: 14px; padding-bottom: calc(14px + var(--bottom-nav-h)); }
    .search-btn kbd { display: none; }
    .topbar { padding: 0 14px; }
}
@media (max-width: 480px) {
    html { font-size: 14px; }
    .page-container { padding: 10px; padding-bottom: calc(10px + var(--bottom-nav-h)); }
}
