/* ============================
   DB Monitor — Premium Dark Theme
   ============================ */

:root {
    /* Colors */
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.7);
    --bg-card-hover: rgba(31, 41, 55, 0.8);
    --border: rgba(99, 102, 241, 0.15);
    --border-hover: rgba(99, 102, 241, 0.3);

    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;

    --accent: #6366f1;
    --accent-light: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.25);

    --green: #10b981;
    --green-glow: rgba(16, 185, 129, 0.2);
    --red: #ef4444;
    --red-glow: rgba(239, 68, 68, 0.2);
    --yellow: #f59e0b;
    --yellow-glow: rgba(245, 158, 11, 0.2);
    --blue: #3b82f6;
    --cyan: #06b6d4;
    --purple: #8b5cf6;
    --teal: #14b8a6;

    /* Spacing */
    --radius: 16px;
    --radius-sm: 10px;
    --gap: 20px;

    /* Fonts */
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Background gradient effect */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 600px;
    background: radial-gradient(ellipse at 50% -20%, rgba(99, 102, 241, 0.12) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

/* ============================
   Header
   ============================ */

#app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    background: rgba(10, 14, 26, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

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

.logo {
    display: flex;
    filter: drop-shadow(0 0 12px var(--accent-glow));
}

.header-title h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
    letter-spacing: 0.02em;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 24px;
}

.db-selector-wrap select {
    appearance: none;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 36px 8px 14px;
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

.db-selector-wrap select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.settings-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.2s;
    flex-shrink: 0;
}

.settings-btn:hover {
    color: var(--accent-light);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.refresh-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 8px var(--green-glow);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.85); }
}

/* ============================
   Main Layout
   ============================ */

#dashboard {
    position: relative;
    z-index: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: 28px 32px;
}

/* ============================
   Section Titles
   ============================ */

.section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.section-title svg {
    color: var(--accent-light);
}

/* ============================
   All Databases Overview
   ============================ */

#db-overview {
    margin-bottom: var(--gap);
}

#db-overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
}

.db-overview-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    transition: all 0.25s ease;
    backdrop-filter: blur(12px);
}

.db-overview-card:hover {
    border-color: var(--border-hover);
    background: var(--bg-card-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.db-overview-card.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent), 0 4px 20px var(--accent-glow);
}

.db-overview-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.db-overview-dot.up {
    background: var(--green);
    box-shadow: 0 0 10px var(--green-glow);
}

.db-overview-dot.down {
    background: var(--red);
    box-shadow: 0 0 10px var(--red-glow);
    animation: pulse 1.5s ease-in-out infinite;
}

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

.db-overview-name {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.db-overview-meta {
    display: flex;
    gap: 16px;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.db-overview-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ============================
   Status Banner
   ============================ */

#status-banner {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 22px 28px;
    border-radius: var(--radius);
    margin-bottom: var(--gap);
    border: 1px solid;
    transition: all 0.4s ease;
}

#status-banner.status-up {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.08), rgba(16, 185, 129, 0.02));
    border-color: rgba(16, 185, 129, 0.2);
}

#status-banner.status-down {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(239, 68, 68, 0.03));
    border-color: rgba(239, 68, 68, 0.3);
}

.status-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.3s;
}

.status-up .status-icon {
    background: rgba(16, 185, 129, 0.15);
    color: var(--green);
    box-shadow: 0 0 20px var(--green-glow);
}

.status-down .status-icon {
    background: rgba(239, 68, 68, 0.15);
    color: var(--red);
    box-shadow: 0 0 20px var(--red-glow);
    animation: statusPulse 1.5s ease-in-out infinite;
}

@keyframes statusPulse {
    0%, 100% { box-shadow: 0 0 20px var(--red-glow); }
    50% { box-shadow: 0 0 35px rgba(239, 68, 68, 0.4); }
}

.status-text h2 {
    font-size: 1.15rem;
    font-weight: 600;
}

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

.status-meta {
    display: flex;
    gap: 32px;
    margin-left: auto;
}

.meta-item {
    text-align: right;
}

.meta-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
}

.meta-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ============================
   Metrics Grid
   ============================ */

#metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--gap);
    margin-bottom: var(--gap);
}

