:root {
    color-scheme: light;
    --bg: #f5f7fa;
    --surface: #ffffff;
    --surface-2: #eef2f6;
    --text: #18202a;
    --muted: #667384;
    --border: #d8e0e8;
    --accent: #1e5b8f;
    --accent-strong: #17496f;
    --ok: #107c41;
    --warn: #a46400;
    --danger: #a93737;
    --shadow: 0 18px 40px rgba(35, 49, 66, 0.08);
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0f141a;
    --surface: #171e26;
    --surface-2: #202a35;
    --text: #eef3f7;
    --muted: #a2afbd;
    --border: #2d3a47;
    --accent: #6da9d8;
    --accent-strong: #9cc7e7;
    --ok: #50c878;
    --warn: #d6a044;
    --danger: #e06d6d;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.32);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

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

.auth-flash {
    position: fixed;
    top: 18px;
    left: 50%;
    z-index: 30;
    width: min(90vw, 460px);
    transform: translateX(-50%);
}

.auth-flash .notice {
    margin: 0;
    text-align: center;
}

.auth-card {
    width: min(100%, 440px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 32px;
}

.auth-card.wide {
    width: min(100%, 620px);
}

.auth-heading {
    display: grid;
    gap: 8px;
    margin-bottom: 24px;
}

.auth-heading h1,
.page-header h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.15;
}

.auth-heading p,
.page-header p,
.muted {
    margin: 0;
    color: var(--muted);
}

.brand-mark {
    width: 38px;
    height: 34px;
    display: inline-grid;
    place-items: center;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
}

.brand-mark.large {
    width: 56px;
    height: 48px;
    font-size: 22px;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 22px;
    border-right: 1px solid var(--border);
    background: var(--surface);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand small,
.user-block small {
    display: block;
    color: var(--muted);
}

.nav-list {
    display: grid;
    gap: 6px;
}

.nav-list a,
.logout,
.quick-switch a,
button,
.secondary {
    border-radius: 8px;
}

.nav-list a {
    padding: 10px 12px;
    color: var(--muted);
}

.nav-list a.active,
.nav-list a:hover {
    color: var(--text);
    background: var(--surface-2);
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 12px;
}

.logout {
    padding: 10px 12px;
    border: 1px solid var(--border);
    text-align: center;
}

.content {
    min-width: 0;
    padding: 32px;
}

.top-tools {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 18px;
}

.top-tools a {
    display: inline-grid;
    place-items: center;
    min-width: 42px;
    min-height: 38px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--muted);
    background: var(--surface);
}

.top-tools a:hover,
.top-tools .help-link {
    color: var(--accent);
    border-color: var(--accent);
}

.flash-stack {
    display: grid;
    gap: 10px;
    margin: 0 0 18px;
}

.flash-stack .notice {
    margin: 0;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
}

.section-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 14px;
}

.section-head h2,
.section-head p {
    margin-top: 0;
}

.quick-switch,
.auth-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.auth-options {
    justify-content: center;
    margin-top: 18px;
}

.auth-pricing-link {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    justify-content: center;
    margin-top: 14px;
}

.auth-pricing-link a {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    text-align: center;
    color: var(--accent);
    background: var(--surface-2);
}

.auth-pricing-link a:nth-child(2) {
    color: #fff;
    border-color: var(--accent);
    background: var(--accent);
}

.auth-note {
    margin-top: 14px;
    text-align: center;
    font-size: 13px;
}

.quick-switch a,
.auth-options a {
    padding: 7px 10px;
    border: 1px solid var(--border);
    color: var(--muted);
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.metric,
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.metric {
    min-height: 108px;
    padding: 18px;
    display: grid;
    align-content: space-between;
}

.metric span {
    color: var(--muted);
}

.metric strong {
    font-size: 26px;
}

.license-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.license-grid .metric {
    min-height: 150px;
}

.license-grid .metric p {
    margin: 0;
}

.manual-intro {
    display: grid;
    gap: 10px;
}

.manual-intro p,
.manual-section li {
    margin: 0;
}

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

.manual-section {
    margin-bottom: 0;
}

.manual-section ul {
    display: grid;
    gap: 10px;
    margin: 0;
    padding-left: 20px;
}

.manual-section li::marker {
    color: var(--accent);
}

.panel {
    padding: 20px;
    margin-bottom: 18px;
}

.panel h2 {
    margin: 0 0 14px;
    font-size: 18px;
}

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

.table-panel {
    padding: 0;
    overflow: hidden;
}

.table-panel h2 {
    padding: 18px 20px 0;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

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

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

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    white-space: nowrap;
}

.badge.ok {
    color: var(--ok);
}

.badge.warn {
    color: var(--warn);
}

.actions {
    white-space: nowrap;
}

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    margin: 0 2px 4px 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
}

.icon-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.icon-btn.danger {
    color: var(--danger);
}

button.icon-btn {
    display: inline-grid;
    min-width: 30px;
    min-height: 30px;
    width: 30px;
    height: 30px;
    padding: 0;
    border-color: var(--border);
    background: var(--surface-2);
    color: var(--text);
}

button.icon-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.modal {
    display: none;
}

.modal:target {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 18px;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(8, 13, 20, 0.55);
}

