/* ============================================
   Lado Stats PWA - estilos base (steelblue, sin gradientes)
   ============================================ */

:root {
    --primary: #4682B4;
    --primary-hover: #3A6F9C;
    --primary-dark: #2E5980;
    --primary-pale: #E8F1F8;
    --primary-tint: #D4E4F0;

    --bg: #F5F7FA;
    --bg-secondary: #FFFFFF;
    --card-bg: #FFFFFF;
    --overlay: rgba(15, 23, 42, 0.55);

    --fg: #0F172A;
    --fg-secondary: #475569;
    --fg-muted: #94A3B8;
    --fg-on-primary: #FFFFFF;

    --border: #E2E8F0;
    --border-strong: #CBD5E1;
    --divider: #EEF2F6;

    --success: #16A34A;
    --success-pale: #DCFCE7;
    --warning: #D97706;
    --warning-pale: #FEF3C7;
    --danger: #DC2626;
    --danger-pale: #FEE2E2;
    --info: #4682B4;
    --info-pale: #E8F1F8;

    --shadow-xs: 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-md: 0 4px 6px rgba(15, 23, 42, .05), 0 2px 4px rgba(15, 23, 42, .04);
    --shadow-lg: 0 10px 20px rgba(15, 23, 42, .08);
    --shadow-focus: 0 0 0 3px rgba(70, 130, 180, .25);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-pill: 999px;

    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 20px;
    --sp-6: 24px;
    --sp-8: 32px;
}

[data-theme="dark"] {
    --primary: #5B96C8;
    --primary-hover: #6FA6D4;
    --primary-dark: #4682B4;
    --primary-pale: #1C2A38;
    --primary-tint: #243A4D;
    --bg: #0B1220;
    --bg-secondary: #111A2C;
    --card-bg: #162236;
    --overlay: rgba(0, 0, 0, .7);
    --fg: #F1F5F9;
    --fg-secondary: #CBD5E1;
    --fg-muted: #64748B;
    --border: #243044;
    --border-strong: #334155;
    --divider: #1C2638;
    --success: #22C55E;
    --success-pale: #0E2A1C;
    --warning: #F59E0B;
    --warning-pale: #2A1E0A;
    --danger: #EF4444;
    --danger-pale: #2A1212;
    --info: #5B96C8;
    --info-pale: #1C2A38;
    --shadow-xs: 0 1px 2px rgba(0,0,0,.4);
    --shadow-sm: 0 1px 3px rgba(0,0,0,.5);
    --shadow-md: 0 4px 8px rgba(0,0,0,.5);
    --shadow-lg: 0 12px 24px rgba(0,0,0,.6);
    --shadow-focus: 0 0 0 3px rgba(91,150,200,.4);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    font-variant-numeric: tabular-nums;
    overscroll-behavior-y: contain;
}

button {
    font-family: inherit;
    cursor: pointer;
}

a {
    color: var(--primary);
    text-decoration: none;
}

/* ===== LOGIN ===== */
.login-screen {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-4);
    background: var(--bg);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--sp-8);
    animation: fadeInUp 400ms cubic-bezier(0.16, 1, 0.3, 1);
}

.login-brand {
    text-align: center;
    margin-bottom: var(--sp-6);
}

.login-logo {
    width: 80px;
    height: 80px;
    object-fit: contain;
    margin-bottom: var(--sp-3);
}

.login-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--fg);
    margin: 0 0 var(--sp-1);
    letter-spacing: -0.02em;
}

.login-subtitle {
    color: var(--fg-muted);
    font-size: 0.875rem;
    margin: 0;
}

.login-error {
    background: var(--danger-pale);
    color: var(--danger);
    padding: var(--sp-3);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    margin-bottom: var(--sp-4);
    border: 1px solid var(--danger);
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
}

.field {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}

.field-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--fg-secondary);
}

.field-input {
    padding: 12px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--fg);
    font-size: 1rem;
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

.field-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--shadow-focus);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    border: 1px solid transparent;
    transition: background 150ms ease, transform 150ms ease;
    font-size: 1rem;
}

