:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --text: #172033;
    --muted: #667085;
    --line: #d9e0ea;
    --brand-blue: #001f60;
    --brand-yellow: #ffe600;
    --red: #b42318;
    --red-bg: #fee4e2;
    --orange: #b54708;
    --orange-bg: #ffead5;
    --yellow: #8a6f00;
    --yellow-bg: #fff4bf;
    --blue: #175cd3;
    --blue-bg: #e9f1ff;
    --green: #027a48;
    --green-bg: #dcfae6;
    --page-max: 1180px;
    --page-gutter: 32px;
    --summary-cols: 4;
    --gateway-cols: 3;
    --grid-gap: 14px;
    --card-padding: 16px;
    --summary-min-height: 112px;
    --gateway-min-height: 170px;
    --h1-size: 26px;
    --h2-size: 22px;
    --client-title-size: 16px;
    --subzone-size: 18px;
    --body-size: 16px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    font-size: var(--body-size);
    line-height: 1.4;
}

.login-page {
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(255, 230, 0, 0.18), transparent 34%),
        linear-gradient(145deg, #00143f 0%, var(--brand-blue) 55%, #073c8a 100%);
}

.login-shell {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(100%, 430px);
    margin: 0;
    padding: 40px;
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 24px 70px rgba(0, 12, 45, 0.35);
}

.login-logo {
    display: block;
    width: min(260px, 100%);
    height: auto;
    margin-bottom: 34px;
}

.login-heading span {
    color: var(--blue);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.login-heading h1 {
    margin-top: 7px;
    font-size: 30px;
}

.login-heading p {
    margin: 8px 0 0;
    color: var(--muted);
}

.login-error {
    margin-top: 22px;
    padding: 12px 14px;
    border: 1px solid #fecdca;
    border-radius: 8px;
    background: var(--red-bg);
    color: var(--red);
    font-size: 14px;
    font-weight: 700;
}

.login-form {
    display: grid;
    gap: 9px;
    margin-top: 26px;
}

.login-form label {
    margin-top: 8px;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
}

.login-form input {
    width: 100%;
    min-height: 48px;
    padding: 10px 13px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    outline: none;
}

.login-form input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(23, 92, 211, 0.13);
}

.login-form button {
    min-height: 48px;
    margin-top: 16px;
    border: 0;
    border-radius: 8px;
    background: var(--brand-blue);
    color: #ffffff;
    cursor: pointer;
    font: inherit;
    font-weight: 800;
}

.login-form button:hover,
.login-form button:focus-visible {
    background: #073c8a;
}

@media (max-width: 520px) {
    .login-card {
        padding: 30px 24px;
    }
}

.page {
    width: min(var(--page-max), calc(100% - var(--page-gutter)));
    margin: 0 auto;
    padding: 32px 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 26px;
    padding: 18px;
    border-radius: 8px;
    background: var(--brand-blue);
    color: #ffffff;
}

.brand {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 18px;
}

.brand a {
    display: inline-flex;
    flex: 0 0 auto;
}

.brand-logo {
    display: block;
    width: clamp(190px, 23vw, 320px);
    height: auto;
    flex: 0 0 auto;
    object-fit: contain;
    border-radius: 4px;
}