.modal-card {
    position: relative;
    z-index: 21;
    width: min(100%, 560px);
    max-height: min(86vh, 760px);
    overflow: auto;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.modal-card.wide {
    width: min(100%, 860px);
}

.pricing-modal .modal-card {
    width: min(100%, 1080px);
    max-height: calc(100vh - 48px);
    overflow-x: hidden;
}

.modal-card header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.modal-card header h2 {
    margin: 0;
    font-size: 18px;
}

.modal-card header a {
    color: var(--muted);
}

.pricing-card header {
    align-items: flex-start;
}

.pricing-header-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.pricing-card header p {
    margin: 4px 0 0;
}

.pricing-section {
    margin-top: 18px;
}

.pricing-section h3 {
    margin: 0 0 10px;
    font-size: 14px;
    letter-spacing: 0;
    color: var(--accent);
    text-transform: uppercase;
}

.pricing-grid {
    display: grid;
    gap: 12px;
}

.pricing-grid.three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.pricing-grid.two {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
    align-items: start;
    margin-top: 6px;
}

.pricing-box {
    min-width: 0;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
}

.pricing-box.highlight {
    border-color: var(--accent);
}

.pricing-box strong {
    display: block;
    margin-bottom: 6px;
}

.pricing-box span {
    display: block;
    margin: 8px 0;
    color: var(--accent);
    font-size: 26px;
    line-height: 1.1;
    font-weight: 700;
}

.pricing-box ul {
    margin: 12px 0 0;
    padding-left: 18px;
    color: var(--muted);
}

.pricing-box li {
    margin: 5px 0;
}

.pricing-box p {
    margin: 8px 0 0;
}

.pricing-formula {
    margin-top: 12px;
}

.pricing-formula strong,
.pricing-formula span {
    display: block;
}

.pricing-formula span {
    margin-top: 8px;
    color: var(--muted);
}

.pricing-table-wrap {
    overflow-x: visible;
}

.pricing-table {
    width: 100%;
    min-width: 0 !important;
    table-layout: fixed;
}

.pricing-table th,
.pricing-table td {
    padding: 10px 12px;
    overflow-wrap: anywhere;
}

.pricing-fee-table th:first-child,
.pricing-fee-table td:first-child {
    width: 34%;
}

.pricing-storage-table td:first-child {
    width: 28%;
}

.form-grid {
    display: grid;
    gap: 14px;
}

.compact-form {
    grid-template-columns: minmax(180px, 280px) auto;
    align-items: end;
    margin-bottom: 14px;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
}

input,
select,
textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}

textarea {
    min-height: 110px;
    resize: vertical;
}

.code-editor {
    min-height: 360px;
    overflow: auto;
    white-space: pre;
    font-family: Consolas, "Courier New", monospace;
    font-size: 13px;
    line-height: 1.45;
    tab-size: 4;
}

hr {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 18px 0;
}

.checkbox-line {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-line input {
    width: auto;
}

.check-list {
    display: grid;
    gap: 8px;
    max-height: 320px;
    overflow: auto;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
}

button,
.secondary {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-height: 42px;
    padding: 10px 14px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    cursor: pointer;
}

.secondary {
    background: transparent;
    color: var(--danger);
    border-color: var(--danger);
}

.secret-box {
    display: grid;
    gap: 8px;
    padding: 14px;
    margin-bottom: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
}

.secret-box code {
    overflow-wrap: anywhere;
    font-size: 18px;
}

.qr-box {
    display: grid;
    place-items: center;
    margin: 0 0 16px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

.qr-box img {
    display: block;
    width: 220px;
    height: 220px;
}

.event-list {
    display: grid;
    gap: 10px;
}

.report-filters {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: end;
}

.legend-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin: 0 0 16px;
    color: var(--muted);
}

.legend-row span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.legend-row i {
    width: 18px;
    height: 4px;
    border-radius: 999px;
    display: inline-block;
}

.legend-power,
.report-chart .power-line {
    background: var(--accent);
    stroke: var(--accent);
}

.legend-wind,
.report-chart .wind-line {
    background: var(--ok);
    stroke: var(--ok);
}

.legend-demand-on,
.report-chart .demand-on {
    background: var(--ok);
    fill: var(--ok);
}

.legend-demand-off,
.report-chart .demand-off {
    background: var(--danger);
    fill: var(--danger);
}

.report-chart {
    width: 100%;
    height: auto;
    margin: 8px 0 18px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
}

.report-chart line {
    stroke: var(--border);
    stroke-width: 1;
}

.report-chart .grid {
    opacity: 0.7;
}

.report-chart polyline {
    fill: none;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.report-chart text {
    fill: var(--muted);
    font-size: 12px;
}

.event-list div,
.definition-list {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
}

.event-list span,
.definition-list dt {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.definition-list {
    display: grid;
    grid-template-columns: 140px minmax(0, 1fr);
    gap: 10px;
}

.definition-list dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.notice {
    margin: 0 0 14px;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.notice-error {
    border-color: var(--danger);
    color: var(--danger);
}

.notice-success {
    border-color: var(--ok);
    color: var(--ok);
}

.notice-warning {
    border-color: var(--warn);
    color: var(--warn);
}

.inline-form {
    display: inline;
}

.link-button {
    min-height: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    text-decoration: underline;
}

.pager {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 12px;
    color: var(--muted);
}

.pager a {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.centered {
    text-align: center;
}

.nav-toggle,
.mobile-menu {
    display: none;
}

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

@media (max-width: 820px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        position: static;
        height: auto;
        padding: 16px;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .mobile-menu {
        display: inline-flex;
        margin-left: auto;
        padding: 6px 9px;
        border: 1px solid var(--border);
        border-radius: 8px;
        color: var(--muted);
    }

    .nav-list,
    .sidebar-footer {
        display: grid;
    }

    .content {
        padding: 20px;
    }

    .page-header,
    .section-head,
    .split-grid,
    .manual-grid,
    .pricing-grid.three,
    .pricing-grid.two,
    .report-filters,
    .compact-form {
        display: grid;
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .auth-card {
        padding: 22px;
    }

    .auth-pricing-link {
        grid-template-columns: 1fr;
    }

    .metric-grid {
        grid-template-columns: 1fr;
    }

    .page-header h1,
    .auth-heading h1 {
        font-size: 24px;
    }
}
