/* ============================================================================
   KioskMode Monitor - Dashboard CSS
   Dark theme, responsive, split-page layout
   ============================================================================ */

/* === CSS Variables === */
:root {
    --bg: #0f172a;
    --bg-alt: #0a0e17;
    --surface: #1e293b;
    --surface-hover: #1a2332;
    --surface-input: #1f2937;
    --border: #1e293b;
    --border-light: #374151;
    --text: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-purple: #a855f7;
    --accent-cyan: #06b6d4;
    --online: #22c55e;
    --offline: #ef4444;
    --warning: #f59e0b;
    --font-mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
}

/* === Reset === */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === Header === */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, var(--accent), var(--accent-purple));
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.header h1 {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.3px;
    white-space: nowrap;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-meta {
    color: var(--text-muted);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

/* === Live Dot === */
.live-dot {
    width: 8px;
    height: 8px;
    background: var(--offline);
    border-radius: 50%;
    flex-shrink: 0;
    transition: background 0.3s;
}

.live-dot.connected {
    background: var(--online);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

@keyframes flash {
    0% { background: var(--accent-cyan); }
    100% { background: var(--online); }
}

.live-dot.flash {
    animation: flash 0.3s ease-out forwards;
}

/* === Navigation === */
.nav-tabs {
    display: flex;
    gap: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
}

.nav-tab {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.nav-tab:hover {
    color: var(--text-secondary);
}

.nav-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.nav-badge {
    background: var(--offline);
    color: white;
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 8px;
    font-weight: 600;
    line-height: 1.4;
}

/* === Stats Bar === */
.stats-bar {
    display: flex;
    gap: 1px;
    background: var(--border);
    border-bottom: 1px solid var(--border);
}

.stat-item {
    flex: 1;
    background: var(--surface);
    padding: 14px 20px;
    text-align: center;
}

.stat-value {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -1px;
}

.stat-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

.stat-item.total .stat-value { color: var(--accent); }
.stat-item.online .stat-value { color: var(--online); }
.stat-item.offline .stat-value { color: var(--offline); }
.stat-item.errors .stat-value { color: var(--warning); }

/* === Main Content === */
.main {
    padding: 20px 24px;
    flex: 1;
}

/* === Host Grid === */
.hosts-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

/* === Host Card === */
.host-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.host-card:hover {
    border-color: var(--border-light);
    background: var(--surface-hover);
    transform: translateY(-1px);
}

.host-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
}

.host-card.online::before { background: var(--online); }
.host-card.offline::before { background: var(--offline); }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.hostname {
    font-size: 14px;
    font-weight: 600;
}

/* === Badges === */
.badge {
    font-size: 10px;
    padding: 2px 7px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    display: inline-block;
}

.badge.online { background: rgba(34, 197, 94, 0.15); color: var(--online); }
.badge.offline { background: rgba(239, 68, 68, 0.15); color: var(--offline); }

/* === Severity Badges === */
.sev-badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 600;
    display: inline-block;
}

.sev-badge.critical { background: rgba(239, 68, 68, 0.2); color: #ff6b6b; }
.sev-badge.error { background: rgba(239, 68, 68, 0.12); color: var(--offline); }
.sev-badge.warning { background: rgba(245, 158, 11, 0.12); color: var(--warning); }
.sev-badge.info { background: rgba(59, 130, 246, 0.12); color: var(--accent); }

/* === Metrics Row === */
.metrics-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-bottom: 10px;
}

.metric {
    background: var(--surface-input);
    border-radius: 6px;
    padding: 6px 8px;
    text-align: center;
}

.metric-value {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.metric-label {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.metric-value.cpu { color: var(--accent-cyan); }
.metric-value.ram { color: var(--accent-purple); }
.metric-value.disk { color: var(--warning); }

/* === Metric Bar (thin) === */
.metric-bar {
    height: 2px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 2px;
    margin-top: 3px;
    overflow: hidden;
}

.metric-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.5s ease;
}

.metric-bar-fill.cpu { background: var(--accent-cyan); }
.metric-bar-fill.ram { background: var(--accent-purple); }
.metric-bar-fill.disk { background: var(--warning); }

/* === Progress Bar (thick, for detail/monitoring) === */
.progress-bar {
    height: 8px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 4px;
    overflow: hidden;
    flex: 1;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.progress-bar-fill.green { background: var(--online); }
.progress-bar-fill.yellow { background: var(--warning); }
.progress-bar-fill.red { background: var(--offline); }

.progress-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.progress-label {
    font-size: 11px;
    color: var(--text-muted);
    width: 40px;
    flex-shrink: 0;
}

.progress-value {
    font-size: 11px;
    font-weight: 600;
    width: 40px;
    text-align: right;
    flex-shrink: 0;
}

/* === Info Rows === */
.info-rows {
    font-size: 11px;
    color: var(--text-secondary);
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.info-row:last-child { border-bottom: none; }
.info-label { color: var(--text-muted); }
.info-value { font-weight: 500; }

/* === App Tags === */
.apps-row {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.app-tag {
    font-size: 10px;
    padding: 2px 7px;
    border-radius: 4px;
    font-weight: 500;
    background: var(--surface-input);
    color: var(--text-secondary);
    border: 1px solid transparent;
}

.app-tag.healthy { color: var(--online); border-color: rgba(34, 197, 94, 0.2); }
.app-tag.unhealthy { color: var(--offline); border-color: rgba(239, 68, 68, 0.2); }
.app-tag.launching { color: var(--warning); border-color: rgba(245, 158, 11, 0.2); }

/* === Tables === */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.table-wrap.borderless {
    border: none;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    text-align: left;
    padding: 9px 12px;
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

thead th.sortable {
    cursor: pointer;
    user-select: none;
}

thead th.sortable:hover {
    color: var(--text-secondary);
}

thead th.sorted-asc::after { content: ' \u2191'; }
thead th.sorted-desc::after { content: ' \u2193'; }

tbody td {
    padding: 7px 12px;
    font-size: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
    color: var(--text-secondary);
}

tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.01);
}

tbody tr:nth-child(even):hover {
    background: rgba(255, 255, 255, 0.03);
}

td.ts-cell {
    font-family: var(--font-mono);
    font-size: 11px;
    white-space: nowrap;
}

td.msg-cell {
    max-width: 400px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* === Error Highlight === */
@keyframes errorHighlight {
    from { background: rgba(239, 68, 68, 0.1); }
    to { background: transparent; }
}

.error-new {
    animation: errorHighlight 3s ease-out;
}

/* === Filters === */
.filters {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-select,
.filter-input {
    background: var(--surface-input);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
}

.filter-select:focus,
.filter-input:focus {
    outline: none;
    border-color: var(--accent);
}

.filter-label {
    font-size: 11px;
    color: var(--text-muted);
}

/* === Detail Cards === */
.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.detail-title {
    font-size: 18px;
    font-weight: 600;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.detail-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
}

.detail-card-title {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 8px;
    font-weight: 600;
}

/* === Buttons === */
.btn {
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-back {
    background: var(--surface-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.btn-back:hover {
    background: var(--border);
    color: var(--text);
}

/* === Charts === */
.chart-container {
    position: relative;
    margin-top: 8px;
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 100px;
}

.chart-bar-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 1px;
}

.chart-bar {
    min-width: 2px;
    border-radius: 1px 1px 0 0;
    transition: height 0.3s;
}

.chart-bar.cpu { background: var(--accent-cyan); }
.chart-bar.ram { background: var(--accent-purple); }
.chart-bar.disk { background: var(--warning); }

.chart-legend {
    display: flex;
    gap: 14px;
    margin-top: 6px;
    font-size: 10px;
    color: var(--text-muted);
}

.chart-legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 4px;
    vertical-align: middle;
}

/* === Color-coded cells for monitoring === */
.cell-green { color: var(--online); }
.cell-yellow { color: var(--warning); }
.cell-red { color: var(--offline); font-weight: 600; }

.cell-bg-green { background: rgba(34, 197, 94, 0.08); }
.cell-bg-yellow { background: rgba(245, 158, 11, 0.08); }
.cell-bg-red { background: rgba(239, 68, 68, 0.08); }

/* === Summary Cards === */
.summary-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.summary-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 20px;
    flex: 1;
    text-align: center;
}

.summary-card .summary-value {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.summary-card .summary-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-top: 2px;
}

/* === Empty State === */
.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
    font-size: 13px;
}

/* === Footer === */
.footer {
    text-align: center;
    padding: 16px;
    color: var(--text-muted);
    font-size: 11px;
    border-top: 1px solid var(--border);
    margin-top: auto;
}

/* === Responsive === */
@media (max-width: 1200px) {
    .hosts-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .header {
        padding: 10px 16px;
    }

    .header h1 {
        font-size: 14px;
    }

    .nav-tabs {
        padding: 0 16px;
        overflow-x: auto;
    }

    .nav-tab {
        padding: 8px 12px;
        font-size: 12px;
    }

    .stats-bar {
        flex-wrap: wrap;
    }

    .stat-item {
        min-width: 50%;
        padding: 10px 14px;
    }

    .stat-value {
        font-size: 20px;
    }

    .main {
        padding: 14px 16px;
    }

    .hosts-grid {
        grid-template-columns: 1fr;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .summary-bar {
        flex-wrap: wrap;
    }

    .summary-card {
        min-width: calc(50% - 6px);
    }

    .filters {
        flex-direction: column;
        align-items: flex-start;
    }

    td.msg-cell {
        max-width: 200px;
    }

    .header-right {
        gap: 8px;
    }
}

@media (max-width: 480px) {
    .stat-item {
        min-width: 50%;
    }

    .summary-card {
        min-width: 100%;
    }
}
