/* ─── Переменные ─────────────────────────────────────────── */
:root {
    --primary:        #a3e635;
    --primary-dark:   #84cc16;
    --primary-hover:  #bef264;
    --sidebar-bg:     #0d1117;
    --sidebar-border: rgba(255,255,255,.06);
    --bg:             #0f172a;
    --bg-card:        #1e293b;
    --bg-input:       #0f172a;
    --text:           #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted:     #64748b;
    --border:         rgba(255,255,255,.08);
    --border-strong:  rgba(255,255,255,.12);
    --success:        #22c55e;
    --warning:        #f59e0b;
    --error:          #ef4444;
    --sidebar-w:      200px;
    --header-h:       56px;
}

/* ─── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: .9rem;
    line-height: 1.5;
}

/* ─── App Layout ─────────────────────────────────────────── */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ─── Sidebar ────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 1.125rem 1.25rem;
    border-bottom: 1px solid var(--sidebar-border);
}

.logo {
    display: flex;
    align-items: center;
    gap: .5rem;
    text-decoration: none;
}

.logo-icon { font-size: 1.25rem; }

.logo-text {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--primary);
}

.nav-menu {
    list-style: none;
    padding: .5rem 0;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .625rem 1.25rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: .875rem;
    font-weight: 500;
    transition: all .15s;
    border-left: 3px solid transparent;
    white-space: nowrap;
}

.nav-item:hover {
    background: rgba(255,255,255,.04);
    color: var(--text-secondary);
}

.nav-item.active {
    background: rgba(163,230,53,.08);
    color: var(--primary);
    border-left-color: var(--primary);
}

.nav-icon { font-size: 1rem; flex-shrink: 0; }

/* ─── Main Content ───────────────────────────────────────── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* ─── Header ─────────────────────────────────────────────── */
.header {
    height: var(--header-h);
    min-height: var(--header-h);
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    flex-shrink: 0;
    gap: 1rem;
}

.page-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
}

.header-right {
    display: flex;
    align-items: center;
    gap: .625rem;
    flex-shrink: 0;
}

/* ─── Content Area ───────────────────────────────────────── */
.content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem 1.25rem;
    min-height: 0;
}

/* ─── Pages ─────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block !important; }

/* ─── Buttons ────────────────────────────────────────────── */
.btn, .btn-primary {
    padding: .4rem .875rem;
    border-radius: .375rem;
    border: none;
    cursor: pointer;
    font-size: .8rem;
    font-weight: 600;
    transition: all .15s;
    white-space: nowrap;
}

.btn {
    background: rgba(255,255,255,.06);
    color: var(--text-secondary);
    border: 1px solid var(--border-strong);
}

.btn:hover { background: rgba(255,255,255,.1); color: var(--text); }

.btn-primary {
    background: var(--primary);
    color: #0a0a0a;
}

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

/* ─── Form Controls ──────────────────────────────────────── */
.search-input, .filter-select {
    padding: .4rem .75rem;
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: .375rem;
    color: var(--text);
    font-size: .8rem;
    outline: none;
    transition: border-color .15s;
}

.search-input { min-width: 220px; }
.filter-select { cursor: pointer; }
.search-input:focus, .filter-select:focus { border-color: var(--primary); }

.filters {
    display: flex;
    align-items: center;
    gap: .625rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

/* ─── Panel ──────────────────────────────────────────────── */
.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: .625rem;
    margin-bottom: 1rem;
}

.panel-header, .panel > h3, .panel > .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .875rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.panel > h3 {
    font-size: .875rem;
    font-weight: 600;
    color: var(--text);
}