.btn-primary {
    background: var(--primary);
    color: var(--fg-on-primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-block {
    width: 100%;
}

.btn-link {
    background: transparent;
    border: none;
    color: var(--primary);
    font-weight: 500;
    text-decoration: underline;
    font-size: 0.8125rem;
}

.login-hint {
    text-align: center;
    color: var(--fg-muted);
    font-size: 0.75rem;
    margin: var(--sp-2) 0 0;
}

/* ===== APP HEADER ===== */
.app-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding-top: env(safe-area-inset-top, 0);
}

.app-header-inner {
    height: 56px;
    padding: 0 var(--sp-4);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
}

.brand {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}

.brand-logo {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.brand-name {
    font-weight: 700;
    color: var(--fg);
    font-size: 1rem;
    letter-spacing: -0.01em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid transparent;
    color: var(--fg-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 150ms ease, color 150ms ease;
}

.icon-btn:hover {
    background: var(--primary-pale);
    color: var(--primary);
}

.header-user {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}

.header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
}

.header-avatar--initial {
    background: var(--primary);
    color: var(--fg-on-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.header-logout-form {
    display: inline-block;
    margin: 0;
}

/* ===== PERIOD TABS ===== */
.period-tabs {
    display: flex;
    overflow-x: auto;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-4);
    border-top: 1px solid var(--divider);
    scrollbar-width: none;
    scroll-snap-type: x mandatory;
}

.period-tabs::-webkit-scrollbar {
    display: none;
}

.period-tab {
    padding: 8px 16px;
    background: var(--bg);
    color: var(--fg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-weight: 500;
    font-size: 0.875rem;
    white-space: nowrap;
    scroll-snap-align: start;
    transition: background 150ms ease, color 150ms ease;
}

.period-tab.is-active {
    background: var(--primary);
    color: var(--fg-on-primary);
    border-color: var(--primary);
}

/* ===== LAYOUT ===== */
.app-main {
    padding: var(--sp-4);
    padding-bottom: calc(var(--sp-8) + env(safe-area-inset-bottom, 0));
    max-width: 1280px;
    margin: 0 auto;
}

.section {
    margin-bottom: var(--sp-6);
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--sp-3);
}

.section-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--fg-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 0;
}

.section-sub {
    font-size: 0.75rem;
    color: var(--fg-muted);
}

/* ===== STAT CARDS ===== */
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--sp-4);
    box-shadow: var(--shadow-xs);
    transition: transform 180ms ease, box-shadow 180ms ease;
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    margin-bottom: var(--sp-3);
}

.stat-card:active {
    transform: scale(0.99);
}

.stat-card--live {
    border-left: 3px solid var(--primary);
    position: relative;
}

.stat-card-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
}

.stat-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--fg-muted);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--fg);
    letter-spacing: -0.015em;
    line-height: 1.1;
}

.t-display {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.delta-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: 600;
    width: fit-content;
}

.delta-badge--up {
    background: var(--success-pale);
    color: var(--success);
}

.delta-badge--down {
    background: var(--danger-pale);
    color: var(--danger);
}

.delta-badge--neutral {
    background: var(--bg);
    color: var(--fg-muted);
}

/* ===== METRIC GRID ===== */
.metric-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--sp-3);
}

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

@media (min-width: 768px) {
    .metric-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    .metric-grid--mini {
        grid-template-columns: repeat(4, 1fr);
    }
    .stat-value {
        font-size: 2.25rem;
    }
}

@media (min-width: 1024px) {
    .metric-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: var(--sp-4);
    }
}

.metric-grid .stat-card {
    margin-bottom: 0;
}

/* ===== LIVE DOT + SPARKLINE ===== */
.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 0 rgba(22, 163, 74, .55);
    animation: pulseDot 1.6s infinite;
    flex-shrink: 0;
}

@keyframes pulseDot {
    0% { box-shadow: 0 0 0 0 rgba(22, 163, 74, .55); }
    70% { box-shadow: 0 0 0 10px rgba(22, 163, 74, 0); }
    100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}

.spark-line {
    width: 120px;
    height: 40px;
    flex-shrink: 0;
}

.spark-line path {
    fill: none;
    stroke: var(--primary);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.spark-line .spark-area {
    fill: var(--primary);
    opacity: 0.1;
    stroke: none;
}

/* ===== SUB TABS ===== */
.sub-tabs {
    display: flex;
    gap: var(--sp-1);
    margin-bottom: var(--sp-3);
    border-bottom: 1px solid var(--border);
}

.sub-tab {
    padding: 8px 14px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--fg-secondary);
    font-weight: 500;
    font-size: 0.875rem;
    transition: color 150ms ease, border-color 150ms ease;
    margin-bottom: -1px;
}

.sub-tab.is-active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* ===== TOP LIST ===== */
.top-list {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}

