/* ============================================================
   API Status Dashboard — Styles
   Dark mode, status-board aesthetic
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --up: #10B981;
    --up-bg: rgba(16, 185, 129, .08);
    --down: #EF4444;
    --down-bg: rgba(239, 68, 68, .08);
    --slow: #EAB308;
    --slow-bg: rgba(234, 179, 8, .08);
    --unknown: #6B7280;
    --bg: #0F172A;
    --bg-elevated: #1E293B;
    --bg-card: #1E293B;
    --bg-surface: #334155;
    --bg-hover: #3B4B66;
    --text-primary: #F1F5F9;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;
    --border: #334155;
    --primary: #3B82F6;
    --primary-light: #60A5FA;
    --accent: #8B5CF6;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-pill: 50px;
    --shadow: 0 4px 16px rgba(0, 0, 0, .3);
    --transition: 200ms ease;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

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

/* --- Header --- */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

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

.logo {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--up), var(--primary));
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.header h1 {
    font-size: 1.2rem;
    font-weight: 700;
}

.header h1 span {
    color: var(--text-muted);
    font-weight: 400;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: .85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

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

.btn:active {
    transform: scale(.97);
}

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

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

.btn-sm {
    padding: 6px 12px;
    font-size: .8rem;
}

.btn-icon {
    padding: 8px;
    min-width: 36px;
    justify-content: center;
}

.btn-danger {
    color: var(--down);
    border-color: rgba(239, 68, 68, .3);
}

.btn-danger:hover {
    background: var(--down-bg);
}

/* --- Summary Bar --- */
.summary-bar {
    display: flex;
    gap: 16px;
    padding: 16px 24px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.summary-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    flex: 1;
    min-width: 160px;
}

.summary-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}

.summary-icon.up {
    background: var(--up-bg);
}

.summary-icon.down {
    background: var(--down-bg);
}

.summary-icon.slow {
    background: var(--slow-bg);
}

.summary-icon.total {
    background: rgba(59, 130, 246, .1);
}

.summary-value {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1;
}

.summary-label {
    font-size: .8rem;
    color: var(--text-muted);
}

/* --- Toolbar --- */
.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    flex-wrap: wrap;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    flex: 1;
    max-width: 300px;
}

.search-box input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: .85rem;
    outline: none;
    width: 100%;
}

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

.group-select,
.interval-select {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: .85rem;
    padding: 6px 12px;
    outline: none;
    cursor: pointer;
}

/* --- Endpoint Grid --- */
.endpoints-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
    padding: 16px 24px;
}

.endpoint-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: all var(--transition);
}

.endpoint-card:hover {
    border-color: var(--primary);
}

.endpoint-card.compact {
    border-radius: var(--radius-sm);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    cursor: pointer;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    position: relative;
}

.status-dot.up {
    background: var(--up);
    box-shadow: 0 0 8px rgba(16, 185, 129, .5);
}

.status-dot.down {
    background: var(--down);
    box-shadow: 0 0 8px rgba(239, 68, 68, .5);
    animation: pulse 2s infinite;
}

.status-dot.slow {
    background: var(--slow);
    box-shadow: 0 0 8px rgba(234, 179, 8, .5);
}

.status-dot.unknown {
    background: var(--unknown);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: .5;
    }
}

.card-info {
    flex: 1;
    min-width: 0;
}

.endpoint-name {
    font-weight: 600;
    font-size: .95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.endpoint-url {
    font-family: var(--font-mono);
    font-size: .75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-meta {
    display: flex;
    align-items: center;
    gap: 8px;
}

.response-time {
    font-family: var(--font-mono);
    font-size: .8rem;
    font-weight: 600;
}

.response-time.fast {
    color: var(--up);
}

.response-time.medium {
    color: var(--slow);
}

.response-time.slow {
    color: var(--down);
}

.uptime-badge {
    font-size: .75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    background: var(--up-bg);
    color: var(--up);
}

.uptime-badge.warning {
    background: var(--slow-bg);
    color: var(--slow);
}

.uptime-badge.danger {
    background: var(--down-bg);
    color: var(--down);
}

/* --- Card Details (expandable) --- */
.card-details {
    max-height: 0;
    overflow: hidden;
    transition: max-height .3s ease;
    border-top: 1px solid transparent;
}

.card-details.open {
    max-height: 500px;
    border-top-color: var(--border);
}

.card-details-inner {
    padding: 16px;
}

.chart-container {
    height: 80px;
    margin-bottom: 12px;
    position: relative;
}

.chart-canvas {
    width: 100%;
    height: 100%;
}

.detail-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.stat-item {
    text-align: center;
    padding: 8px;
    background: var(--bg);
    border-radius: var(--radius-sm);
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 700;
    font-family: var(--font-mono);
}

.stat-label {
    font-size: .7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
}

.card-actions {
    display: flex;
    gap: 6px;
    margin-top: 12px;
}

/* --- Group Label --- */
.group-label {
    grid-column: 1 / -1;
    padding: 8px 0 4px;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border);
    margin-top: 8px;
}

/* --- Add Endpoint Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 90%;
    max-width: 480px;
    box-shadow: var(--shadow);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.1rem;
}

.modal-body {
    padding: 24px;
}

.form-group {
    margin-bottom: 16px;
}

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

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

.form-input:focus {
    border-color: var(--primary);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

/* --- Incident Log --- */
.incident-log {
    margin: 0 24px 24px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.incident-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.incident-header h3 {
    font-size: .9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.incident-count {
    background: var(--down-bg);
    color: var(--down);
    font-size: .7rem;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
}

.incident-list {
    max-height: 0;
    overflow: hidden;
    transition: max-height .3s ease;
}

.incident-list.open {
    max-height: 400px;
    overflow-y: auto;
}

.incident-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    font-size: .85rem;
}

.incident-item:last-child {
    border-bottom: none;
}

.incident-time {
    font-family: var(--font-mono);
    font-size: .75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.incident-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.incident-status.down {
    background: var(--down);
}

.incident-status.slow {
    background: var(--slow);
}

.incident-status.up {
    background: var(--up);
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.empty-state h3 {
    color: var(--text-secondary);
    margin-bottom: 8px;
}

/* --- Toast --- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 20px;
    font-size: .85rem;
    color: var(--text-primary);
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transition: all var(--transition);
    z-index: 200;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .summary-bar {
        gap: 8px;
    }

    .summary-card {
        min-width: 120px;
        padding: 10px 12px;
    }

    .endpoints-grid {
        grid-template-columns: 1fr;
        padding: 12px;
    }

    .header {
        flex-wrap: wrap;
        gap: 8px;
    }

    .toolbar {
        padding: 8px 12px;
    }
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}