.nav-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.nav-links a {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 8px 12px;
    border: 1px solid color-mix(in srgb, #ffffff 32%, var(--brand-blue));
    border-radius: 8px;
    background: color-mix(in srgb, #ffffff 8%, var(--brand-blue));
    color: #ffffff;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
}

.nav-links a:hover,
.nav-links a:focus {
    border-color: var(--brand-yellow);
    color: var(--brand-yellow);
}

.section-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

section {
    margin-top: 34px;
}

h1,
h2 {
    margin: 0;
    letter-spacing: 0;
}

h1 {
    font-size: var(--h1-size);
}

h2 {
    font-size: var(--h2-size);
}

.muted {
    color: var(--muted);
    margin: 6px 0 0;
}

.topbar .muted {
    color: color-mix(in srgb, #ffffff 72%, var(--brand-blue));
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(var(--summary-cols), minmax(0, 1fr));
    gap: var(--grid-gap);
    margin-bottom: 20px;
}

.summary-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: var(--card-padding);
    min-height: var(--summary-min-height);
}

.summary-card strong {
    display: block;
    margin-top: 10px;
    font-size: 30px;
    line-height: 1;
}

.summary-card span {
    color: var(--muted);
    font-size: 14px;
}

.summary-card span strong {
    display: inline;
    margin-top: 0;
    font-size: inherit;
    line-height: inherit;
}

.summary-card strong.gateway-client-name {
    display: block;
    color: inherit;
    margin-top: 0;
    font-size: 15px;
    font-weight: 800;
    line-height: 1.2;
}

.summary-card.red {
    background: var(--red-bg);
    border-color: #fecdca;
    color: var(--red);
}

.summary-card.orange {
    background: var(--orange-bg);
    border-color: #fedf89;
    color: var(--orange);
}

.summary-card.yellow {
    background: var(--yellow-bg);
    border-color: #f7df72;
    color: var(--yellow);
}

.summary-card.blue {
    background: var(--blue-bg);
    border-color: #b2ccff;
    color: var(--blue);
}

.summary-card.green {
    background: var(--green-bg);
    border-color: #abefc6;
    color: var(--green);
}

.client-summary-link {
    display: block;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.client-summary-link .summary-card {
    height: 100%;
    transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.client-summary-link:hover .summary-card,
.client-summary-link:focus-visible .summary-card {
    border-color: #84adff;
    box-shadow: 0 10px 24px rgba(23, 92, 211, 0.12);
    transform: translateY(-2px);
}

.client-summary-link:focus-visible {
    border-radius: 8px;
    outline: 3px solid rgba(23, 92, 211, 0.25);
    outline-offset: 3px;
}

.client-card-action {
    display: block;
    margin-top: 14px;
    color: var(--blue);
    font-size: 12px;
    font-weight: 800;
}

.battery-summary-card strong {
    color: var(--text);
    font-size: 18px;
    line-height: 1.25;
}

.battery-total {
    display: block;
    margin-top: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.battery-total b {
    color: var(--blue);
    font-size: 18px;
    line-height: 1;
}

.battery-breakdown {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 14px;
}

.battery-breakdown span {
    display: grid;
    gap: 4px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.battery-breakdown b {
    font-size: 24px;
    line-height: 1;
}

.battery-breakdown .red {
    color: var(--red);
}

.battery-breakdown .orange {
    color: var(--orange);
}

.battery-breakdown .green {
    color: var(--green);
}

.table-wrap {
    overflow-x: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

table {
    width: 100%;
    min-width: 980px;
    border-collapse: collapse;
}

th,
td {
    padding: 13px 14px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    background: #f9fbfd;
}

tr:last-child td {
    border-bottom: 0;
}

.metric {
    display: inline-flex;
    align-items: baseline;
    gap: 8px;
    white-space: nowrap;
    font-weight: 700;
}

.metric small {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.metric.red {
    color: var(--red);
}

.metric.orange {
    color: var(--orange);
}

.metric.yellow {
    color: var(--yellow);
}

.metric.green {
    color: var(--green);
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    font-weight: 700;
    color: var(--red);
}

.status-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 18%, transparent);
}

.status.red {
    color: var(--red);
}

.notice {
    background: var(--panel);
    border: 1px solid var(--line);
    border-left: 4px solid var(--blue);
    border-radius: 8px;
    padding: 14px 16px;
    color: var(--muted);
}

.client-block {
    margin-bottom: 22px;
}

.client-block h3 {
    margin: 0 0 10px;
    font-size: var(--client-title-size);
    letter-spacing: 0;
}

.gateway-grid {
    display: grid;
    grid-template-columns: repeat(var(--gateway-cols), minmax(0, 1fr));
    gap: var(--grid-gap);
}

.gateway-card {
    display: grid;
    gap: 10px;
    min-height: var(--gateway-min-height);
    padding: var(--card-padding);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.gateway-card.red {
    background: var(--red-bg);
    border-color: #fecdca;
}

.gateway-card.orange {
    background: var(--orange-bg);
    border-color: #fedf89;
}

.gateway-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.gateway-subzone {
    margin: 0;
    font-size: var(--subzone-size);
    line-height: 1.2;
    letter-spacing: 0;
}

.gateway-zone {
    margin-top: 5px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.gateway-detail {
    color: var(--text);
    font-size: 15px;
    font-weight: 700;
    line-height: 1.25;
}

.gateway-detail.muted {
    color: var(--muted);
    font-size: 14px;
}

@media (min-width: 1440px) {
    :root {
        --page-max: 1360px;
        --summary-cols: 5;
        --gateway-cols: 4;
        --grid-gap: 16px;
    }
}

@media (min-width: 1920px) {
    :root {
        --page-max: 1760px;
        --page-gutter: 64px;
        --summary-cols: 5;
        --gateway-cols: 5;
        --grid-gap: 18px;
        --card-padding: 20px;
        --summary-min-height: 132px;
        --gateway-min-height: 190px;
        --h1-size: 34px;
        --h2-size: 28px;
        --client-title-size: 20px;
        --subzone-size: 22px;
        --body-size: 18px;
    }

    .page {
        padding: 44px 0;
    }

    .topbar {
        margin-bottom: 34px;
    }

    section {
        margin-top: 44px;
    }

    .summary-card strong {
        font-size: 38px;
    }

    .summary-card span,
    .gateway-zone,
    .gateway-detail.muted {
        font-size: 16px;
    }

    .gateway-detail {
        font-size: 18px;
    }

    .status-dot {
        width: 14px;
        height: 14px;
    }
}

@media (min-width: 2560px) {
    :root {
        --page-max: 2360px;
        --page-gutter: 96px;
        --gateway-cols: 6;
        --grid-gap: 22px;
        --card-padding: 24px;
        --summary-min-height: 150px;
        --gateway-min-height: 220px;
        --h1-size: 42px;
        --h2-size: 34px;
        --client-title-size: 24px;
        --subzone-size: 26px;
        --body-size: 20px;
    }

    .summary-card strong {
        font-size: 48px;
    }

    .summary-card span,
    .gateway-zone,
    .gateway-detail.muted {
        font-size: 18px;
    }

    .gateway-detail {
        font-size: 20px;
    }
}

@media (max-width: 860px) {
    :root {
        --summary-cols: 2;
        --gateway-cols: 2;
    }
}

@media (max-width: 560px) {
    :root {
        --summary-cols: 1;
        --gateway-cols: 1;
    }

    .page {
        width: min(100% - 24px, 1180px);
        padding: 22px 0;
    }

    .section-header {
        display: block;
    }

    .topbar {
        display: block;
    }

    .brand {
        display: block;
    }

    .brand-logo {
        width: min(100%, 280px);
        margin-bottom: 14px;
    }

    .nav-links {
        margin-top: 14px;
    }
}

/* Direct client index */
.client-index-page {
    background: #f0f3f8;
}

.client-index {
    --index-navy: #071b3b;
    --index-blue: #155eef;
    --index-red: #d92d20;
    --index-amber: #dc6803;
    --index-green: #039855;
    --index-border: #dfe5ee;
    width: min(1400px, calc(100% - 40px));
    padding: 22px 0 44px;
}

.index-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 22px 26px;
    border-radius: 16px;
    background: var(--index-navy);
    color: #ffffff;
}

.index-brand,
.index-header-actions {
    display: flex;
    align-items: center;
}

.index-brand {
    gap: 22px;
}

.index-brand img {
    display: block;
    width: 205px;
    height: auto;
}

.index-brand > div {
    padding-left: 22px;
    border-left: 1px solid rgba(255, 255, 255, 0.22);
}

.index-brand span,
.index-header-actions div span {
    display: block;
    color: #8fa8cf;
    font-size: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.index-brand h1 {
    margin-top: 3px;
    font-size: 25px;
}

.index-header-actions {
    gap: 10px;
}

.index-header-actions > div {
    display: grid;
    gap: 2px;
    margin-right: 8px;
    text-align: right;
}

.index-header-actions div strong {
    font-size: 12px;
}

.index-header-actions a {
    padding: 9px 13px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 8px;
    color: #ffffff;
    font-size: 12px;
    font-weight: 800;
    text-decoration: none;
}

.index-header-actions a:first-of-type {
    border-color: #3b82f6;
    background: var(--index-blue);
}

.index-api-warning {
    margin-top: 14px;
    padding: 13px 16px;
    border: 1px solid #fedf89;
    border-radius: 9px;
    background: #fffaeb;
    color: #93370d;
    font-size: 12px;
}

.client-index .index-overview {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-top: 18px;
}

.index-overview article {
    padding: 18px 20px;
    border: 1px solid var(--index-border);
    border-radius: 11px;
    background: #ffffff;
    box-shadow: 0 8px 22px rgba(16, 24, 40, 0.05);
}

.index-overview span {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
}

.index-overview strong {
    display: block;
    margin-top: 10px;
    color: #101828;
    font-size: 32px;
    line-height: 1;
}

.index-overview strong.index-danger {
    color: var(--index-red);
}

.index-overview strong.index-warning {
    color: var(--index-amber);
}

.client-directory {
    margin-top: 18px;
    overflow: hidden;
    border: 1px solid var(--index-border);
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 10px 30px rgba(16, 24, 40, 0.06);
}

.directory-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 22px 24px;
    border-bottom: 1px solid var(--index-border);
}

.directory-header > div > span {
    display: block;
    margin-bottom: 3px;
    color: var(--index-blue);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

.directory-header h2 {
    font-size: 20px;
}

.directory-header p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.directory-header > span {
    padding: 7px 11px;
    border: 1px solid #b2ccff;
    border-radius: 999px;
    background: #eff4ff;
    color: #1849a9;
    font-size: 11px;
    font-weight: 800;
}

.client-directory-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    padding: 20px;
    background: #f8fafc;
}

.directory-card {
    display: block;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.directory-card article {
    height: 100%;
    padding: 19px;
    border: 1px solid var(--index-border);
    border-top: 3px solid #98a2b3;
    border-radius: 11px;
    background: #ffffff;
    transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.directory-card.is-critical article {
    border-top-color: var(--index-red);
}

.directory-card.is-warning article {
    border-top-color: var(--index-amber);
}

.directory-card.is-operational article {
    border-top-color: #98a2b3;
}

.directory-card:hover article,
.directory-card:focus-visible article {
    border-color: #84adff;
    box-shadow: 0 12px 26px rgba(21, 94, 239, 0.12);
    transform: translateY(-3px);
}

.directory-card:focus-visible {
    border-radius: 11px;
    outline: 3px solid rgba(21, 94, 239, 0.2);
    outline-offset: 3px;
}

.directory-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.directory-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
}

.directory-status i {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.is-critical .directory-status i {
    background: var(--index-red);
    box-shadow: 0 0 0 4px #fee4e2;
}

.is-warning .directory-status i {
    background: var(--index-amber);
    box-shadow: 0 0 0 4px #ffead5;
}

.is-operational .directory-status i {
    background: #98a2b3;
    box-shadow: 0 0 0 4px #eaecf0;
}

.directory-arrow {
    color: #98a2b3;
    font-size: 20px;
}

.directory-card h3 {
    min-height: 46px;
    margin: 18px 0;
    color: #101828;
    font-size: 19px;
    line-height: 1.2;
}

.directory-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    border-top: 1px solid #eaecf0;
    border-bottom: 1px solid #eaecf0;
}

.directory-metrics > div {
    min-width: 0;
    padding: 14px 10px;
}

.directory-metrics > div:first-child {
    padding-left: 0;
}

.directory-metrics > div + div {
    border-left: 1px solid #eaecf0;
}

.directory-metrics span,
.directory-metrics small {
    display: block;
    color: var(--muted);
    font-size: 9px;
}

.directory-metrics strong {
    display: block;
    margin: 6px 0 4px;
    color: #101828;
    font-size: 25px;
    line-height: 1;
}

.metric-critical strong {
    color: var(--index-red);
}

.metric-warning strong {
    color: var(--index-amber);
}

.directory-open {
    display: block;
    margin-top: 16px;
    color: var(--index-blue);
    font-size: 11px;
    font-weight: 800;
}

@media (max-width: 1050px) {
    .client-directory-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .client-index {
        width: min(100% - 24px, 1400px);
    }

    .index-header-actions > div,
    .index-header-actions a:last-child {
        display: none;
    }

    .index-brand img {
        width: 155px;
    }

    .client-index .index-overview {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 560px) {
    .index-header {
        padding: 18px;
    }

    .index-brand img {
        width: 135px;
    }

    .index-brand > div {
        display: none;
    }

    .client-directory-grid {
        grid-template-columns: 1fr;
        padding: 14px;
    }

    .directory-header {
        align-items: flex-start;
        padding: 18px;
    }

    .directory-header > span {
        display: none;
    }
}

/* Almirall technical dashboard */
.almirall-page {
    background: #f0f3f8;
}

.almirall-dashboard {
    --tech-navy: #071b3b;
    --tech-blue: #155eef;
    --tech-red: #d92d20;
    --tech-amber: #dc6803;
    --tech-green: #039855;
    --tech-border: #dfe5ee;
    --tech-shadow: 0 10px 30px rgba(16, 24, 40, 0.06);
    width: min(1400px, calc(100% - 40px));
    padding: 22px 0 44px;
}

.tech-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 30px;
    padding: 22px 26px;
    border-radius: 16px 16px 0 0;
    background: var(--tech-navy);
    color: #ffffff;
}

.tech-brand,
.tech-header-meta {
    display: flex;
    align-items: center;
}

.tech-brand {
    gap: 22px;
}

.tech-brand a {
    display: inline-flex;
}

.tech-brand img {
    display: block;
    width: 205px;
    height: auto;
}

.tech-divider {
    width: 1px;
    height: 40px;
    background: rgba(255, 255, 255, 0.22);
}

.tech-overline,
.panel-overline {
    display: block;
    margin-bottom: 3px;
    color: #8fa8cf;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.tech-brand h1 {
    font-size: 25px;
}

.tech-header-meta {
    gap: 12px;
}

.tech-header-meta > div {
    display: grid;
    gap: 2px;
    margin-right: 10px;
    text-align: right;
}

.tech-header-meta > div span {
    color: #8fa8cf;
    font-size: 10px;
    text-transform: uppercase;
}

.tech-header-meta > div strong {
    font-size: 13px;
}

.tech-refresh,
.tech-back {
    padding: 9px 13px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 8px;
    color: #ffffff;
    font-size: 12px;
    font-weight: 800;
    text-decoration: none;
}

.tech-refresh {
    border-color: #3b82f6;
    background: #155eef;
}

.system-strip {
    display: grid;
    grid-template-columns: 1.2fr 0.7fr 0.7fr 1.4fr;
    align-items: center;
    min-height: 70px;
    padding: 0 26px;
    border: 1px solid var(--tech-border);
    border-top: 0;
    background: #ffffff;
}

.system-state,
.system-api {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 38px;
    padding-right: 20px;
    border-right: 1px solid var(--tech-border);
}

.system-state div,
.system-api {
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 1px;
}

.system-state span:not(.system-dot),
.system-api span {
    color: var(--muted);
    font-size: 10px;
    text-transform: uppercase;
}

.system-state strong,
.system-api strong {
    font-size: 13px;
}

.system-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
}

.status-critical .system-dot {
    background: var(--tech-red);
    box-shadow: 0 0 0 5px #fee4e2;
}

.status-operational .system-dot {
    background: var(--tech-green);
    box-shadow: 0 0 0 5px #dcfae6;
}

.status-warning .system-dot {
    background: var(--tech-amber);
    box-shadow: 0 0 0 5px #ffead5;
}

.status-unknown .system-dot {
    background: #667085;
    box-shadow: 0 0 0 5px #eaecf0;
}

.api-ok {
    color: var(--tech-green);
}

.api-error,
.kpi-footer .kpi-critical {
    color: var(--tech-red);
}

.system-legend,
.severity-summary {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 16px;
    color: var(--muted);
    font-size: 11px;
}

.system-legend i,
.severity-summary i {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 6px;
    border-radius: 50%;
}

.legend-critical {
    background: var(--tech-red);
}

.legend-warning {
    background: #f79009;
}

.legend-unknown {
    background: #98a2b3;
}

.tech-kpis {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-top: 18px;
}

.tech-kpi {
    --kpi-status-color: var(--tech-blue);
    --kpi-status-bg: #eff4ff;
    min-width: 0;
    padding: 20px;
    border: 1px solid var(--tech-border);
    border-radius: 12px;
    background: #ffffff;
    box-shadow: var(--tech-shadow);
}

.tech-kpi.kpi-critical {
    --kpi-status-color: var(--tech-red);
    --kpi-status-bg: #fef3f2;
    border-top: 3px solid var(--tech-red);
    padding-top: 18px;
}

.tech-kpi.kpi-warning {
    --kpi-status-color: var(--tech-amber);
    --kpi-status-bg: #fffaeb;
    border-top: 3px solid var(--tech-amber);
    padding-top: 18px;
}

.tech-kpi.kpi-operational {
    --kpi-status-color: var(--tech-blue);
    --kpi-status-bg: #eff4ff;
}

.kpi-topline,
.kpi-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.kpi-topline > span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.kpi-icon {
    position: relative;
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
    border-radius: 8px;
    background: var(--kpi-status-bg);
    color: var(--kpi-status-color);
}

.kpi-icon.icon-critical {
    background: #fef3f2;
    color: var(--tech-red);
}

.kpi-icon.icon-warning {
    background: #fffaeb;
    color: var(--tech-amber);
}

.kpi-icon.icon-operational {
    background: #eff4ff;
    color: var(--tech-blue);
}

.kpi-icon::before,
.kpi-icon::after {
    content: "";
    position: absolute;
}

.icon-gateway::before {
    inset: 8px 6px;
    border: 2px solid currentColor;
    border-radius: 3px;
}

.icon-gateway::after {
    left: 10px;
    bottom: 5px;
    width: 10px;
    border-top: 2px solid currentColor;
}

.icon-time::before {
    inset: 6px;
    border: 2px solid currentColor;
    border-radius: 50%;
}

.icon-time::after {
    left: 14px;
    top: 10px;
    width: 5px;
    height: 6px;
    border-left: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
}

.icon-tags::before {
    inset: 7px;
    border: 2px solid var(--tech-blue);
    border-radius: 4px;
    transform: rotate(45deg);
}

.icon-battery::before {
    left: 6px;
    top: 9px;
    width: 16px;
    height: 10px;
    border: 2px solid currentColor;
    border-radius: 2px;
}

.icon-battery::after {
    right: 4px;
    top: 12px;
    width: 3px;
    height: 6px;
    border-radius: 0 2px 2px 0;
    background: currentColor;
}

.tech-kpi > strong {
    display: block;
    margin: 17px 0 13px;
    color: #101828;
    font-size: 36px;
    line-height: 1;
}

.tech-kpi > strong small {
    color: var(--muted);
    font-size: 16px;
}

.kpi-footer {
    justify-content: flex-start;
    color: var(--muted);
    font-size: 11px;
}

.kpi-footer span + span::before {
    content: "/";
    margin-right: 8px;
    color: #d0d5dd;
}

.tech-panel {
    margin-top: 18px;
    overflow: hidden;
    border: 1px solid var(--tech-border);
    border-radius: 12px;
    background: #ffffff;
    box-shadow: var(--tech-shadow);
}

.tech-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 22px 24px;
    border-bottom: 1px solid var(--tech-border);
}

.panel-overline {
    color: var(--tech-blue);
}

.tech-panel-header h2 {
    font-size: 20px;
}

.tech-panel-header p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.panel-total {
    padding: 7px 11px;
    border: 1px solid #b2ccff;
    border-radius: 999px;
    background: #eff4ff;
    color: #1849a9;
    font-size: 11px;
    font-weight: 800;
}

.battery-technical-grid {
    display: grid;
    grid-template-columns: 340px 1fr;
    min-height: 310px;
}

.battery-chart-wrap {
    display: grid;
    place-items: center;
    border-right: 1px solid var(--tech-border);
    background: #fbfcfe;
}

.battery-donut {
    display: grid;
    width: 205px;
    height: 205px;
    place-items: center;
    border-radius: 50%;
    background: conic-gradient(
        #12b76a 0 calc(var(--healthy) * 1%),
        #fdb022 calc(var(--healthy) * 1%) calc((var(--healthy) + var(--low-50)) * 1%),
        #f79009 calc((var(--healthy) + var(--low-50)) * 1%) calc((var(--healthy) + var(--low-50) + var(--low-30)) * 1%),
        #d92d20 calc((var(--healthy) + var(--low-50) + var(--low-30)) * 1%) 100%
    );
}

.battery-donut::before {
    content: "";
    grid-area: 1 / 1;
    width: 145px;
    height: 145px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 0 0 1px #eef1f5;
}

.battery-donut > div {
    z-index: 1;
    grid-area: 1 / 1;
    text-align: center;
}

.battery-donut strong,
.battery-donut span {
    display: block;
}

.battery-donut strong {
    color: #101828;
    font-size: 36px;
}

.battery-donut span {
    margin-top: 4px;
    color: var(--muted);
    font-size: 11px;
}

.battery-distribution {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: center;
    gap: 12px;
    padding: 28px;
}

.battery-stat {
    display: grid;
    grid-template-columns: 8px 1fr auto;
    align-items: center;
    gap: 12px;
    min-height: 94px;
    padding: 16px;
    border: 1px solid var(--tech-border);
    border-radius: 10px;
}

.battery-swatch {
    width: 5px;
    height: 42px;
    border-radius: 999px;
}

.battery-stat div {
    display: grid;
    gap: 3px;
}

.battery-stat div strong {
    font-size: 14px;
}

.battery-stat small,
.battery-stat em {
    color: var(--muted);
    font-size: 10px;
    font-style: normal;
}

.battery-stat > b {
    font-size: 27px;
}

.battery-stat > em {
    grid-column: 3;
    text-align: right;
}

.battery-critical .battery-swatch {
    background: var(--tech-red);
}

.battery-warning .battery-swatch {
    background: #f79009;
}

.battery-watch .battery-swatch {
    background: #fdb022;
}

.battery-healthy .battery-swatch {
    background: #12b76a;
}

.severity-summary {
    font-weight: 700;
}

.tech-table-wrap {
    overflow-x: auto;
}

.tech-table {
    min-width: 920px;
}

.tech-table th {
    padding: 12px 18px;
    background: #f8fafc;
    color: #475467;
    font-size: 10px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.tech-table td {
    padding: 15px 18px;
    color: #344054;
    font-size: 12px;
}

.tech-table tbody tr:hover {
    background: #f9fbff;
}

.align-right {
    text-align: right;
}

.severity-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-width: 78px;
    padding: 5px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 800;
}

.severity-badge i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
}

.severity-badge.critical {
    background: #fef3f2;
    color: #b42318;
}

.severity-badge.critical i {
    background: var(--tech-red);
}

.severity-badge.warning {
    background: #fffaeb;
    color: #b54708;
}

.severity-badge.warning i {
    background: #f79009;
}

.severity-badge.unknown {
    background: #f2f4f7;
    color: #475467;
}

.severity-badge.unknown i {
    background: #98a2b3;
}

.gateway-id {
    color: #101828;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 11px;
}

.offline-value.critical {
    color: var(--tech-red);
}

.offline-value.warning {
    color: var(--tech-amber);
}

.offline-value.unknown {
    color: #667085;
}

.tech-alert,
.tech-empty {
    margin: 24px;
    padding: 16px 18px;
    border-radius: 8px;
    font-size: 13px;
}

.tech-alert {
    border: 1px solid #fecdca;
    background: #fef3f2;
    color: #b42318;
}

.tech-empty {
    border: 1px solid #abefc6;
    background: #ecfdf3;
    color: #344054;
}

.tech-empty span {
    margin-right: 8px;
    font-weight: 800;
}

@media (max-width: 1050px) {
    .tech-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .system-strip {
        grid-template-columns: repeat(3, 1fr);
        gap: 14px;
        padding-top: 14px;
        padding-bottom: 14px;
    }

    .system-legend {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }

    .battery-technical-grid {
        grid-template-columns: 280px 1fr;
    }
}

@media (max-width: 760px) {
    .almirall-dashboard {
        width: min(100% - 24px, 1400px);
    }

    .tech-header {
        align-items: flex-start;
    }

    .tech-header-meta > div,
    .tech-back {
        display: none;
    }

    .tech-brand img {
        width: 155px;
    }

    .tech-divider {
        display: none;
    }

    .system-strip {
        grid-template-columns: 1fr 1fr;
    }

    .system-state {
        grid-column: 1 / -1;
    }

    .system-state,
    .system-api {
        border-right: 0;
    }

    .battery-technical-grid {
        grid-template-columns: 1fr;
    }

    .battery-chart-wrap {
        min-height: 270px;
        border-right: 0;
        border-bottom: 1px solid var(--tech-border);
    }

    .battery-distribution {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 520px) {
    .tech-header {
        padding: 18px;
    }

    .tech-brand img {
        width: 135px;
    }

    .tech-overline,
    .tech-brand h1 {
        display: none;
    }

    .tech-refresh {
        padding: 8px 10px;
        font-size: 11px;
    }

    .tech-kpis {
        grid-template-columns: 1fr;
    }

    .tech-panel-header {
        align-items: flex-start;
        padding: 18px;
    }

    .panel-total,
    .severity-summary {
        display: none;
    }

    .battery-distribution {
        padding: 18px;
    }
}
