/* Shared design system for the Call Analytic server-rendered UI (Thymeleaf).
   Layout: fixed dark sidebar (fragments/layout.html :: sidebar) + light content area with cards. */

:root {
    --sidebar-bg: #111827;
    --sidebar-bg-hover: #1f2937;
    --sidebar-text: #9ca3af;
    --sidebar-text-active: #ffffff;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --bg: #f1f5f9;
    --card-bg: #ffffff;
    --border: #e5e7eb;
    --text: #1f2937;
    --text-muted: #6b7280;
    --danger: #dc2626;
    --danger-bg: #fee2e2;
    --danger-text: #991b1b;
    --success-bg: #dcfce7;
    --success-text: #166534;
    --warning-bg: #fef3c7;
    --warning-text: #92400e;
    --neutral-bg: #e5e7eb;
    --neutral-text: #374151;
    --tag-bg: #e0e7ff;
    --tag-text: #3730a3;
    --sidebar-width: 15rem;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, sans-serif;
    color: var(--text);
    background: var(--bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout shell */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    flex: 0 0 var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 1.25rem 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}
.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--sidebar-text-active);
    font-weight: 700;
    font-size: 1.05rem;
    padding: 0 0.4rem;
}
.sidebar .brand svg { flex: none; }
.sidebar nav { display: flex; flex-direction: column; gap: 0.2rem; }
.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem 0.7rem;
    border-radius: 0.5rem;
    color: var(--sidebar-text);
    font-size: 0.92rem;
    text-decoration: none;
}
.sidebar nav a svg { flex: none; opacity: 0.85; }
.sidebar nav a:hover { background: var(--sidebar-bg-hover); color: var(--sidebar-text-active); text-decoration: none; }
.sidebar nav a.active { background: var(--accent); color: #fff; }
.sidebar nav a.active svg { opacity: 1; }

.main { flex: 1 1 auto; padding: 1.75rem 2.25rem 3rem; min-width: 0; }

.topbar {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.topbar h1 { font-size: 1.5rem; margin: 0; }
.topbar .topbar-actions { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.9rem; }

/* Cards */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    padding: 1.25rem 1.5rem;
    margin-top: 1.25rem;
}
.card.resolved { opacity: 0.55; }
.card h2 { font-size: 1.05rem; color: var(--text); margin: 0 0 0.9rem; }
.card h3 { font-size: 0.92rem; color: var(--text-muted); margin: 1rem 0 0.4rem; }
.card-header { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 0.5rem; }
.card-header .file { font-weight: 600; }

/* KPI cards */
.kpis { display: flex; flex-wrap: wrap; gap: 1.1rem; margin-top: 1.5rem; }
.kpi {
    flex: 1 1 12rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    padding: 1.1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.9rem;
}
.kpi .icon {
    flex: none;
    width: 2.6rem;
    height: 2.6rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}
.kpi .icon.blue { background: #2563eb; }
.kpi .icon.purple { background: #7c3aed; }
.kpi .icon.green { background: #16a34a; }
.kpi .icon.orange { background: #ea580c; }
.kpi .icon.red { background: #dc2626; }
.kpi .body { min-width: 0; }
.kpi .label { font-size: 0.82rem; color: var(--text-muted); }
.kpi .value { font-size: 1.6rem; font-weight: 700; margin-top: 0.1rem; line-height: 1.1; }
.kpi .value a { color: inherit; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; color: var(--text-muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.02em; }
tbody tr[data-href] { cursor: pointer; }
tbody tr[data-href]:hover { background: #f8fafc; }

/* Badges */
.badge { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.8rem; font-weight: 500; }
.status-COMPLETED, .sentiment-positive, .active-label { background: var(--success-bg); color: var(--success-text); }
.status-FAILED, .sentiment-negative { background: var(--danger-bg); color: var(--danger-text); }
.status-UPLOADED, .status-TRANSCRIBING, .status-TRANSCRIBED, .status-ANALYZING { background: var(--warning-bg); color: var(--warning-text); }
.sentiment-neutral { background: var(--neutral-bg); color: var(--neutral-text); }

.tags span, .topics span {
    display: inline-block;
    background: var(--tag-bg);
    color: var(--tag-text);
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    margin: 0 0.35rem 0.35rem 0;
    font-size: 0.82rem;
}
.reasons span {
    display: inline-block;
    background: var(--danger-bg);
    color: var(--danger-text);
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    margin: 0.5rem 0.35rem 0 0;
    font-size: 0.82rem;
}

/* Forms & buttons */
button, input[type="submit"] {
    padding: 0.5rem 1.1rem;
    border: none;
    border-radius: 0.5rem;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-size: 0.9rem;
}
button:hover { background: var(--accent-hover); }
button.danger { background: var(--danger); padding: 0.3rem 0.7rem; font-size: 0.85rem; }
button.danger:hover { background: #b91c1c; }

input[type="text"], input[type="file"], select, textarea {
    padding: 0.45rem 0.65rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    font-family: inherit;
    font-size: 0.9rem;
    background: #fff;
}
textarea { width: 100%; box-sizing: border-box; }
label { font-size: 0.85rem; color: var(--text-muted); }

form.upload, form.reanalyze {
    margin-top: 1.25rem;
    padding: 1.1rem 1.25rem;
    border: 1px dashed #cbd5e1;
    border-radius: 0.75rem;
    background: var(--card-bg);
}

form.filters { display: flex; flex-wrap: wrap; align-items: end; gap: 0.9rem; margin-top: 1.25rem; }
form.filters div { display: flex; flex-direction: column; gap: 0.25rem; }
form.filters select { min-width: 10rem; }
form.filters a.reset { font-size: 0.88rem; align-self: center; }

form.add { display: flex; gap: 0.6rem; align-items: center; }
form.add input[type="text"] { min-width: 16rem; }
form.remove, form.activate, form.resolve { display: inline; }
label.toggle { display: flex; align-items: center; gap: 0.5rem; font-size: 0.95rem; color: var(--text); }

/* Charts */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 1.25rem; margin-top: 1.25rem; }
.chart-card .chart-wrap { position: relative; height: 280px; }
.chart-card p.no-data { color: var(--text-muted); font-size: 0.9rem; }

/* Dashboard (Главная): two-column rows, funnel, bar-list panels, AI insight cards */
.dashboard-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 1.25rem; margin-top: 1.25rem; align-items: start; }
.dashboard-grid--even { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) {
    .dashboard-grid { grid-template-columns: 1fr; }
}

.funnel { display: flex; flex-direction: column; gap: 1rem; margin-top: 0.75rem; }
.funnel-row { display: flex; align-items: center; gap: 1rem; }
.funnel-shape-wrap { flex: 0 0 9rem; height: 2.75rem; display: flex; align-items: center; justify-content: center; }
.funnel-shape { width: 100%; height: 100%; display: block; }
.funnel-shape.stage1 { fill: #34c795; }
.funnel-shape.stage2 { fill: #4f8ff0; }
.funnel-shape.stage3 { fill: #8b7fe8; }
.funnel-info { display: flex; align-items: baseline; gap: 0.5rem; }
.funnel-info .label { flex: 0 0 8.5rem; font-weight: 600; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.funnel-info .value { font-weight: 700; font-size: 1rem; white-space: nowrap; }
.funnel-info .pct { color: var(--text-muted); font-size: 0.85rem; }

.bar-list { display: flex; flex-direction: column; gap: 0.9rem; margin-top: 0.6rem; }
.bar-list-row { display: flex; align-items: center; gap: 0.9rem; }
.bar-list-label {
    flex: 0 0 10.5rem;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text);
    white-space: normal;
    word-break: break-word;
    line-height: 1.25;
}
.bar-list-label::first-letter { text-transform: uppercase; }
.bar-list-track { flex: 1; background: #eef1f6; border-radius: 999px; height: 0.85rem; overflow: hidden; min-width: 3rem; }
.bar-list-fill { height: 100%; border-radius: 999px; }
.bar-list-value { flex: 0 0 2.4rem; text-align: right; font-size: 0.88rem; font-weight: 600; color: var(--text); }

/* One distinct color per row, no cycling — covers up to CallAnalyticsService.TOP_N (10) rows */
.bar-list-row:nth-child(1) .bar-list-fill { background: #f0555a; }
.bar-list-row:nth-child(2) .bar-list-fill { background: #ffa53e; }
.bar-list-row:nth-child(3) .bar-list-fill { background: #ffd23e; }
.bar-list-row:nth-child(4) .bar-list-fill { background: #4f8ff0; }
.bar-list-row:nth-child(5) .bar-list-fill { background: #8b7fe8; }
.bar-list-row:nth-child(6) .bar-list-fill { background: #34c795; }
.bar-list-row:nth-child(7) .bar-list-fill { background: #f472b6; }
.bar-list-row:nth-child(8) .bar-list-fill { background: #22c1c3; }
.bar-list-row:nth-child(9) .bar-list-fill { background: #b45309; }
.bar-list-row:nth-child(10) .bar-list-fill { background: #c7ced9; }

.insights { display: flex; flex-direction: column; gap: 0.85rem; margin-top: 0.5rem; }
.insight { display: flex; gap: 0.85rem; padding: 0.85rem 1rem; background: #f8fafc; border: 1px solid var(--border); border-radius: 0.6rem; }
.insight .icon { flex: none; width: 2.1rem; height: 2.1rem; border-radius: 50%; background: #ede9fe; color: #7c3aed; display: flex; align-items: center; justify-content: center; }
.insight .body { min-width: 0; }
.insight .body .title { font-weight: 600; font-size: 0.92rem; }
.insight .body .desc { font-size: 0.87rem; color: var(--text-muted); margin-top: 0.15rem; }
.insight .body a { font-size: 0.85rem; display: inline-block; margin-top: 0.35rem; }

/* Misc */
.muted { color: #9ca3af; }
.empty { color: var(--text-muted); margin-top: 1.25rem; }
.message { background: var(--success-bg); color: var(--success-text); padding: 1rem 1.25rem; border-radius: 0.75rem; }
.error { background: var(--danger-bg); color: var(--danger-text); padding: 1rem 1.25rem; border-radius: 0.75rem; }
p.hint { color: var(--text-muted); font-size: 0.9rem; }
pre { white-space: pre-wrap; background: #f8fafc; padding: 1rem; border-radius: 0.5rem; }
dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1.25rem; margin: 0; }
dt { color: var(--text-muted); }
.summary { display: inline-block; max-width: 16rem; font-size: 0.9rem; }
.lost-badge { display: inline-block; margin-left: 0.4rem; font-size: 0.9rem; cursor: help; }
.lost-badge.resolved { opacity: 0.4; }
.lost-booking { margin-top: 1rem; padding: 0.85rem 1.1rem; background: var(--danger-bg); border-radius: 0.75rem; }
.lost-booking .action { margin-top: 0.6rem; padding: 0.65rem 0.85rem; background: #fff; border-left: 3px solid var(--danger); border-radius: 0.4rem; }
.action.blue { border-left-color: var(--accent); background: #eff6ff; }
.action .label { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.meta { color: var(--text-muted); font-size: 0.85rem; }
.promptPreview { max-width: 32rem; white-space: pre-wrap; font-size: 0.85rem; color: var(--text-muted); }