.metric-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.metric-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-glow), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.metric-card:hover {
    border-color: var(--border-hover);
    background: var(--bg-card-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.metric-card:hover::before {
    opacity: 1;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.connections-icon { background: rgba(99, 102, 241, 0.15); color: var(--accent); }
.queries-icon { background: rgba(6, 182, 212, 0.15); color: var(--cyan); }
.size-icon { background: rgba(139, 92, 246, 0.15); color: var(--purple); }
.cache-icon { background: rgba(245, 158, 11, 0.15); color: var(--yellow); }
.locks-icon { background: rgba(239, 68, 68, 0.15); color: var(--red); }
.replication-icon { background: rgba(59, 130, 246, 0.15); color: var(--blue); }
.rows-icon { background: rgba(20, 184, 166, 0.15); color: var(--teal); }
.io-icon { background: rgba(139, 92, 246, 0.15); color: var(--purple); }

.card-header h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

.card-big-number {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.1;
    margin-bottom: 2px;
}

.card-big-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Progress bar */
.card-progress {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.progress-bar {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--accent), var(--accent-light));
    transition: width 0.6s ease, background 0.3s;
}

.progress-fill.warning {
    background: linear-gradient(90deg, var(--yellow), #fbbf24);
}

.progress-fill.danger {
    background: linear-gradient(90deg, var(--red), #f87171);
}

.progress-text {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 40px;
    text-align: right;
}

/* Card details */
.card-details {
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    padding-top: 12px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    font-size: 0.82rem;
}

.detail-row span:first-child {
    color: var(--text-muted);
}

.detail-value {
    font-weight: 600;
    color: var(--text-primary);
}

.warning-value {
    color: var(--yellow) !important;
}

.danger-value {
    color: var(--red) !important;
}

.insert-value {
    color: var(--green) !important;
}

.update-value {
    color: var(--blue) !important;
}

/* ============================
   Charts Section
   ============================ */

#charts-section {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--gap);
    margin-bottom: var(--gap);
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.chart-card.full-width {
    grid-column: 1 / -1;
}

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

.chart-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
}

.chart-controls {
    display: flex;
    gap: 4px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    padding: 3px;
}

.chart-range {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 5px 14px;
    border-radius: 6px;
    font-family: var(--font);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.chart-range:hover {
    color: var(--text-secondary);
}

.chart-range.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px var(--accent-glow);
}

.chart-container {
    position: relative;
    height: 220px;
}

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

/* ============================
   Data Panels (Tables & Queries)
   ============================ */

#table-stats-section,
#queries-section {
    margin-bottom: var(--gap);
}

.data-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    backdrop-filter: blur(12px);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.panel-header h3 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    font-weight: 600;
}

.panel-header h3 svg {
    color: var(--accent-light);
}

.badge {
    background: var(--accent);
    color: white;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    min-width: 24px;
    text-align: center;
}

.panel-body {
    padding: 0;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.data-table thead th {
    text-align: left;
    padding: 12px 20px;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    white-space: nowrap;
}

.data-table tbody td {
    padding: 12px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
    vertical-align: middle;
}

.data-table tbody tr:hover {
    background: rgba(99, 102, 241, 0.04);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 32px 20px !important;
    font-style: italic;
}

/* Table size bar */
.size-bar-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 120px;
}

.size-bar-outer {
    flex: 1;
    height: 8px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 4px;
    overflow: hidden;
}

.size-bar-fill {
    height: 100%;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--accent), var(--purple));
    transition: width 0.5s ease;
}

/* Query text styling */
.query-text {
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
    font-size: 0.72rem;
    color: var(--text-muted);
    max-width: 400px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.state-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.state-badge.active {
    background: rgba(16, 185, 129, 0.15);
    color: var(--green);
}

.state-badge.idle {
    background: rgba(107, 114, 128, 0.15);
    color: var(--text-muted);
}

.state-badge.waiting {
    background: rgba(245, 158, 11, 0.15);
    color: var(--yellow);
}

.duration-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.duration-value.slow {
    color: var(--yellow);
}

.duration-value.critical {
    color: var(--red);
}

/* ============================
   Footer
   ============================ */

#app-footer {
    text-align: center;
    padding: 24px 32px;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
    margin-top: 20px;
}

.footer-sep {
    margin: 0 8px;
    opacity: 0.4;
}

#app-footer a {
    color: var(--accent-light);
    text-decoration: none;
    transition: color 0.2s;
}

#app-footer a:hover {
    color: var(--accent);
}

/* ============================
   Responsive
   ============================ */

@media (max-width: 1200px) {
    #metrics-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 1100px) {
    #metrics-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    #app-header {
        flex-direction: column;
        gap: 12px;
        padding: 12px 16px;
    }

    #dashboard {
        padding: 16px;
    }

    #status-banner {
        flex-direction: column;
        text-align: center;
        gap: 12px;
    }

    .status-meta {
        margin-left: 0;
        justify-content: center;
    }

    #metrics-grid {
        grid-template-columns: 1fr;
    }

    #charts-section {
        grid-template-columns: 1fr;
    }

    .hide-mobile {
        display: none;
    }
}

/* ============================
   Animations
   ============================ */

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.metric-card {
    animation: fadeInUp 0.5s ease-out backwards;
}

.metric-card:nth-child(1) { animation-delay: 0.05s; }
.metric-card:nth-child(2) { animation-delay: 0.1s; }
.metric-card:nth-child(3) { animation-delay: 0.15s; }
.metric-card:nth-child(4) { animation-delay: 0.2s; }
.metric-card:nth-child(5) { animation-delay: 0.25s; }
.metric-card:nth-child(6) { animation-delay: 0.3s; }
.metric-card:nth-child(7) { animation-delay: 0.35s; }
.metric-card:nth-child(8) { animation-delay: 0.4s; }

.chart-card {
    animation: fadeInUp 0.5s ease-out 0.35s backwards;
}

.data-panel {
    animation: fadeInUp 0.5s ease-out 0.45s backwards;
}

.db-overview-card {
    animation: fadeInUp 0.4s ease-out backwards;
}

.db-overview-card:nth-child(1) { animation-delay: 0.02s; }
.db-overview-card:nth-child(2) { animation-delay: 0.06s; }
.db-overview-card:nth-child(3) { animation-delay: 0.1s; }

/* Number transition */
.updating {
    transition: color 0.3s;
    color: var(--accent-light) !important;
}

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

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

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}