/* ─── Tables ─────────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .825rem;
}

.data-table th {
    padding: .625rem 1rem;
    text-align: left;
    font-size: .7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    background: rgba(0,0,0,.15);
}

.data-table td {
    padding: .625rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    vertical-align: middle;
}

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

.data-table tr:hover td { background: rgba(255,255,255,.02); }

.data-table td code {
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: .8rem;
    color: var(--text-muted);
}

.data-table .loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

/* ─── Status badges ──────────────────────────────────────── */
.status-ok, .status-success {
    display: inline-flex; align-items: center;
    padding: .2rem .6rem; border-radius: 9999px;
    font-size: .72rem; font-weight: 700;
    background: rgba(34,197,94,.12); color: var(--success);
}

.status-error {
    display: inline-flex; align-items: center;
    padding: .2rem .6rem; border-radius: 9999px;
    font-size: .72rem; font-weight: 700;
    background: rgba(239,68,68,.12); color: var(--error);
}

.status-warn, .status-warning {
    display: inline-flex; align-items: center;
    padding: .2rem .6rem; border-radius: 9999px;
    font-size: .72rem; font-weight: 700;
    background: rgba(245,158,11,.12); color: var(--warning);
}

/* ─── Log levels ─────────────────────────────────────────── */
.log-level { padding: .15rem .5rem; border-radius: .25rem; font-size: .72rem; font-weight: 700; text-transform: uppercase; }
.log-level.debug, .log-level.DEBUG { background: rgba(100,116,139,.15); color: #94a3b8; }
.log-level.info,  .log-level.INFO  { background: rgba(34,197,94,.12);  color: #22c55e; }
.log-level.warn,  .log-level.WARN,
.log-level.warning,.log-level.WARNING { background: rgba(245,158,11,.12); color: #f59e0b; }
.log-level.error, .log-level.ERROR { background: rgba(239,68,68,.12);  color: #ef4444; }
.log-level.fatal, .log-level.FATAL { background: rgba(239,68,68,.2);   color: #fca5a5; }

/* ─── Pagination ─────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .875rem 1rem;
    border-top: 1px solid var(--border);
    font-size: .8rem;
    color: var(--text-muted);
}

.pagination .btn { padding: .3rem .7rem; font-size: .78rem; }

/* ─── Dashboard ──────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: .625rem;
    padding: 1.125rem 1.25rem;
}

.stat-card .stat-label {
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    margin-bottom: .375rem;
}

.stat-card .stat-value {
    font-size: 1.625rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1;
}

.stat-card .stat-sub {
    font-size: .72rem;
    color: var(--text-muted);
    margin-top: .25rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 1rem;
}

/* ─── Services list ──────────────────────────────────────── */
.service-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .625rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

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

.service-name { font-weight: 600; font-size: .85rem; color: var(--text); }

.service-status {
    display: flex;
    align-items: center;
    gap: .375rem;
    font-size: .75rem;
}

.dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 4px var(--success);
}

/* ─── Infra cards (summary) ──────────────────────────────── */
#infra-summary-stats,
#apm-overview-stats,
#error-stats,
#alerts-summary,
#service-map-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: .875rem;
    margin-bottom: 1rem;
}

/* ─── Progress bar ───────────────────────────────────────── */
.progress-wrap {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.progress-bar-track {
    flex: 1;
    height: 5px;
    background: rgba(255,255,255,.08);
    border-radius: 3px;
    overflow: hidden;
    min-width: 60px;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 3px;
    background: var(--success);
}

/* ─── Service Map SVG ────────────────────────────────────── */
#service-map-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: .625rem;
    overflow: hidden;
}

#service-map-svg { display: block; width: 100%; }

#service-details-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: .625rem;
    padding: 1.25rem;
    margin-top: 1rem;
}

/* ─── Modal ──────────────────────────────────────────────── */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.75);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    backdrop-filter: blur(2px);
}

.modal.show { display: flex; }

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: .75rem;
    width: 90vw;
    max-width: 900px;
    max-height: 90vh;
    overflow: auto;
}

.modal-content.large { max-width: 1200px; }

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

.modal-header h3 { font-size: 1rem; font-weight: 700; }

.modal-close {
    font-size: 1.375rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
    transition: color .15s;
}

.modal-close:hover { color: var(--text); }

