html, body {
    margin: 0;
    min-height: 100%;
    background: #f5f6fa;
    color: #172033;
    font-family: Inter, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
a { color: inherit; }
.quick-link { display: block; color: inherit; text-decoration: none; }
.quick-link .mud-paper { height: 100%; transition: transform .15s ease, border-color .15s ease; }
.quick-link:hover .mud-paper { transform: translateY(-2px); border-color: #cfcaf8; }

.app-bar {
    border-bottom: 1px solid rgba(255, 255, 255, .06);
}

.app-drawer {
    border-right: 0 !important;
}

.main-content {
    min-height: 100vh;
    padding-top: 64px;
}

.content-shell {
    width: min(1480px, 100%);
    margin: 0 auto;
    padding: 2rem 2.25rem 3rem;
}

.content-shell h1[tabindex="-1"]:focus {
    outline: none;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.25rem;
    margin-bottom: 1.8rem;
}

.page-header h1 {
    margin: 0;
    font-size: 1.95rem;
    line-height: 1.2;
    letter-spacing: -.04em;
}

.page-header p {
    margin: .45rem 0 0;
    color: #687386;
    max-width: 690px;
}

.eyebrow {
    display: block;
    margin-bottom: .35rem;
    color: #7165e8;
    font-size: .7rem;
    font-weight: 800;
    letter-spacing: .13em;
    text-transform: uppercase;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.metric-card {
    position: relative;
    min-height: 145px;
    overflow: hidden;
    border: 1px solid #e8ebf1;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 7px 22px rgba(16, 24, 38, .035);
    padding: 1.25rem;
}

.metric-card::after {
    content: "";
    position: absolute;
    width: 105px;
    height: 105px;
    border-radius: 50%;
    right: -42px;
    top: -42px;
    background: var(--metric-tint, rgba(113, 101, 232, .1));
}

.metric-icon {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    color: var(--metric-color, #7165e8);
    background: var(--metric-tint, rgba(113, 101, 232, .1));
}

.metric-value {
    margin-top: .8rem;
    font-size: 1.75rem;
    font-weight: 750;
    line-height: 1;
}

.metric-label {
    margin-top: .45rem;
    color: #687386;
    font-size: .78rem;
}

.panel {
    border: 1px solid #e8ebf1;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 7px 22px rgba(16, 24, 38, .035);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1.15rem 1.25rem;
    border-bottom: 1px solid #eef0f4;
}

.panel-header h2, .panel-header h3 {
    margin: 0;
    font-size: 1rem;
}

.panel-body { padding: 1.25rem; }

.two-column {
    display: grid;
    grid-template-columns: minmax(0, 1.65fr) minmax(280px, .85fr);
    gap: 1.25rem;
}

.home-section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: .85rem;
}
.home-section-heading h2 { margin: 0; font-size: 1rem; font-weight: 650; letter-spacing: 0; }
.home-period { color: #687386; font-size: .8rem; }
.home-overview .metric-card { border-radius: 8px; min-height: 125px; box-shadow: none; }
.home-overview .metric-card::after { display: none; }
.home-overview .metric-icon { border-radius: 6px; }
.home-module-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin: 0; padding: 0; list-style: none; }
.home-module-tile { display: flex; flex-direction: column; min-width: 0; background: #fff; border: 1px solid #e8ebf1; border-radius: 8px; overflow: hidden; }
.home-module-tile:hover { border-color: #cfcaf8; }
.home-module-link { display: flex; align-items: center; gap: .85rem; flex: 1; min-height: 100px; padding: 1.15rem; text-decoration: none; }
.home-module-link > .mud-icon-root { flex-shrink: 0; }
.home-module-link > .mud-icon-root:last-child { width: 18px; height: 18px; color: #687386; }
.home-module-content { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.home-module-content strong { display: block; font-size: .95rem; font-weight: 650; }
.home-module-content span { display: block; margin-top: .4rem; color: #687386; font-size: .8rem; }
.home-module-actions { display: flex; flex-wrap: wrap; gap: 1rem; border-top: 1px solid #e8ebf1; padding: .75rem 1.15rem; }
.home-module-actions a { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; text-decoration: none; }
.home-module-actions a:hover { color: #5347c5; }
.home-module-link:focus-visible, .home-module-actions a:focus-visible { outline: 2px solid #7165e8; outline-offset: -2px; }
@media (max-width: 650px) {
    .home-overview .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
    .home-overview .metric-card { padding: 1rem; }
    .home-overview .metric-value { font-size: 1.5rem; }
    .home-module-grid { grid-template-columns: 1fr; }
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    padding: .8rem 1rem;
    color: #7a8495;
    background: #fafbfc;
    border-bottom: 1px solid #e9ecf1;
    font-size: .68rem;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.data-table td {
    padding: .9rem 1rem;
    border-bottom: 1px solid #eef0f4;
    font-size: .84rem;
    vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #fafaff; }

.dashboard-list {
    margin: 0;
    padding: 0;
    list-style: none;
    background: #fff;
    border-top: 1px solid #e8ebf1;
}

.dashboard-list > li { border-bottom: 1px solid #e8ebf1; }

.dashboard-list-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-height: 72px;
    padding: 1rem;
    text-decoration: none;
}

a.dashboard-list-row:hover { background: #fafaff; }
a.dashboard-list-row:focus-visible { outline: 2px solid #7165e8; outline-offset: -2px; }
.dashboard-list-row > .mud-icon-root { flex-shrink: 0; }
.dashboard-list-content { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.dashboard-list-content strong { display: block; font-size: .95rem; font-weight: 650; }
.dashboard-list-content small { display: block; margin-top: .2rem; color: #687386; }
.dashboard-list-content .dashboard-list-status { color: #a86a0a; }

.status-chip {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .28rem .55rem;
    border-radius: 999px;
    background: #eff1f5;
    color: #5f6979;
    font-size: .69rem;
    font-weight: 700;
}

.status-chip::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.status-success { color: #15815a; background: #e9f7f1; }
.status-warning { color: #a86a0a; background: #fff5df; }
.status-error { color: #b1374c; background: #fcecef; }
.status-info { color: #5549c6; background: #efedff; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: .4rem;
}

.form-field.full { grid-column: 1 / -1; }
.form-field label { color: #4e596a; font-size: .74rem; font-weight: 700; }
.form-field input, .form-field select, .form-field textarea {
    width: 100%;
    min-height: 42px;
    border: 1px solid #dfe3ea;
    border-radius: 10px;
    padding: .65rem .75rem;
    color: #172033;
    background: #fff;
    outline: none;
}

#export-interval:disabled, #chart-window:disabled {
    background: #f1f3f6;
    color: #7c8696;
    cursor: not-allowed;
}

.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
    border-color: #7165e8;
    box-shadow: 0 0 0 3px rgba(113, 101, 232, .1);
}

.validation-message { color: #c53c54; font-size: .72rem; }
.form-actions { display: flex; justify-content: flex-end; gap: .7rem; margin-top: 1.2rem; }

.device-toolbar {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
}

.device-toolbar.compact { gap: .5rem; }

.device-list-controls {
    display: grid;
    grid-template-columns: minmax(220px, 1.5fr) repeat(2, minmax(170px, .75fr));
    gap: 1rem;
    align-items: end;
}

.device-list-controls.compact {
    grid-template-columns: minmax(220px, 1fr);
}

.device-export-controls {
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    gap: 1rem;
    align-items: end;
}

.chart-controls {
    grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.ticket-list-controls {
    display: grid;
    grid-template-columns: minmax(240px, 1.5fr) minmax(180px, .5fr);
    gap: 1rem;
}

.ticket-table strong {
    display: block;
    max-width: 520px;
    overflow-wrap: anywhere;
}

.ticket-modal {
    width: min(1180px, 100%);
}

.ticket-modal-body {
    padding: 1.25rem;
}

.ticket-detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
    gap: 1.5rem;
    align-items: start;
}

.ticket-section-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: .85rem;
}

.ticket-section-heading h3 {
    margin: 0;
    font-size: .95rem;
}

.ticket-article {
    padding: 1rem 0;
    border-top: 1px solid #eef0f4;
}

.ticket-article:first-of-type {
    border-top: 0;
}

.ticket-article-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .45rem .75rem;
    color: #7c8696;
    font-size: .72rem;
}

.ticket-article-meta strong {
    color: #303a4c;
    font-size: .8rem;
}

.ticket-article-body {
    margin-top: .65rem;
    color: #374255;
    font-size: .84rem;
    line-height: 1.55;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.ticket-comment-box {
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid #e8ebf1;
}

.ticket-checkbox {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    margin-top: .75rem;
    color: #4e596a;
    font-size: .76rem;
}

.ticket-actions {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: .85rem;
    padding-left: 1.5rem;
    border-left: 1px solid #eef0f4;
}

.ticket-actions hr {
    width: 100%;
    margin: .25rem 0;
    border: 0;
    border-top: 1px solid #eef0f4;
}

.ticket-facts {
    display: grid;
    gap: .75rem;
    margin-bottom: .35rem;
}

.ticket-facts div {
    display: flex;
    flex-direction: column;
    gap: .18rem;
}

.ticket-facts span {
    color: #7c8696;
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.ticket-facts strong {
    color: #303a4c;
    font-size: .82rem;
    overflow-wrap: anywhere;
}

.table-scroll {
    overflow-x: auto;
}

.table-scroll-tall {
    max-height: 420px;
    overflow: auto;
    border: 1px solid #eef0f4;
    border-radius: 14px;
}

.device-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: rgba(18, 24, 38, .48);
    backdrop-filter: blur(4px);
}

.device-modal {
    width: min(1360px, 100%);
    max-height: min(90dvh, 980px);
    display: flex;
    flex-direction: column;
    border-radius: 8px;
    overflow: hidden;
}

.device-modal > .panel-header { flex-shrink: 0; flex-wrap: wrap; background: #f5f7fa; }
.device-modal .panel-header h2 { overflow-wrap: anywhere; }
.device-modal-body {
    min-height: 0;
    padding: 0;
    overflow: auto;
}

.device-summary.mud-grid { width: 100%; margin: 0; padding: .5rem 1rem 1rem; background: #f5f7fa; }
.device-section { --section-accent: #197f8b; --section-tint: #eef7f7; padding: 1.25rem; border-top: 1px solid #dce4eb; }
.device-section-heading { display: flex; align-items: center; gap: .5rem; margin: 0 0 1rem; color: var(--section-accent); font-size: 1rem; font-weight: 600; letter-spacing: 0; }
.device-section-heading .mud-icon-root { width: 20px; height: 20px; flex-shrink: 0; }
.device-connections { --section-accent: #936213; --section-tint: #fcf6e8; background: #fffdf7; border-top: 3px solid #d5ad53; }
.device-connections .data-table th { background: var(--section-tint); color: #77521b; }
.device-modal code, .device-modal td { overflow-wrap: anywhere; }
.mqtt-credentials { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .3rem .75rem; margin: .5rem 0 0; }
.mqtt-credentials dt { color: #687386; font-weight: 500; white-space: nowrap; }
.mqtt-credentials dd { margin: 0; min-height: 1.2em; }
.mqtt-credential-editor { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid #e2d8bf; }
.device-values { border-top: 3px solid #197f8b; }
.device-subsection-heading { display: flex; justify-content: space-between; align-items: center; margin: 0 0 .75rem; padding: .6rem .75rem; color: #156571; background: #eef7f7; font-size: .875rem; font-weight: 600; }
.device-subsection-heading span { font-variant-numeric: tabular-nums; }
.device-telemetry .data-table th { color: #156571; background: #f4fafa; }
.device-attributes .device-subsection-heading { color: #9b465c; background: #faf0f3; }
.device-attributes .data-table th { color: #8b4e60; background: #fcf6f8; }
.device-chart { border-top: 3px solid #4b75ad; background: #f8fafc; }
.device-chart .device-section-heading { color: #345f92; margin-bottom: 0; }
.device-chart .panel-body { padding: 1rem 0 0; }
.telemetry-chart-frame, .telemetry-chart-empty { width: 100%; min-height: 320px; margin-top: 1rem; background: #fff; }
.telemetry-chart-frame { min-width: 0; overflow: hidden; }
.telemetry-chart-empty { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: .75rem; color: #687386; }

.telemetry-picker { width: min(560px, 100%); max-height: 90dvh; display: flex; flex-direction: column; border-radius: 8px; }
.telemetry-picker-body { min-height: 0; overflow: auto; }
.telemetry-key-list { max-height: 45dvh; overflow: auto; }
.telemetry-key-option { display: flex; align-items: center; gap: .75rem; padding: .7rem .5rem; border-bottom: 1px solid #e4e8ef; cursor: pointer; }
.telemetry-key-option span { overflow-wrap: anywhere; min-width: 0; }
.telemetry-key-option input { width: 16px; height: 16px; flex-shrink: 0; accent-color: #197f8b; }
.telemetry-key-select-all { background: #eef7f7; font-weight: 600; }
.telemetry-picker-footer { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: .5rem; padding: 1rem; border-top: 1px solid #dce4eb; }

.chart-header {
    padding-left: 0;
    padding-right: 0;
}

.empty-state {
    display: flex;
    min-height: 270px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: .75rem;
    text-align: center;
    border: 1px dashed #dce0e8;
    border-radius: 16px !important;
    background: #fff;
}

.empty-state-short {
    min-height: 180px;
}

.audit-row {
    display: grid;
    grid-template-columns: 38px 1fr auto;
    align-items: center;
    gap: .8rem;
    padding: .8rem 0;
    border-bottom: 1px solid #eef0f4;
}

.audit-row:last-child { border-bottom: 0; }
.audit-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; color: #7165e8; background: #f0eeff; }
.audit-copy { display: flex; flex-direction: column; font-size: .8rem; }
.audit-copy small, .muted { color: #7c8696; }
.audit-time { color: #8b94a3; font-size: .7rem; white-space: nowrap; }

.dashboard-frame, #superset-container {
    width: 100%;
    min-height: calc(100vh - 205px);
    border: 0;
    border-radius: 14px;
    background: #fff;
}

#superset-container iframe { width: 100%; min-height: calc(100vh - 205px); border: 0; }

.page-header.chatbot-header {
    flex-direction: row;
    align-items: center;
    gap: .75rem;
}

.chatbot-header h1 { letter-spacing: 0; }
.chatbot-header .mud-icon-button { flex-shrink: 0; }

.chatbot-frame {
    display: block;
    height: calc(100dvh - 205px);
    min-height: 480px;
    border-radius: 0;
}

.inori-nav .mud-nav-link {
    margin: .13rem .7rem;
    border-radius: 10px;
}

.inori-nav .mud-nav-link.active {
    color: #fff !important;
    background: rgba(113, 101, 232, .25) !important;
}

.inori-nav .mud-nav-link:hover { background: rgba(255, 255, 255, .055); }

#blazor-error-ui {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    padding: 1rem;
    color: #fff;
    background: #a93148;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
}

#blazor-error-ui .dismiss { cursor: pointer; float: right; }

@media (max-width: 1000px) {
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .two-column { grid-template-columns: 1fr; }
    .device-list-controls, .chart-controls { grid-template-columns: 1fr 1fr; }
    .device-export-controls { grid-template-columns: 1fr 1fr; }
    .ticket-detail-grid { grid-template-columns: 1fr; }
    .ticket-actions { position: static; padding: 1.25rem 0 0; border-top: 1px solid #eef0f4; border-left: 0; }
}

@media (max-width: 650px) {
    .content-shell { padding: 1.35rem 1rem 2rem; }
    .page-header { flex-direction: column; }
    .metric-grid, .form-grid { grid-template-columns: 1fr; }
    .device-list-controls, .chart-controls { grid-template-columns: 1fr; }
    .device-export-controls { grid-template-columns: 1fr; }
    .ticket-list-controls { grid-template-columns: 1fr; }
    .form-field.full { grid-column: auto; }
    .data-table { min-width: 650px; }
    .panel { overflow-x: auto; }
    .device-modal-backdrop { padding: .5rem; }
    .device-modal .panel-header { padding: .75rem; gap: .5rem; }
    .device-modal .device-section { padding: .85rem; }
    .device-modal .device-list-controls.compact { width: 100%; grid-template-columns: minmax(0, 1fr); }
    .device-modal .data-table { min-width: 520px; }
    .telemetry-chart-frame, .telemetry-chart-empty { min-height: 320px; }
}
