:root {
    --font-ui: "Manrope", "Inter", "Segoe UI", Arial, sans-serif;
    --font-heading: "Plus Jakarta Sans", "Manrope", "Inter", sans-serif;

    --bg: #f5f5f6;
    --bg-elevated: #eeeeef;
    --surface: #ffffff;
    --surface-soft: #f8f8f9;
    --text: #101828;
    --muted: #667085;
    --primary: #165d48;
    --primary-soft: #1d7a5f;
    --accent: #2f8f6f;
    --border: #d8dadd;
    --ring: rgba(22, 93, 72, 0.28);
    --shadow-sm: 0 6px 18px rgba(16, 24, 40, 0.06);
    --shadow: 0 12px 30px rgba(16, 24, 40, 0.08);

    --sidebar-bg: #232629;
    --sidebar-soft: #2d3136;
    --sidebar-border: #3a3f46;
    --sidebar-text: #e5e7eb;
    --sidebar-muted: #b3b8bf;
    --sidebar-active-bg: #3a4048;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: var(--font-ui);
    color: var(--text);
    background: linear-gradient(155deg, #f7f7f8 0%, #ececef 100%);
}

h1, h2, h3, h4 { font-family: var(--font-heading); letter-spacing: -0.01em; }

.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 290px;
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, #1b1e22 100%);
    border-right: 1px solid var(--sidebar-border);
    padding: 20px 16px;
}
.sidebar-brand {
    display: grid;
    place-items: center;
    padding: 10px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.14);
}
.sidebar-logo {
    width: 172px;
    max-width: 100%;
    height: 66px;
    object-fit: contain;
    border-radius: 12px;
    background: #ffffff;
    padding: 8px 12px;
}
.sidebar ul { list-style: none; padding: 0; margin: 24px 0 0; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--sidebar-text);
    padding: 12px 14px;
    border-radius: 11px;
    margin-bottom: 8px;
    border: 1px solid transparent;
    transition: all .2s;
    font-weight: 600;
}
.nav-item:hover, .nav-item.active {
    background: var(--sidebar-active-bg);
    border-color: rgba(255, 255, 255, 0.22);
    color: #f8fafc;
}
.nav-icon {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: 0 0 auto;
}

.main-area { flex: 1; display: flex; flex-direction: column; }
.app-header {
    min-height: 82px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 12px 24px;
}
.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
    border: 1px solid var(--border);
    padding: 8px 10px;
    border-radius: 14px;
    box-shadow: var(--shadow-sm);
}
.header-user-meta { display: flex; flex-direction: column; min-width: 210px; }
.header-user-meta strong { font-size: .95rem; }
.header-user-meta span { color: var(--muted); font-size: .83rem; }

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(145deg, #2f8f6f 0%, #165d48 100%);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    border: 2px solid rgba(255, 255, 255, 0.9);
    overflow: hidden;
}
.avatar.large { width: 84px; height: 84px; font-size: 1.8rem; }
.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.content-area { padding: 24px; background: transparent; }
.page-shell { width: 100%; }
.dashboard-page { max-width: none; }
.page-heading h2 { margin-bottom: 6px; font-size: clamp(1.45rem, 2vw, 1.8rem); }
.page-heading p { margin-top: 0; color: var(--muted); }

.blank-state {
    border: 1px dashed var(--border);
    background: var(--surface-soft);
    padding: 34px;
    border-radius: 16px;
    color: var(--muted);
}

.tabs { margin-top: 18px; }
.tab-list { display: flex; gap: 10px; margin-bottom: 16px; }
.tab-button {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    padding: 10px 16px;
    border-radius: 999px;
    font-weight: 600;
    cursor: pointer;
}
.tab-button.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-sm);
    padding: 20px;
    margin-bottom: 20px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}
.form-grid label { display: flex; flex-direction: column; font-size: .9rem; color: var(--muted); gap: 6px; font-weight: 600; }
input, select {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 0.95rem;
    background: #fff;
    color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--ring); border-color: transparent; }

.button-row { display: flex; gap: 10px; margin-top: 16px; }
.btn {
    border: none;
    border-radius: 10px;
    padding: 10px 14px;
    font-weight: 700;
    cursor: pointer;
    font-family: var(--font-ui);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-soft); }
