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

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #16161f;
    --bg-card-hover: #1c1c28;
    --border: #1e1e2e;
    --border-glow: rgba(139, 92, 246, 0.15);

    --text-primary: #f0f0f5;
    --text-secondary: #8888a0;
    --text-muted: #55556a;

    --purple-primary: #8b5cf6;
    --purple-light: #a78bfa;
    --purple-dark: #6d28d9;
    --purple-glow: rgba(139, 92, 246, 0.25);
    --purple-glow-strong: rgba(139, 92, 246, 0.5);

    --red: #ef4444;
    --red-glow: rgba(239, 68, 68, 0.2);
    --green: #22c55e;
    --green-glow: rgba(34, 197, 94, 0.2);
    --yellow: #eab308;
    --yellow-glow: rgba(234, 179, 8, 0.2);

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

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html,
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
}

#app {
    max-width: 500px;
    margin: 0 auto;
    padding: 0 16px 32px;
}

/* ==================== STATUS BAR ==================== */
.status-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 0 4px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 0.4s ease;
}

.status-dot.connected {
    background: var(--green);
    box-shadow: 0 0 8px var(--green-glow);
    animation: pulse-dot 2s ease-in-out infinite;
}

.status-dot.error {
    background: var(--red);
    box-shadow: 0 0 8px var(--red-glow);
}

@keyframes pulse-dot {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* ==================== HEADER ==================== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0 24px;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    box-shadow: 0 4px 20px var(--purple-glow);
}

.header h1 {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--purple-light), var(--purple-primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.3px;
    margin-top: 1px;
}

.notifications-btn {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    padding: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.notifications-btn:hover,
.notifications-btn:active {
    background: var(--bg-card-hover);
    color: var(--purple-light);
    border-color: var(--border-glow);
}

.notifications-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--red);
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    box-shadow: 0 2px 8px var(--red-glow);
    animation: badge-bounce 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes badge-bounce {
    0% {
        transform: scale(0);
    }

    100% {
        transform: scale(1);
    }
}

/* ==================== COUNTER SECTION ==================== */
.counter-section {
    margin-bottom: 20px;
}

.counter-card {
    position: relative;
    background: linear-gradient(135deg, #1a1028 0%, #12121a 50%, #0f1628 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px 24px;
    overflow: hidden;
    transition: border-color 0.4s ease;
}

.counter-card:hover {
    border-color: rgba(139, 92, 246, 0.3);
}

.counter-glow {
    position: absolute;
    top: -60%;
    left: 50%;
    transform: translateX(-50%);
    width: 200%;
    height: 200%;
    background: radial-gradient(ellipse at center, var(--purple-glow) 0%, transparent 60%);
    pointer-events: none;
    opacity: 0.6;
}

.counter-content {
    position: relative;
    z-index: 1;
    text-align: center;
}

.counter-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--purple-light);
    margin-bottom: 12px;
}

.counter-value {
    font-size: 48px;
    font-weight: 900;
    letter-spacing: -2px;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    line-height: 1;
    margin-bottom: 8px;
    transition: color 0.3s ease;
}

.counter-loading {
    opacity: 0.3;
    animation: loading-pulse 1.5s ease-in-out infinite;
}

@keyframes loading-pulse {

    0%,
    100% {
        opacity: 0.15;
    }

    50% {
        opacity: 0.4;
    }
}

.counter-diff {
    font-size: 13px;
    font-weight: 600;
    min-height: 20px;
    transition: all 0.3s ease;
}

.counter-diff.positive {
    color: var(--green);
}

.counter-diff.negative {
    color: var(--red);
}

.counter-pulse {
    position: absolute;
    inset: 0;
    border-radius: var(--radius);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.counter-pulse.active {
    animation: counter-ring 0.8s ease-out;
}

@keyframes counter-ring {
    0% {
        box-shadow: inset 0 0 0 2px var(--purple-primary);
        opacity: 1;
    }

    100% {
        box-shadow: inset 0 0 0 0px var(--purple-primary);
        opacity: 0;
    }
}

/* ==================== STATS GRID ==================== */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.3s ease;
}

.stat-card:hover {
    border-color: var(--border-glow);
    transform: translateY(-1px);
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon.purple {
    background: rgba(139, 92, 246, 0.12);
    color: var(--purple-light);
}

.stat-icon.red {
    background: rgba(239, 68, 68, 0.12);
    color: var(--red);
}

.stat-value {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.5px;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    margin-top: 2px;
}

/* ==================== PUSH SECTION ==================== */
.push-section {
    margin-bottom: 20px;
}

.push-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.push-info {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary);
}

.push-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.push-desc {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Toggle Switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
    flex-shrink: 0;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 14px;
    transition: all 0.3s ease;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 22px;
    width: 22px;
    left: 2px;
    bottom: 2px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.toggle input:checked+.toggle-slider {
    background: var(--purple-primary);
    border-color: var(--purple-primary);
    box-shadow: 0 0 16px var(--purple-glow);
}

.toggle input:checked+.toggle-slider::before {
    transform: translateX(22px);
    background: white;
}

/* ==================== ALERTS SECTION ==================== */
.alerts-section {
    margin-bottom: 20px;
}

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

.alerts-header h2 {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.mark-read-btn {
    background: none;
    border: none;
    color: var(--purple-light);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-xs);
    transition: all 0.2s ease;
}

.mark-read-btn:hover {
    background: var(--purple-glow);
}

.alerts-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.alerts-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 13px;
}