.modal-body { padding: 1.5rem; }

/* ─── Trace waterfall (inline styles в renderTraceDetail) ── */
.trace-waterfall { font-size: .8rem; }
.span-name { font-weight: 500; }
/* НЕ используем .span-bar с background:var(--primary) — даёт зелёный overlay */

/* ─── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.2); }

/* ─── Spinner ────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Subtitle ───────────────────────────────────────────── */
.subtitle { color: var(--text-muted); font-size: .85rem; margin-bottom: 1rem; }

/* ─── Alerts form ────────────────────────────────────────── */
.condition-fields { margin-top: 1rem; }

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

label {
    display: block;
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: .375rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}

input[type="text"], input[type="email"], input[type="number"],
input[type="tel"], select, textarea {
    width: 100%;
    padding: .5rem .75rem;
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: .375rem;
    color: var(--text);
    font-size: .85rem;
    outline: none;
    transition: border-color .15s;
}

input:focus, select:focus, textarea:focus { border-color: var(--primary); }

/* ─── Alert modal ────────────────────────────────────────── */
#alert-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

#alert-modal.show,
#alert-modal[style*="flex"] { display: flex !important; }

/* ─── Correlation ────────────────────────────────────────── */
.timeline-item {
    display: flex;
    gap: 1rem;
    padding: .75rem 0;
    border-bottom: 1px solid var(--border);
    align-items: flex-start;
}

.timeline-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .875rem;
    flex-shrink: 0;
    background: rgba(163,230,53,.1);
}

.timeline-content { flex: 1; min-width: 0; }
.timeline-time { font-size: .75rem; color: var(--text-muted); white-space: nowrap; }

/* ─── Latency colors ─────────────────────────────────────── */
.latency-good    { color: var(--success); }
.latency-warn    { color: var(--warning); }
.latency-bad     { color: var(--error); }
.latency-good, .latency-warn, .latency-bad { font-weight: 600; }


/* ─── Logs list ─────────────────────────────────────────── */
.log-entry {
    display: grid;
    grid-template-columns: 140px 60px 160px 1fr;
    gap: 1rem;
    align-items: baseline;
    padding: .5rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-size: .8rem;
    font-family: 'Fira Code', 'Consolas', monospace;
    transition: background .1s;
}

.log-entry:hover { background: rgba(255,255,255,.02); }
.log-entry:last-child { border-bottom: none; }

.log-time { color: var(--text-muted); white-space: nowrap; font-size: .75rem; }
.log-service { color: #60a5fa; font-weight: 600; font-size: .75rem; }
.log-message { color: var(--text-secondary); word-break: break-word; }
.log-message.error { color: #fca5a5; }
.log-message.warn  { color: #fcd34d; }
.log-message.debug { color: var(--text-muted); }

/* ─── Alert history table fix ────────────────────────────── */
#alert-history-table {
    width: 100%;
    border-collapse: collapse;
}

#alert-history-table th,
#alert-history-table td {
    padding: .625rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: .825rem;
}

#alert-history-table th {
    font-size: .7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    background: rgba(0,0,0,.15);
}

/* ─── API Keys fix ───────────────────────────────────────── */
#api-keys-page .panel { overflow-x: auto; }

/* ─── Error tracking filter fix ─────────────────────────── */
.errors-filters {
    display: flex;
    gap: .625rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

/* ─── Trace modal fix — убираем зелёный фон ─────────────── */
.modal-content { background: var(--bg-card) !important; }
.modal-body pre, .modal-body code { background: rgba(0,0,0,.3); }

/* ─── APM tables ─────────────────────────────────────────── */
.apm-table { width: 100%; border-collapse: collapse; font-size: .825rem; }
.apm-table th, .apm-table td {
    padding: .5rem .875rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.apm-table th {
    font-size: .7rem; font-weight: 600;
    color: var(--text-muted); text-transform: uppercase;
    background: rgba(0,0,0,.15);
}