.btn-secondary { background: #f2f4f7; color: #344054; border: 1px solid var(--border); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.helper-text { color: var(--muted); margin-top: 0; }
.feedback {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    display: none;
    font-size: .92rem;
}
.feedback.success { display: block; background: #ecfdf3; color: #027a48; border: 1px solid #a6f4c5; }
.feedback.error { display: block; background: #fef3f2; color: #b42318; border: 1px solid #fecdca; }

.panel-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.sql-preview {
    background: #101828;
    color: #e4e7ec;
    border-radius: 12px;
    padding: 14px;
    max-height: 250px;
    overflow: auto;
    font-size: .85rem;
}

.table-wrap { overflow-x: auto; }
.users-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 14px;
}
.users-table th, .users-table td {
    text-align: left;
    padding: 10px;
    border-bottom: 1px solid var(--border);
}
.users-table th { color: var(--muted); font-weight: 600; }
.muted-cell { color: var(--muted); text-align: center; }
.table-action {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
    padding: 6px 10px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

.profile-card .profile-top {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}
.file-label input[type="file"] { padding: 9px; }

.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(145deg, #fcfcfc 0%, #f0f1f3 100%);
}
.auth-shell {
    width: min(480px, 94vw);
}
.auth-panel { padding: 0; }
.auth-brand-logo {
    width: min(280px, 76%);
    align-self: center;
    object-fit: contain;
    border-radius: 12px;
    background: #fff;
    padding: 8px 12px;
    border: 1px solid #e4e7ec;
}
.auth-panel-form {
    display: grid;
    place-items: center;
    background: transparent;
}
.auth-card {
    width: min(460px, 100%);
    background: #ffffff;
    border: 1px solid #e4e7ec;
    box-shadow: 0 16px 30px rgba(16, 24, 40, 0.08);
    border-radius: 16px;
    padding: 34px 30px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.auth-card h1 { margin: 8px 0 0; font-size: 1.5rem; text-align: center; }
.auth-subtitle { margin: -4px 0 6px; color: var(--muted); text-align: center; }
.auth-field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin: 0;
    color: #344054;
    font-size: .88rem;
    font-weight: 600;
}
.auth-field input { width: 100%; }
.remember-row {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
    color: #475467;
    font-size: .88rem;
    font-weight: 600;
}
.auth-btn { margin-top: 4px; }

@media (max-width: 900px) {
    .app-layout { flex-direction: column; }
    .sidebar { width: 100%; }
    .header-user-meta { min-width: 0; }
}

.dashboard-page .card h3 { margin-top: 0; }
.dashboard-grid { display: grid; gap: 14px; margin-bottom: 16px; }
.dashboard-grid.kpi { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.dashboard-grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.dashboard-grid.four { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); }
.kpi-card .label { color: var(--muted); font-size: .82rem; }
.kpi-card .value { font-size: 1.3rem; font-weight: 700; margin-top: 4px; }
.health-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 10px; }
.health-pill { border: 1px solid var(--border); border-radius: 999px; padding: 8px 12px; background: #ffffff; font-size: .85rem; }
.status-badge { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: .74rem; font-weight: 700; text-transform: uppercase; }
.status-success{ background:#e5f5e4; color:#2b6a2f; }
.status-failed,.status-error{ background:#f7e6e6; color:#8a2831; }
.status-running{ background:#f9f0dd; color:#8d631d; }
.chart-box { min-height: 220px; }
.chart-svg { width: 100%; height: 220px; background: #ffffff; border: 1px solid var(--border); border-radius: 10px; }
.rank-list { list-style:none; padding:0; margin:0; display:grid; gap:8px; }
.rank-list li { display:flex; justify-content:space-between; gap:8px; border-bottom:1px dashed var(--border); padding-bottom:6px; }
.shortcut-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(170px,1fr)); gap:10px; }
.shortcut-card { text-decoration:none; color:var(--text); background:var(--surface-soft); border:1px solid var(--border); border-radius:12px; padding:14px; font-weight:600; }
.data-table { width:100%; border-collapse:collapse; font-size:.86rem; }
.data-table th,.data-table td { padding:8px; border-bottom:1px solid var(--border); text-align:left; }
.data-table th { color:var(--muted); position: sticky; top: 0; background: #fffaf3; }
.table-scroll { overflow:auto; max-height:420px; border:1px solid var(--border); border-radius:10px; }
.filter-row { display:grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap:10px; margin-bottom:12px; }
.filter-row input,.filter-row select { width:100%; }
.helper-inline { font-size:.8rem; color:var(--muted); margin-top:4px; }
.animal-drawer { position:fixed; right:-560px; top:0; height:100vh; width:min(560px,92vw); background:var(--surface); border-left:1px solid var(--border); box-shadow: var(--shadow); z-index:40; transition:right .25s; padding:16px; overflow:auto; }
.animal-drawer.open { right:0; }
.close-drawer { float:right; }
.metric-help { border-bottom:1px dotted var(--muted); cursor:help; }

@media (max-width: 1024px) {
    .auth-shell { min-height: unset; }
}


.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.dashboard-grid.two-col { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.kpi-card { margin: 0; padding: 14px; }
.kpi-label { color: var(--muted); font-size: .82rem; display: block; margin-bottom: 6px; }
.kpi-value { font-size: 1.15rem; }
.filter-card h3, .card h3 { margin-top: 0; }
.mini-chart { margin-bottom: 18px; }
.mini-chart h4, .spotlight-block h4 { margin: 4px 0 10px; }
.bar-row {
    display: grid;
    grid-template-columns: 140px 1fr 64px;
    gap: 8px;
    align-items: center;
    margin-bottom: 6px;
    font-size: .84rem;
}
.bar-track {
    background: #e8eef6;
    border: 1px solid var(--border);
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
}
.bar-track i {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
}
.spotlight-block { margin-bottom: 16px; }
.users-table.compact th, .users-table.compact td { padding: 8px; font-size: .82rem; }

@media (max-width: 840px) {
    .bar-row { grid-template-columns: 1fr; }
}

.genetic-kpis { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
@media (min-width: 1100px) {
    .genetic-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.kpi-card-premium { position: relative; overflow: hidden; transition: transform .2s ease, box-shadow .2s ease; animation: fadeInUp .35s ease both; }
.kpi-card-premium:hover { transform: translateY(-2px); box-shadow: 0 14px 24px rgba(16, 24, 40, 0.12); }
.kpi-card-premium .kpi-icon { width: 32px; height: 32px; border-radius: 10px; background: rgba(22,93,72,.12); display:grid; place-items:center; margin-bottom:10px; }
.kpi-card-premium .kpi-icon svg { width: 19px; height: 19px; stroke: var(--primary); fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.kpi-card-premium .kpi-note { display:block; margin-top:8px; color:var(--muted); font-size:.76rem; }
.kpi-card-premium.healthy { border-color: #7dc58a; }
.kpi-card-premium.caution { border-color: #f0b429; }
.kpi-card-premium.danger { border-color: #d86a73; }
.chart-host { min-height: 280px; }
.line-svg { width:100%; min-height:260px; border:1px solid var(--border); border-radius:12px; background:#ffffff; }
.line-svg text { font-size: 10px; fill: #667085; }
.line-svg .y-grid { stroke: #e4eaf3; stroke-width: 1; stroke-dasharray: 4 4; }
.line-svg .axis-line { stroke: #cbd5e1; stroke-width: 1.2; }
.line-svg .y-label { font-size: 10px; fill: #475467; }
.line-svg .axis-title { font-size: 11px; fill: #667085; font-weight: 600; }
.chart-legend { display:flex; flex-wrap:wrap; gap:10px; margin-top:10px; font-size:.8rem; color:var(--muted); }
.chart-legend span { display:inline-flex; align-items:center; gap:6px; }
.chart-legend i, .risk-legend i { width:10px; height:10px; border-radius:50%; display:inline-block; }
.donut { width: 190px; height: 190px; border-radius: 50%; margin: 12px auto; display:grid; place-items:center; position:relative; }
.donut > div { width: 120px; height: 120px; border-radius:50%; background:var(--surface); display:grid; place-items:center; font-weight:700; font-size:1.2rem; }
.donut small { display:block; font-size:.72rem; font-weight:500; color:var(--muted); }
.risk-legend { display:flex; justify-content:center; flex-wrap:wrap; gap:10px; font-size:.85rem; }
.risk-panel-layout { display:grid; grid-template-columns: minmax(220px, 280px) 1fr; gap:14px; align-items: center; }
.risk-side-alerts { min-height: 100%; display: grid; align-content: center; }
.alert-panel { background:#fef6f5; border:1px solid #fecdca; border-radius:10px; padding:10px 12px; margin-top:12px; }
.alert-panel h4 { margin:0 0 8px; color:#a1282d; }
.alert-panel p { margin:0 0 6px; font-size:.84rem; }
.leaderboard { display:grid; gap:8px; }
.leader-row { border:1px solid var(--border); border-radius:12px; background:#ffffff; padding:10px; display:grid; grid-template-columns:56px 1fr 160px; gap:10px; align-items:center; }
.rank-badge { display:inline-grid; place-items:center; width:46px; height:28px; border-radius:999px; background:var(--surface-soft); border:1px solid var(--border); font-weight:700; font-size:.8rem; }
.leader-row p { margin:3px 0 0; font-size:.78rem; color:var(--muted); }
.score-cell { text-align:right; }
.score-cell strong { font-size:.95rem; }
.radar-svg { width:100%; max-width:390px; margin:0 auto; display:block; }
.radar-svg line { stroke: #d0dae8; stroke-width: 1; }
.radar-svg text { font-size: 8px; fill: #667085; }
.radar-svg polygon { fill: rgba(22,93,72,.24); stroke: #165d48; stroke-width: 2; }
.insight-grid { display:grid; gap:10px; }
.insight-card { border:1px solid var(--border); border-radius:12px; padding:12px; background:#ffffff; }
.insight-card h4 { margin:0 0 6px; }
.insight-card p { margin:0; color:var(--muted); font-size:.88rem; }
.insight-card.good { border-left: 4px solid #2f9e44; }
.insight-card.caution { border-left: 4px solid #f08c00; }
.insight-card.danger { border-left: 4px solid #c92a2a; }

.filter-collapsible { padding-top: 0; overflow: hidden; }
.filter-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 0;
    background: linear-gradient(145deg, #f8fbff, #ffffff);
    border-bottom: 1px solid var(--border);
    padding: 14px;
    cursor: pointer;
}
.filter-toggle span { text-align: left; }
.filter-toggle h3 { margin: 0; }
.filter-toggle small { color: var(--muted); font-size: .78rem; }
.filter-toggle i {
    width: 11px;
    height: 11px;
    border-right: 2px solid #64748b;
    border-bottom: 2px solid #64748b;
    transform: rotate(45deg);
    transition: transform .2s ease;
}
.filter-collapsible:not(.collapsed) .filter-toggle i { transform: rotate(-135deg); }
.filter-content { padding: 14px; animation: fadeInUp .25s ease both; }

.watch-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.watch-card { border: 1px solid var(--border); border-radius: 14px; background: #fffdf8; padding: 12px; box-shadow: 0 8px 20px rgba(141, 63, 35, 0.08); }
.watch-card header { display:flex; justify-content:space-between; align-items:baseline; gap:10px; margin-bottom:8px; }
.watch-card header span { color: var(--muted); font-size: .8rem; }
.watch-metrics p { margin: 0 0 4px; font-size: .82rem; color: #475467; }
.watch-risk-meter { height: 8px; border-radius: 999px; overflow: hidden; background: #e4ecf7; border: 1px solid #cfdae8; margin-top: 6px; }
.watch-risk-meter i { height: 100%; display:block; background: linear-gradient(90deg, #f08c00, #c92a2a); }
.watch-risk-label { margin: 7px 0 3px; font-size: .78rem; font-weight: 700; }
.watch-reason { margin: 0 0 4px; font-size: .82rem; color: #344054; }
.watch-card small { color: var(--muted); }
.watch-card.good { border-left: 4px solid #2f9e44; }
.watch-card.caution { border-left: 4px solid #f08c00; }
.watch-card.danger { border-left: 4px solid #c92a2a; }

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

@media (max-width: 900px) {
    .leader-row { grid-template-columns: 1fr; }
    .score-cell { text-align: left; }
    .risk-panel-layout { grid-template-columns: 1fr; }
}