.alerts-empty p {
    margin-top: 12px;
}

/* Alert Item — Swipe to delete */
.alert-wrapper {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius);
    transition: max-height 0.35s ease, opacity 0.35s ease, margin-bottom 0.35s ease;
    max-height: 200px;
}

.alert-wrapper.removing {
    max-height: 0;
    opacity: 0;
    margin-bottom: -8px;
}

.alert-delete-bg {
    position: absolute;
    inset: 0;
    background: var(--red);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 20px;
    color: white;
    font-size: 13px;
    font-weight: 700;
    gap: 6px;
    border-radius: var(--radius);
    pointer-events: none;
    user-select: none;
}

.alert-delete-bg svg {
    flex-shrink: 0;
}

.alert-item {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    cursor: pointer;
    transition: transform 0.05s linear;
    animation: alert-slide-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    touch-action: pan-y;
    will-change: transform;
}

.alert-item.swiping {
    transition: none !important;
}

.alert-item.snapping {
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
}

.alert-item:hover {
    border-color: var(--border-glow);
}

.alert-item.unread {
    border-left: 3px solid var(--red);
    background: #191420;
}

.alert-item.unread.warning {
    border-left-color: var(--yellow);
    background: #1a1810;
}

.alert-item.unread.info {
    border-left-color: var(--purple-primary);
    background: #171428;
}

@keyframes alert-slide-in {
    0% {
        opacity: 0;
        transform: translateY(-10px) scale(0.97);
    }

    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.alert-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.alert-title {
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
}

.alert-level-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.alert-level-dot.error {
    background: var(--red);
    box-shadow: 0 0 6px var(--red-glow);
}

.alert-level-dot.warning {
    background: var(--yellow);
    box-shadow: 0 0 6px var(--yellow-glow);
}

.alert-level-dot.info {
    background: var(--purple-primary);
    box-shadow: 0 0 6px var(--purple-glow);
}

.alert-time {
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 500;
    flex-shrink: 0;
}

.alert-message {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
    word-break: break-word;
    max-height: 60px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
}

.alert-context {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 6px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    letter-spacing: 0.2px;
}

/* ==================== FOOTER ==================== */
.footer {
    text-align: center;
    padding: 16px 0;
    color: var(--text-muted);
    font-size: 11px;
}

.footer-version {
    margin-top: 4px;
    font-size: 10px;
    opacity: 0.5;
}

/* ==================== ALERT DETAIL MODAL ==================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-sheet {
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    background: var(--bg-secondary);
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;
    padding: 12px 20px 32px;
    padding-bottom: calc(32px + var(--safe-bottom));
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

.modal-overlay.open .modal-sheet {
    transform: translateY(0);
}

.modal-handle {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 16px;
}

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

.modal-level {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 12px 5px 8px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal-level.error {
    background: rgba(239, 68, 68, 0.15);
    color: var(--red);
}

.modal-level.warning {
    background: rgba(234, 179, 8, 0.15);
    color: var(--yellow);
}

.modal-level.info {
    background: rgba(139, 92, 246, 0.15);
    color: var(--purple-light);
}

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

.modal-close {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-close:active {
    background: var(--bg-card-hover);
    transform: scale(0.92);
}

.modal-title {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -0.3px;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.modal-time {
    font-size: 12px;
    color: var(--text-muted);
    display: block;
    margin-bottom: 20px;
}

.modal-section {
    margin-bottom: 16px;
}

.modal-section-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.modal-code {
    background: #0d0d14;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 12px;
    line-height: 1.7;
    color: #f87171;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-height: 300px;
    overflow-y: auto;
}

.modal-code .code-keyword {
    color: #c084fc;
}

.modal-code .code-string {
    color: #a5f3fc;
}

.modal-code .code-function {
    color: #fbbf24;
}

.modal-code .code-line-num {
    color: #444;
    user-select: none;
    margin-right: 12px;
}

.modal-code .code-path {
    color: #94a3b8;
}

.modal-context {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
    color: var(--purple-light);
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-context::before {
    content: '📍';
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.modal-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 13px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 700;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-btn:active {
    transform: scale(0.96);
}

.modal-btn-read {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.modal-btn-read:active {
    background: var(--bg-card-hover);
}

.modal-btn-delete {
    background: rgba(239, 68, 68, 0.12);
    color: var(--red);
}

.modal-btn-delete:active {
    background: rgba(239, 68, 68, 0.25);
}

/* ==================== ANIMATIONS ==================== */
@keyframes count-up {
    0% {
        opacity: 0.5;
        transform: translateY(4px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.count-updated {
    animation: count-up 0.4s ease-out;
}

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

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

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

/* ==================== RESPONSIVE ==================== */
@media (max-width: 380px) {
    .counter-value {
        font-size: 40px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* Landscape phone */
@media (max-height: 500px) {
    .counter-card {
        padding: 20px;
    }

    .counter-value {
        font-size: 36px;
    }
}