:root {
    --navy: #13253d;
    --navy-2: #1d3554;
    --blue: #2067a5;
    --blue-soft: #e8f2fb;
    --teal: #1c7d79;
    --green: #247a50;
    --amber: #a76507;
    --red: #a53a3a;
    --ink: #182231;
    --muted: #66758a;
    --line: #dce3eb;
    --surface: #ffffff;
    --background: #f3f6f9;
    --shadow: 0 10px 30px rgba(19, 37, 61, .08);
    --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: Inter, "Segoe UI", Arial, sans-serif; color: var(--ink); background: var(--background); }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; }
.topbar {
    height: 76px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    color: white;
    background: linear-gradient(100deg, var(--navy), #183e66);
    box-shadow: 0 4px 18px rgba(9, 25, 43, .22);
    position: sticky;
    top: 0;
    z-index: 20;
}
.brand-block { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.2); }
.eyebrow { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; opacity: .72; }
h1 { font-size: 21px; line-height: 1.1; margin: 3px 0 0; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.company-picker { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; }
.company-picker select { min-width: 130px; }
select, input[type="search"], input[type="number"], input[type="file"] {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    color: var(--ink);
    padding: 9px 11px;
}
.topbar select { border-color: rgba(255,255,255,.25); background: rgba(255,255,255,.12); color: white; }
.topbar select option { color: var(--ink); }
.user-badge { font-size: 12px; max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .9; }

.workspace { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: calc(100vh - 76px); }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; justify-content: space-between; position: sticky; top: 76px; height: calc(100vh - 76px); }
.sidebar nav { display: flex; flex-direction: column; gap: 5px; }
.nav-item { border: 0; border-radius: 9px; padding: 11px 12px; display: flex; align-items: center; gap: 10px; background: transparent; color: #46566a; text-align: left; font-weight: 600; }
.nav-item:hover { background: #f0f4f8; color: var(--navy); }
.nav-item.active { background: var(--blue-soft); color: var(--blue); }
.nav-icon { width: 22px; text-align: center; font-weight: 800; }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.smarts-link { color: var(--blue); font-size: 13px; font-weight: 700; text-decoration: none; }
.last-updated { color: var(--muted); font-size: 11px; line-height: 1.4; }

.main-content { padding: 24px; min-width: 0; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-header h2 { margin: 0; font-size: 25px; }
.page-header p { margin: 5px 0 0; color: var(--muted); }
.page-actions, .filters { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }

.button { border: 1px solid transparent; border-radius: 8px; padding: 9px 13px; font-weight: 700; background: var(--blue); color: white; }
.button:hover { filter: brightness(.96); }
.button.secondary { background: white; color: var(--navy); border-color: var(--line); }
.topbar .button.secondary { background: rgba(255,255,255,.12); color: white; border-color: rgba(255,255,255,.25); }
.button.danger { background: var(--red); }
.icon-button { width: 38px; height: 38px; border: 0; border-radius: 50%; font-size: 27px; background: #eef2f6; color: var(--ink); }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 17px; box-shadow: 0 2px 8px rgba(19,37,61,.025); }
.kpi-label { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 30px; font-weight: 800; margin-top: 7px; color: var(--navy); }
.kpi-note { color: var(--muted); font-size: 12px; margin-top: 4px; }
.kpi-card.attention .kpi-value { color: var(--amber); }
.kpi-card.critical .kpi-value { color: var(--red); }
.kpi-card.good .kpi-value { color: var(--green); }

.panel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 2px 8px rgba(19,37,61,.025); min-width: 0; }
.panel-header { padding: 15px 17px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-header h3 { margin: 0; font-size: 16px; }
.panel-body { padding: 16px 17px; }
.panel.full { grid-column: 1 / -1; }

.bar-list { display: grid; gap: 11px; }
.bar-row { display: grid; grid-template-columns: minmax(100px, 170px) 1fr 38px; gap: 10px; align-items: center; font-size: 12px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.bar-track { height: 9px; background: #edf1f5; border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--blue), #4e99d2); border-radius: 99px; }
.bar-count { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

.grid-container { width: 100%; height: 600px; }
.grid-container.medium { height: 430px; }
.grid-container.small { height: 300px; }
.ag-theme-quartz { --ag-font-family: Inter, "Segoe UI", Arial, sans-serif; --ag-font-size: 12px; --ag-header-background-color: #f5f7fa; --ag-header-foreground-color: #33455c; --ag-border-color: var(--line); --ag-row-hover-color: #f2f7fc; }
.status-pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 3px 8px; font-size: 11px; font-weight: 700; background: #eef2f6; color: #47566a; }
.status-pill.good { background: #e7f5ed; color: var(--green); }
.status-pill.warning { background: #fff1dd; color: var(--amber); }
.status-pill.critical { background: #fde9e9; color: var(--red); }
.issue-list { display: flex; gap: 4px; flex-wrap: wrap; padding: 4px 0; }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab-button { border: 0; background: transparent; padding: 10px 12px; color: var(--muted); font-weight: 700; border-bottom: 3px solid transparent; }
.tab-button.active { color: var(--blue); border-bottom-color: var(--blue); }

.notice { border-radius: 9px; padding: 13px 14px; border: 1px solid var(--line); background: #f8fafc; color: #43536a; font-size: 13px; line-height: 1.5; }
.notice.warning { border-color: #ecd09f; background: #fff8eb; }
.notice.good { border-color: #b5ddc5; background: #eef9f2; }
.notice.critical { border-color: #efb8b8; background: #fff0f0; }
.empty-state { color: var(--muted); text-align: center; padding: 34px; }
.loading-state { min-height: 50vh; display: grid; place-content: center; text-align: center; color: var(--muted); }
.spinner { width: 34px; height: 34px; margin: auto; border: 3px solid #dce5ee; border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.drawer-backdrop { position: fixed; inset: 0; background: rgba(13,25,40,.38); z-index: 39; }
.device-drawer { position: fixed; top: 0; right: 0; width: min(780px, 92vw); height: 100vh; background: white; z-index: 40; box-shadow: -18px 0 50px rgba(0,0,0,.18); transform: translateX(102%); transition: transform .22s ease; display: flex; flex-direction: column; }
.device-drawer.open { transform: translateX(0); }
.drawer-header { min-height: 76px; padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.drawer-header h2 { margin: 3px 0 0; }
.drawer-content { padding: 18px 20px 40px; overflow: auto; }
.detail-section { margin-bottom: 20px; }
.detail-section h3 { font-size: 15px; margin: 0 0 10px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px 16px; }
.detail-item { min-width: 0; }
.detail-label { color: var(--muted); font-size: 11px; text-transform: uppercase; font-weight: 700; }
.detail-value { margin-top: 3px; overflow-wrap: anywhere; font-size: 13px; }
.detail-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.detail-table th, .detail-table td { border-bottom: 1px solid var(--line); text-align: left; padding: 7px 8px; vertical-align: top; }
.detail-table th { color: var(--muted); background: #f7f9fb; }

.toast-container { position: fixed; right: 18px; bottom: 18px; z-index: 60; display: grid; gap: 8px; }
.toast { background: var(--navy); color: white; padding: 12px 14px; border-radius: 9px; box-shadow: var(--shadow); font-size: 13px; max-width: 380px; }
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }

.code-block { background: #142033; color: #dbe9f7; border-radius: 8px; padding: 13px; overflow: auto; font-family: Consolas, monospace; font-size: 12px; }

@media (max-width: 1100px) {
    .kpi-grid { grid-template-columns: repeat(2, minmax(160px, 1fr)); }
    .panel-grid { grid-template-columns: 1fr; }
    .panel.full { grid-column: auto; }
}
@media (max-width: 760px) {
    .topbar { height: auto; min-height: 76px; align-items: flex-start; gap: 12px; flex-direction: column; padding: 14px; }
    .topbar-actions { width: 100%; flex-wrap: wrap; }
    .workspace { display: block; }
    .sidebar { position: static; height: auto; padding: 8px; overflow-x: auto; }
    .sidebar nav { flex-direction: row; }
    .nav-item { white-space: nowrap; }
    .sidebar-footer { display: none; }
    .main-content { padding: 16px; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .page-header { align-items: flex-start; flex-direction: column; }
    .detail-grid { grid-template-columns: 1fr; }
}
