/* QPM Dashboard — Dark Premium Theme
   Inspired by Wealthfront/Revolut fintech aesthetic
   Fully responsive: mobile-first with breakpoints at 768px and 1024px
*/

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* Backgrounds */
    --bg-primary: #13151a;
    --bg-secondary: #1a1d28;
    --bg-card: rgba(255, 255, 255, 0.04);
    --bg-card-hover: rgba(255, 255, 255, 0.07);
    --bg-sidebar: #111318;
    --bg-input: rgba(255, 255, 255, 0.06);

    /* Borders */
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(108, 140, 255, 0.4);

    /* Text */
    --text-primary: #e4e4e7;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --text-inverse: #13151a;

    /* Accents */
    --accent-blue: #6c8cff;
    --accent-blue-dim: rgba(108, 140, 255, 0.15);
    --accent-green: #4ade80;
    --accent-green-dim: rgba(74, 222, 128, 0.12);
    --accent-red: #ff4444;
    --accent-red-dim: rgba(255, 68, 68, 0.12);
    --accent-yellow: #facc15;
    --accent-yellow-dim: rgba(250, 204, 21, 0.12);

    /* Layout */
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --bottom-nav-height: 64px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-elevated: 0 4px 12px rgba(0, 0, 0, 0.4);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

a { color: var(--accent-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== LAYOUT ===== */
.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--transition-base);
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== SIDEBAR ===== */
.sidebar-logo {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.sidebar-logo span {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: block;
    margin-top: 2px;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition-fast);
    cursor: pointer;
    text-decoration: none;
}

.nav-item:hover {
    background: var(--bg-card);
    color: var(--text-primary);
    text-decoration: none;
}

.nav-item.active {
    background: var(--accent-blue-dim);
    color: var(--accent-blue);
}

.nav-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.nav-separator {
    height: 1px;
    background: var(--border-subtle);
    margin: 12px 0;
}

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid var(--border-subtle);
}

/* ===== TOPBAR ===== */
.topbar {
    height: var(--topbar-height);
    padding: 0 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-subtle);
    background: rgba(19, 21, 26, 0.8);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

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

.topbar-user {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ===== PAGE CONTENT ===== */
.page-content {
    padding: 32px;
    flex: 1;
}

/* ===== GRID SYSTEM ===== */
.grid {
    display: grid;
    gap: 24px;
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* ===== CARDS ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 24px;
    box-shadow: var(--shadow-card);
    transition: all var(--transition-fast);
}

.card:hover {
    background: var(--bg-card-hover);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.card-value {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.card-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ===== KPI CARD ===== */
.kpi-card { text-align: left; }

.kpi-card .card-value.positive { color: var(--accent-green); }
.kpi-card .card-value.negative { color: var(--accent-red); }
.kpi-card .card-value.neutral { color: var(--accent-blue); }

/* ===== REGIME BADGE ===== */
.regime-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.regime-badge.bull {
    background: var(--accent-green-dim);
    color: var(--accent-green);
}

.regime-badge.neutral {
    background: var(--accent-yellow-dim);
    color: var(--accent-yellow);
}

.regime-badge.bear {
    background: var(--accent-red-dim);
    color: var(--accent-red);
}

.regime-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ===== REGIME SEMAPHORE (Home) ===== */
.semaphore {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 0 auto 16px;
}

.semaphore.bull {
    background: radial-gradient(circle, var(--accent-green) 0%, rgba(74, 222, 128, 0.2) 70%);
    color: var(--text-inverse);
    box-shadow: 0 0 40px rgba(74, 222, 128, 0.3);
}

.semaphore.neutral {
    background: radial-gradient(circle, var(--accent-yellow) 0%, rgba(250, 204, 21, 0.2) 70%);
    color: var(--text-inverse);
    box-shadow: 0 0 40px rgba(250, 204, 21, 0.3);
}

.semaphore.bear {
    background: radial-gradient(circle, var(--accent-red) 0%, rgba(255, 68, 68, 0.2) 70%);
    color: #fff;
    box-shadow: 0 0 40px rgba(255, 68, 68, 0.3);
}

/* ===== QRS BAR ===== */
.qrs-bar-container {
    width: 100%;
    margin: 16px 0;
}

.qrs-bar {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(to right,
        var(--accent-green) 0%, var(--accent-green) 33%,
        var(--accent-yellow) 33%, var(--accent-yellow) 66%,
        var(--accent-red) 66%, var(--accent-red) 100%
    );
    position: relative;
    opacity: 0.3;
}

.qrs-bar-marker {
    position: absolute;
    top: -6px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #fff;
    border: 3px solid var(--bg-primary);
    box-shadow: var(--shadow-elevated);
    transform: translateX(-50%);
    transition: left var(--transition-base);
}

/* ===== TABLES ===== */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

thead th {
    text-align: left;
    padding: 12px 16px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-subtle);
}

tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
}

tbody tr:hover {
    background: var(--bg-card);
}

tbody tr.refuge td {
    background: var(--accent-blue-dim);
}

.text-green { color: var(--accent-green); }
.text-red { color: var(--accent-red); }
.text-yellow { color: var(--accent-yellow); }
.text-blue { color: var(--accent-blue); }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* ===== BADGES ===== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-green, .badge-ok { background: var(--accent-green-dim); color: var(--accent-green); }
.badge-red, .badge-error { background: var(--accent-red-dim); color: var(--accent-red); }
.badge-yellow, .badge-warn { background: var(--accent-yellow-dim); color: var(--accent-yellow); }
.badge-blue { background: var(--accent-blue-dim); color: var(--accent-blue); }

/* ===== ALERTS ===== */
.alert { padding: 16px 20px; border-radius: var(--radius-md); margin-bottom: 16px; }
.alert-error { background: var(--accent-red-dim); color: var(--accent-red); border: 1px solid rgba(239,68,68,0.2); }

/* ===== ROW STATES ===== */
.row-warning { background: rgba(245,158,11,0.05); }

/* ===== BUTTONS ===== */
.btn { padding: 8px 16px; border-radius: var(--radius-md); font-size: 0.8rem; font-weight: 500; cursor: pointer; border: 1px solid var(--border); background: var(--card-bg); color: var(--text-primary); transition: all 0.15s; }
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 5px 12px; font-size: 0.75rem; }