.top-row {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--sp-3);
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    box-shadow: var(--shadow-xs);
}

.top-row-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--primary-pale);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-weight: 600;
    font-size: 0.875rem;
}

.top-row-main {
    flex: 1;
    min-width: 0;
}

.top-row-name {
    font-weight: 600;
    color: var(--fg);
    font-size: 0.9375rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-row-sub {
    color: var(--fg-muted);
    font-size: 0.8125rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-row-value {
    font-weight: 700;
    color: var(--fg);
    font-size: 0.9375rem;
    white-space: nowrap;
}

.top-row-bar {
    width: 60px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    overflow: hidden;
    margin-top: var(--sp-1);
}

.top-row-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
}

/* ===== HEALTH ===== */
.bar {
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: var(--primary);
    transition: width 400ms ease;
}

.health-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--sp-2);
    font-size: 0.875rem;
}

.health-label {
    color: var(--fg-secondary);
    font-weight: 500;
}

.health-value {
    color: var(--fg);
    font-weight: 600;
}

.health-storage-pill {
    background: var(--primary-pale);
    color: var(--primary);
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: 500;
}

/* ===== SKELETON ===== */
.skeleton {
    background: var(--border);
    border-radius: var(--radius-md);
    min-height: 80px;
    animation: skelPulse 1.4s ease-in-out infinite;
}

.skeleton.top-row {
    height: 64px;
    margin-bottom: var(--sp-2);
}

@keyframes skelPulse {
    0%, 100% { opacity: 0.65; }
    50% { opacity: 1; }
}

/* ===== FOOTER ===== */
.app-footer {
    padding: var(--sp-4);
    text-align: center;
    color: var(--fg-muted);
    font-size: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    align-items: center;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== CLICKABLE CARD ===== */
.stat-card--clickable {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.stat-card--clickable:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.stat-card--clickable:active {
    transform: scale(0.99);
}

.stat-hint {
    font-size: 0.75rem;
    color: var(--fg-muted);
    margin-top: 4px;
}

/* ===== BOTTOM SHEET ===== */
.sheet {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.sheet[hidden] {
    display: none;
}

.sheet-backdrop {
    position: absolute;
    inset: 0;
    background: var(--overlay);
    animation: fadeIn 200ms ease-out;
}

.sheet-panel {
    position: relative;
    background: var(--card-bg);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 720px;
    max-height: 85vh;
    max-height: 85dvh;
    display: flex;
    flex-direction: column;
    animation: sheetUp 320ms cubic-bezier(0.32, 0.72, 0, 1);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--border-strong);
    border-radius: 2px;
    margin: 8px auto 0;
    flex-shrink: 0;
}

.sheet-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--divider);
    flex-shrink: 0;
}

.sheet-title {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--fg);
}

.sheet-sub {
    margin: 2px 0 0;
    font-size: 0.8125rem;
    color: var(--fg-muted);
}

.sheet-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: var(--sp-3) var(--sp-4) var(--sp-4);
    flex: 1;
}

@media (min-width: 768px) {
    .sheet {
        align-items: center;
        padding: var(--sp-4);
    }
    .sheet-panel {
        border-radius: var(--radius-lg);
        max-height: 80vh;
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes sheetUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* ===== ONLINE LIST ===== */
.online-row {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3) 0;
    border-bottom: 1px solid var(--divider);
}

.skeleton.online-row {
    height: 56px;
    margin-bottom: var(--sp-2);
    border-bottom: none;
}

.online-row:last-child {
    border-bottom: none;
}

.online-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--primary-pale);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    position: relative;
}

.online-avatar-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--success);
    border: 2px solid var(--card-bg);
}

.online-row-main {
    flex: 1;
    min-width: 0;
}

.online-row-name {
    font-weight: 600;
    color: var(--fg);
    font-size: 0.9375rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 4px;
}

.online-row-tag {
    background: var(--primary-pale);
    color: var(--primary);
    padding: 1px 6px;
    border-radius: var(--radius-pill);
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.online-row-tag--verified {
    background: var(--success-pale);
    color: var(--success);
}

.online-row-sub {
    color: var(--fg-muted);
    font-size: 0.8125rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.online-row-time {
    font-size: 0.75rem;
    color: var(--fg-muted);
    white-space: nowrap;
}

.online-empty {
    text-align: center;
    color: var(--fg-muted);
    padding: var(--sp-8) var(--sp-4);
    font-size: 0.875rem;
}