/* ===== FORMS ===== */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color var(--transition-fast);
    outline: none;
}

.form-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px var(--border-focus);
}

.form-input::placeholder {
    color: var(--text-muted);
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: none;
    transition: all var(--transition-fast);
}

.btn-primary {
    background: var(--accent-blue);
    color: #fff;
}

.btn-primary:hover {
    background: #5a7af0;
    box-shadow: 0 2px 8px rgba(108, 140, 255, 0.3);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
}

.btn-ghost:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

.btn-block {
    width: 100%;
}

/* ===== PERIOD TABS ===== */
.period-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 4px;
}

.period-tab {
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
    background: transparent;
    font-family: inherit;
}

.period-tab:hover {
    color: var(--text-primary);
}

.period-tab.active {
    background: var(--accent-blue-dim);
    color: var(--accent-blue);
}

/* ===== CHART CONTAINER ===== */
.chart-container {
    width: 100%;
    min-height: 300px;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.chart-container-sm {
    min-height: 180px;
}

/* ===== TIMELINE ===== */
.timeline {
    position: relative;
    padding-left: 24px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border-subtle);
}

.timeline-item {
    position: relative;
    padding-bottom: 24px;
}

.timeline-dot {
    position: absolute;
    left: -20px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent-blue);
    border: 2px solid var(--bg-primary);
}

.timeline-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.timeline-content {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* ===== COMPONENT CARD (QRS) ===== */
.component-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
}

.component-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.component-indicator.ok { background: var(--accent-green); }
.component-indicator.active { background: var(--accent-red); }

.component-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
}

.component-detail {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ===== LOGIN PAGE ===== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 40px 32px;
    box-shadow: var(--shadow-elevated);
}

.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 8px;
}

.login-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 32px;
}

.login-error {
    background: var(--accent-red-dim);
    color: var(--accent-red);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 20px;
}

/* ===== LOADING SKELETON ===== */
.skeleton {
    background: linear-gradient(90deg,
        var(--bg-card) 25%,
        var(--bg-card-hover) 50%,
        var(--bg-card) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text { height: 16px; margin-bottom: 8px; }
.skeleton-title { height: 32px; width: 60%; margin-bottom: 16px; }
.skeleton-chart { height: 200px; }

/* ===== BOTTOM NAV (MOBILE) ===== */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border-subtle);
    z-index: 100;
    padding: 0 8px;
}

.bottom-nav-items {
    display: flex;
    height: 100%;
    align-items: center;
    justify-content: space-around;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 500;
    text-decoration: none;
    transition: color var(--transition-fast);
}

.bottom-nav-item svg {
    width: 22px;
    height: 22px;
}

.bottom-nav-item.active {
    color: var(--accent-blue);
}

.bottom-nav-item:hover {
    color: var(--text-primary);
    text-decoration: none;
}

/* ===== HAMBURGER (MOBILE) ===== */
.hamburger {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
}

.hamburger svg {
    width: 24px;
    height: 24px;
}

/* ===== OVERLAY (MOBILE SIDEBAR) ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

/* ===== FILTER BAR ===== */
.filter-bar {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.filter-bar .form-input {
    width: auto;
    min-width: 160px;
}

/* ===== PAGINATION ===== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 24px;
}

.pagination button {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}

.pagination button.active {
    background: var(--accent-blue-dim);
    color: var(--accent-blue);
    border-color: var(--accent-blue);
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    opacity: 0.4;
}

.empty-state p {
    font-size: 0.9rem;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============================================
   RESPONSIVE BREAKPOINTS
   Mobile-first: default is mobile
   768px+ = tablet
   1024px+ = desktop
   ============================================ */

/* --- MOBILE (default, <768px) --- */
@media (max-width: 767px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.open {
        display: block;
    }

    .main-content {
        margin-left: 0;
        padding-bottom: var(--bottom-nav-height);
    }

    .bottom-nav {
        display: block;
    }

    .hamburger {
        display: block;
    }

    .topbar {
        padding: 0 16px;
    }

    .page-content {
        padding: 20px 16px;
    }

    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }

    .card {
        padding: 16px;
    }

    .card-value {
        font-size: 1.5rem;
    }

    .semaphore {
        width: 90px;
        height: 90px;
        font-size: 0.8rem;
    }

    .filter-bar {
        flex-direction: column;
    }

    .filter-bar .form-input {
        width: 100%;
    }
}

/* --- TABLET (768px - 1023px) --- */
@media (min-width: 768px) and (max-width: 1023px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.open {
        display: block;
    }

    .main-content {
        margin-left: 0;
    }

    .hamburger {
        display: block;
    }

    .bottom-nav {
        display: none;
    }

    .page-content {
        padding: 24px;
    }

    .grid-3, .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* --- DESKTOP (1024px+) --- */
@media (min-width: 1024px) {
    .sidebar {
        transform: translateX(0);
    }

    .hamburger {
        display: none;
    }

    .bottom-nav {
        display: none;
    }
}

/* ===== UTILITIES ===== */
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mt-8 { margin-top: 32px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.hidden { display: none; }
