:root {
    --bg: #f4f4f9;
    --panel: #ffffff;
    --ink: #333333;
    --muted: #5f6670;
    --line: #d8dde5;
    --accent: #4CAF50;
    --accent-dark: #388E3C;
    --danger: #a53b3b;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
}

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

button,
.download {
    border: 1px solid var(--line);
    border-radius: 5px;
    background: #e0e0e0;
    color: var(--ink);
    cursor: pointer;
    min-height: 36px;
    padding: 0 12px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

button:hover,
.download:hover {
    background: var(--accent);
    color: #fff;
}

.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.primary:hover {
    background: var(--accent-dark);
}

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

.app-shell {
    min-height: 100vh;
    padding: 0 0 24px;
}

.workspace {
    margin: 0 auto;
    max-width: 1440px;
    width: 100%;
}

.dashboard-view {
    max-width: none;
}

.home-topbar {
    align-items: center;
    background-color: var(--accent);
    color: white;
    display: flex;
    gap: 16px;
    justify-content: space-between;
    padding: 20px;
}

.home-topbar h1 {
    font-size: 32px;
    margin: 0;
}

.home-nav {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.home-nav a,
.home-nav span {
    color: #fff;
    font-size: 14px;
    text-decoration: none;
}

.home-nav a {
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 5px;
    padding: 8px 10px;
}

.home-nav a:hover {
    background: rgba(255, 255, 255, 0.18);
}

.dashboard-container {
    display: grid;
    gap: 20px;
    grid-template-columns: 1fr 1fr;
    margin: 0 auto;
    max-width: 1200px;
    padding: 20px;
}

.category {
    background-color: #fff;
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 20px;
}

.external-tools {
    grid-column: 1 / -1;
}

.category h2 {
    color: #333;
    margin: 30px 0 20px;
    text-align: center;
}

.category h2:first-child {
    margin-top: 0;
}

.category ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
}

.category li {
    margin: 15px 0;
}

.category a,
.dashboard-link {
    background-color: #e0e0e0;
    border: 0;
    border-radius: 5px;
    color: #333;
    display: block;
    font-size: 18px;
    min-height: 0;
    padding: 10px;
    text-align: center;
    text-decoration: none;
    transition: background-color 0.3s ease, color 0.3s ease;
    width: 100%;
}

.category a:hover,
.dashboard-link:hover {
    background-color: var(--accent);
    color: white;
}

.category a:active,
.dashboard-link:active {
    background-color: var(--accent-dark);
}

.back-button {
    margin-bottom: 10px;
}

.topbar {
    align-items: center;
    background: linear-gradient(135deg, #1d9e4c 0%, #127238 100%);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
    color: #fff;
    display: flex;
    gap: 20px;
    justify-content: space-between;
    margin-bottom: 24px;
    min-height: 58px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-info {
    align-items: center;
    display: flex;
    gap: 14px;
    min-width: 0;
}

.topbar h1 {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.2;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 26px;
}

h2,
legend {
    font-size: 15px;
    font-weight: 700;
}

p {
    color: inherit;
    margin-top: 4px;
}

.topbar p {
    color: rgba(255, 255, 255, 0.72);
    font-size: 12.5px;
    margin-top: 2px;
}

.actions,
.upload-row,
.section-head {
    align-items: center;
    display: flex;
    gap: 10px;
}

.info-popover {
    position: relative;
}

.info-button {
    border-radius: 999px;
    font-weight: 800;
    height: 38px;
    padding: 0;
    width: 38px;
}

.info-panel {
    background: #fff;
    border: 1px solid rgba(18, 55, 42, 0.18);
    border-radius: 8px;
    box-shadow: 0 18px 46px rgba(18, 55, 42, 0.22);
    color: var(--ink);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.45;
    max-width: min(320px, calc(100vw - 32px));
    opacity: 0;
    padding: 12px 14px;
    pointer-events: none;
    position: absolute;
    right: 0;
    top: calc(100% + 10px);
    transform: translateY(-4px);
    transition: opacity 0.16s ease, transform 0.16s ease;
    width: 320px;
    z-index: 30;
}

.info-popover:hover .info-panel,
.info-popover:focus-within .info-panel {
    opacity: 1;
    transform: translateY(0);
}

.workbook-mode-controls {
    display: grid;
    gap: 10px;
}

.workbook-mode-controls .inline-check {
    margin-top: 0;
}

.action-status {
    align-items: stretch;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.action-status .status {
    color: rgba(255, 255, 255, 0.9);
    min-height: 16px;
    text-align: center;
}

.action-status .status.error {
    color: #ffe1e1;
}

[hidden] {
    display: none !important;
}

.layout {
    align-items: start;
    display: grid;
    gap: 18px;
    grid-template-columns: minmax(420px, 560px) minmax(0, 1fr);
    padding: 0 20px;
}

.binding-layout {
    align-items: start;
    display: grid;
    gap: 18px;
    grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
    padding: 0 20px;
}

#bindingView {
    max-width: 1880px;
}

.binding-layout .output-panel {
    grid-column: 1 / -1;
}

.binding-controls {
    display: grid;
    gap: 18px;
}

.binding-table-panel {
    min-width: 0;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 18px;
}

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

fieldset:first-child {
    border-top: 0;
    padding-top: 0;
}

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

input,
select,
textarea {
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--ink);
    min-height: 36px;
    padding: 7px 9px;
    width: 100%;
}

textarea {
    font-family: "Courier New", monospace;
    font-size: 12px;
    line-height: 1.45;
    min-height: 170px;
    resize: vertical;
}

input[type="checkbox"] {
    min-height: auto;
    width: 18px;
}

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

.checkbox-row input {
    flex: 0 0 auto;
}

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

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

.section-head {
    justify-content: space-between;
    margin-bottom: 12px;
}

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

.mode-column-editor {
    border: 1px solid var(--line);
    border-radius: 6px;
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 12px;
    padding: 10px;
}

.mode-column-editor .inline-check:first-child {
    grid-column: 1 / -1;
}

.include-column-editor {
    border: 1px solid var(--line);
    border-radius: 6px;
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 12px;
    padding: 10px;
}

.summary-table-editor {
    border: 1px solid var(--line);
    border-radius: 6px;
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 12px;
    padding: 10px;
}

.summary-table-editor .inline-check:first-child {
    grid-column: 1 / -1;
}

.fan-coil-layout {
    grid-template-columns: minmax(360px, 480px) minmax(0, 1fr);
}

.fan-coil-options {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.fan-coil-options .inline-check {
    align-items: center;
    color: var(--ink);
    display: flex;
    gap: 8px;
}

.fan-coil-options input[type="number"] {
    max-width: 120px;
}

.fan-coil-schematic {
    background:
        linear-gradient(90deg, rgba(216, 221, 229, 0.45) 1px, transparent 1px),
        linear-gradient(rgba(216, 221, 229, 0.45) 1px, transparent 1px),
        #f8fafc;
    background-size: 24px 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    height: 300px;
    overflow: hidden;
    position: relative;
}

.fan-coil-schematic > div {
    align-items: center;
    border: 1px solid #8793a3;
    display: flex;
    font-size: 12px;
    font-weight: 700;
    justify-content: center;
    overflow: hidden;
    padding: 4px;
    position: absolute;
    text-align: center;
    white-space: normal;
}

.fcu-duct {
    background: linear-gradient(#fefefe, #c6c9cd);
    color: #333;
}

.fcu-node {
    background: #ffd100;
    border-radius: 50%;
    color: #333;
}

.fcu-coil {
    background: #42b4e6;
    color: #fff;
}

.fcu-coil.heat {
    background: #e47f00;
}

.fcu-sensor,
.fcu-zone {
    background: #f7f7f8;
    border-radius: 8px;
    color: #333;
}

.fcu-table {
    background: #fff;
    border-color: #079647;
    border-radius: 8px;
    color: #626469;
}

.ahu-box-editor {
    border: 1px solid var(--line);
    border-radius: 6px;
    display: grid;
    gap: 12px;
    margin-top: 12px;
    padding: 10px;
}

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

.ahu-box-list[hidden],
#addAhuBoxButton[hidden] {
    display: none !important;
}

.ahu-box-item {
    background: color-mix(in srgb, var(--panel) 92%, var(--accent) 8%);
    border: 1px solid var(--line);
    border-radius: 6px;
    display: grid;
    gap: 10px;
    padding: 10px;
}

.ahu-box-fields {
    align-items: end;
    display: grid;
    gap: 10px;
    grid-template-columns: minmax(130px, 1fr) minmax(100px, 0.7fr) minmax(130px, 0.9fr) 34px;
}

.ahu-highlight {
    align-self: center;
    margin-bottom: 7px;
}

.ahu-served-rows {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.toolbar-options {
    display: grid;
    gap: 10px;
}

.toolbar-option {
    align-items: center;
    color: var(--ink);
    display: grid;
    gap: 10px;
    grid-template-columns: 18px minmax(0, 1fr) 72px;
}

.toolbar-option-head {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.toolbar-option .toolbar-order {
    min-height: 32px;
}

.item-row {
    align-items: end;
    display: grid;
    gap: 10px;
    grid-template-columns: minmax(110px, 1fr) minmax(100px, 0.85fr) minmax(140px, 1.25fr) 62px 34px;
}

.rows .item-row {
    grid-template-columns: minmax(160px, 1fr) 42px;
}

.summary-column-option {
    align-self: center;
    color: var(--ink);
    justify-content: center;
    margin-bottom: 7px;
}

.summary-column-option[hidden] {
    display: none !important;
}

.icon-button {
    padding: 0;
}

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

.binding-table {
    border-collapse: collapse;
    table-layout: fixed;
    width: 100%;
}

.binding-table th,
.binding-table td {
    border-bottom: 1px solid var(--line);
    padding: 6px;
    text-align: left;
    vertical-align: top;
}

.binding-table th {
    background: #f3f6f8;
    color: var(--muted);
    font-size: 12px;
}

.binding-table td {
    background: #fff;
}

.binding-table input {
    min-width: 0;
}

.binding-table th:nth-child(1),
.binding-table td:nth-child(1) {
    width: 26%;
}

.binding-table th:nth-child(2),
.binding-table td:nth-child(2) {
    width: 14%;
}

.binding-table th:nth-child(3),
.binding-table td:nth-child(3) {
    width: 15%;
}

.binding-table th:nth-child(4),
.binding-table td:nth-child(4) {
    width: 15%;
}

.binding-table th:nth-child(5),
.binding-table td:nth-child(5) {
    width: 27%;
}

.binding-table th:nth-child(6),
.binding-table td:nth-child(6) {
    width: 34px;
}

.binding-table .manual {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(47, 122, 79, 0.12);
}

.output-panel {
    display: grid;
    gap: 16px;
    min-width: 0;
}

.preview {
    background: #111820;
    border-radius: 8px;
    color: #d8e5ef;
    font-family: "Courier New", monospace;
    font-size: 12px;
    height: 420px;
    line-height: 1.45;
    margin: 0;
    overflow: auto;
    padding: 14px;
    white-space: pre;
}

.download.disabled {
    opacity: 0.45;
    pointer-events: none;
}

.grid-preview-wrap {
    display: grid;
    gap: 10px;
}

.grid-preview {
    background-color: #f8fafc;
    background-image:
        linear-gradient(#dfe5ec 1px, transparent 1px),
        linear-gradient(90deg, #dfe5ec 1px, transparent 1px);
    background-size: 20px 20px;
    border: 1px solid var(--line);
    border-radius: 8px;
    min-height: 220px;
    overflow: hidden;
    position: relative;
}

.grid-cell {
    align-items: center;
    border: 1px solid #8793a3;
    display: flex;
    font-size: 11px;
    justify-content: center;
    overflow: hidden;
    position: absolute;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.grid-cell.header {
    background: #2b3038;
    color: #fff;
}

.grid-cell.body {
    background: rgba(255, 255, 255, 0.88);
}

.status {
    color: var(--danger);
    font-size: 13px;
}

.status.neutral {
    color: var(--muted);
}

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

.auth-page {
    align-items: center;
    display: flex;
    min-height: 100vh;
    padding: 20px;
}

.auth-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 16px;
    margin: 0 auto;
    max-width: 430px;
    padding: 24px;
    width: 100%;
}

.auth-card h1 {
    color: var(--ink);
    text-align: center;
}

.auth-card form,
.admin-create-form {
    display: grid;
    gap: 12px;
}

.auth-links {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.auth-links a,
.reset-link {
    color: var(--accent-dark);
    overflow-wrap: anywhere;
}

.auth-note {
    color: var(--muted);
    font-size: 14px;
    text-align: center;
}

.flash-list {
    display: grid;
    gap: 8px;
}

.flash-message {
    background: #eef7ef;
    border: 1px solid #b7ddb9;
    border-radius: 5px;
    color: #245f3e;
    padding: 10px;
}

.admin-shell {
    min-height: 100vh;
}

.admin-layout {
    display: grid;
    gap: 18px;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    padding: 0 20px 24px;
}

.inline-check {
    align-items: center;
    display: flex;
    gap: 8px;
}

.inline-check input {
    width: 18px;
}

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

.admin-table {
    border-collapse: collapse;
    min-width: 850px;
    width: 100%;
}

.admin-table th,
.admin-table td {
    border-bottom: 1px solid var(--line);
    padding: 10px;
    text-align: left;
    vertical-align: top;
}

.admin-table th {
    background: #f3f6f8;
    color: var(--muted);
    font-size: 12px;
}

.admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.admin-actions form {
    margin: 0;
}

.admin-actions button {
    min-height: 32px;
}

.admin-wide-panel {
    grid-column: 1 / -1;
}

.request-layout {
    grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
}

.request-list {
    display: grid;
    gap: 12px;
}

.request-card {
    align-items: start;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 12px;
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 14px;
}

.request-card h3 {
    font-size: 16px;
    margin: 0 0 6px;
}

.request-card p {
    color: var(--muted);
    line-height: 1.45;
}

.request-card span {
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    padding: 6px 9px;
}

.request-card.todo span {
    background: #fff6df;
    color: #7a5412;
}

.request-card.complete span {
    background: var(--accent-soft);
    color: var(--accent-dark);
}

.request-table th:nth-child(1),
.request-table td:nth-child(1) {
    width: 90px;
}

.request-table th:nth-child(2),
.request-table td:nth-child(2) {
    width: 180px;
}

.request-table th:nth-child(4),
.request-table td:nth-child(4) {
    width: 210px;
}

@media (max-width: 980px) {
    .topbar {
        flex-wrap: wrap;
        min-height: auto;
        padding: 10px 16px;
    }

    .topbar-info {
        gap: 10px;
    }

    .layout,
    .binding-layout,
    .dashboard-container,
    .admin-layout {
        display: grid;
        grid-template-columns: 1fr;
    }

    .home-topbar {
        align-items: stretch;
        display: grid;
        text-align: center;
    }

    .home-nav {
        justify-content: center;
    }

    .external-tools {
        grid-column: auto;
    }

    .actions {
        flex-wrap: wrap;
    }

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

    .binding-table {
        min-width: 900px;
    }
}

@media (max-width: 560px) {
    .app-shell {
        padding: 0 0 14px;
    }

    .dashboard-container,
    .layout,
    .binding-layout {
        padding-left: 14px;
        padding-right: 14px;
    }

    .grid-fields,
    .replace-grid,
    .mode-column-editor,
    .include-column-editor,
    .summary-table-editor,
    .ahu-box-fields,
    .ahu-served-rows,
    .item-row,
    .rows .item-row {
        grid-template-columns: 1fr;
    }

    .icon-button {
        width: 100%;
    }
}

/* Modern UI refresh */
:root {
    --bg: #eef3f1;
    --bg-soft: #f7faf8;
    --panel: #ffffff;
    --ink: #16211d;
    --muted: #66736d;
    --line: #dce5e1;
    --line-strong: #c6d4ce;
    --accent: #16834a;
    --accent-dark: #0f6639;
    --accent-soft: #e7f5ed;
    --danger: #b44444;
    --shadow: 0 18px 45px rgba(22, 33, 29, 0.08);
    --shadow-soft: 0 8px 22px rgba(22, 33, 29, 0.06);
}

body {
    background:
        radial-gradient(circle at top left, rgba(22, 131, 74, 0.12), transparent 32rem),
        linear-gradient(180deg, #f9fbfa 0%, var(--bg) 100%);
    color: var(--ink);
    font-family: Inter, "Segoe UI", Arial, Helvetica, sans-serif;
}

button,
.download {
    background: #fff;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    color: var(--ink);
    font-weight: 650;
    min-height: 38px;
    padding: 0 14px;
    transition: background-color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

button:hover,
.download:hover {
    background: var(--accent-soft);
    border-color: rgba(22, 131, 74, 0.42);
    box-shadow: var(--shadow-soft);
    color: var(--accent-dark);
    transform: translateY(-1px);
}

.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.primary:hover {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
    color: #fff;
}

.home-topbar,
.topbar {
    background: linear-gradient(135deg, #12372a 0%, #16834a 100%);
    box-shadow: 0 16px 42px rgba(18, 55, 42, 0.18);
    margin-bottom: 24px;
    padding: 22px 28px;
}

.home-topbar h1,
.topbar h1 {
    font-size: 28px;
    line-height: 1.1;
}

.home-topbar h1 {
    font-size: 32px;
}

.home-nav span {
    color: rgba(255, 255, 255, 0.84);
}

.home-nav a,
.topbar .download,
.topbar button {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.32);
    color: #fff;
}

.home-nav a {
    border-radius: 999px;
    font-weight: 650;
    padding: 8px 12px;
}

.home-nav a:hover,
.topbar .download:hover,
.topbar button:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.58);
    box-shadow: none;
    color: #fff;
}

.topbar .primary {
    background: #fff;
    border-color: #fff;
    color: #0f6639;
}

.topbar .primary:hover {
    background: #effaf3;
    color: #0f6639;
}

.dashboard-container {
    gap: 22px;
    max-width: 1220px;
    padding: 0 24px 24px;
}

.category,
.panel,
.auth-card {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(198, 212, 206, 0.78);
    border-radius: 14px;
    box-shadow: var(--shadow);
}

.category {
    overflow: hidden;
    padding: 22px;
}

.category h2 {
    color: #12372a;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.04em;
    margin: 28px 0 14px;
    text-align: left;
    text-transform: uppercase;
}

.category h2:first-child {
    margin-top: 0;
}

.category ul {
    display: grid;
    gap: 10px;
}

.category li {
    margin: 0;
}

.category a,
.dashboard-link {
    align-items: center;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--ink);
    display: flex;
    font-size: 15px;
    font-weight: 650;
    justify-content: space-between;
    min-height: 48px;
    padding: 12px 14px;
    text-align: left;
    transition: background-color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.category a::after,
.dashboard-link::after {
    color: var(--muted);
    content: ">";
    font-size: 17px;
    font-weight: 800;
}

.category a:hover,
.dashboard-link:hover {
    background: var(--accent-soft);
    border-color: rgba(22, 131, 74, 0.36);
    box-shadow: var(--shadow-soft);
    color: var(--accent-dark);
    transform: translateY(-1px);
}

.layout,
.binding-layout,
.admin-layout {
    gap: 20px;
    padding: 0 24px;
}

.binding-layout {
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
}

.panel {
    padding: 20px;
}

label {
    color: var(--muted);
    gap: 7px;
    font-weight: 650;
}

input,
select,
textarea {
    background: #fbfdfc;
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    min-height: 38px;
    outline: none;
    padding: 8px 10px;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

input:focus,
select:focus,
textarea:focus {
    background: #fff;
    border-color: rgba(22, 131, 74, 0.58);
    box-shadow: 0 0 0 4px rgba(22, 131, 74, 0.12);
}

textarea,
.preview {
    font-family: "Cascadia Mono", "Courier New", monospace;
}

input[type="checkbox"] {
    accent-color: var(--accent);
}

.mode-column-editor,
.include-column-editor,
.summary-table-editor,
.toolbar-option,
.item-row {
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
}

.toolbar-option-head {
    background: transparent;
    border: 0;
    font-weight: 800;
    padding: 0 9px;
}

.binding-table-wrap,
.admin-table-wrap,
.grid-preview,
.preview {
    border-radius: 12px;
}

.binding-table th,
.admin-table th {
    background: #f4f8f6;
    font-weight: 800;
}

.binding-table th,
.binding-table td,
.admin-table th,
.admin-table td {
    padding: 9px;
}

.binding-table .manual {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(22, 131, 74, 0.12);
}

.preview {
    background: #101816;
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #dcece5;
    line-height: 1.5;
    padding: 16px;
}

.grid-preview {
    background-color: #fbfdfc;
    background-image:
        linear-gradient(#e1e9e5 1px, transparent 1px),
        linear-gradient(90deg, #e1e9e5 1px, transparent 1px);
}

.grid-cell.header {
    background: #15221e;
}

.auth-card {
    gap: 18px;
    max-width: 440px;
    padding: 28px;
}

.auth-card h1 {
    font-size: 28px;
}

.auth-links a,
.reset-link {
    color: var(--accent-dark);
    font-weight: 650;
}

.flash-message {
    background: var(--accent-soft);
    border: 1px solid #b7ddc8;
    border-radius: 10px;
    color: var(--accent-dark);
    padding: 10px 12px;
}

@media (max-width: 560px) {
    .home-topbar,
    .topbar {
        padding: 18px 14px;
    }
}

/* Table builder overflow fixes */
.layout,
.panel,
.output-panel {
    min-width: 0;
}

.upload-row {
    flex-wrap: wrap;
}

.upload-row input,
.upload-row select {
    min-width: 0;
}

.include-column-editor {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: hidden;
}

.include-column-editor .inline-check {
    grid-column: 1 / -1;
}

.include-column-editor input {
    min-width: 0;
}

@media (max-width: 1180px) {
    .layout {
        grid-template-columns: minmax(0, 1fr);
    }
}


/* Site analyzer */
.site-analyzer-shell {
    padding-bottom: 28px;
}

.site-analyzer-topbar .tool-home-link {
    margin-bottom: 10px;
}

.site-analyzer-layout {
    display: grid;
    gap: 20px;
    margin: 0 auto;
    max-width: 1680px;
    padding: 0 24px;
}

.site-instructions-panel {
    align-items: center;
    display: flex;
    gap: 16px;
    justify-content: space-between;
}

.site-instructions-panel h2 {
    margin-bottom: 6px;
}

.site-instructions-panel .download {
    flex: 0 0 auto;
}

.site-upload-panel {
    align-items: end;
    display: grid;
    gap: 14px;
    grid-template-columns: minmax(260px, 1fr) auto;
}

.site-upload-panel h2,
.site-upload-panel .site-muted,
.site-upload-panel .site-file-note {
    grid-column: 1 / -1;
}

.site-muted,
.site-file-note {
    color: var(--muted);
    font-size: 14px;
}

.site-error-panel {
    border-color: rgba(180, 68, 68, 0.35);
}

.site-error-panel ul {
    color: var(--danger);
    margin: 10px 0 0;
}

.site-summary-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric-card {
    display: grid;
    gap: 8px;
}

.metric-card span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 750;
    text-transform: uppercase;
}

.metric-card strong {
    color: #12372a;
    font-size: 30px;
    line-height: 1;
}

.site-table-panel {
    min-width: 0;
}

.site-table-wrap {
    border: 1px solid var(--line);
    border-radius: 12px;
    max-height: 520px;
    overflow: auto;
}

.site-table-wrap.compact {
    max-height: 420px;
}

.hierarchy-wrap {
    max-height: 720px;
}

.site-analyzer-table {
    border-collapse: collapse;
    min-width: 1120px;
    table-layout: fixed;
    width: 100%;
}

.site-analyzer-table th,
.site-analyzer-table td {
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
    text-align: left;
    vertical-align: top;
}

.site-analyzer-table th {
    background: #f4f8f6;
    color: var(--muted);
    font-size: 12px;
    font-weight: 850;
    position: sticky;
    top: 0;
    z-index: 1;
}

.site-analyzer-table td {
    background: rgba(255, 255, 255, 0.9);
    font-size: 13px;
    line-height: 1.4;
}

.site-analyzer-table tbody tr:hover td {
    background: #fbfdfc;
}

.site-type-cell,
.path-cell {
    font-family: "Cascadia Mono", "Courier New", monospace;
    font-size: 12px;
    overflow-wrap: anywhere;
}

.parent-cell,
.object-cell {
    min-width: 0;
}

.parent-cell strong,
.object-cell strong {
    display: block;
    color: var(--ink);
    font-weight: 800;
    overflow-wrap: anywhere;
}

.parent-cell span,
.object-cell span {
    display: block;
    margin-top: 5px;
    color: var(--muted);
    font-family: "Cascadia Mono", "Courier New", monospace;
    font-size: 12px;
    overflow-wrap: anywhere;
}

.count-cell {
    color: #12372a;
    font-weight: 800;
    text-align: right !important;
}

.type-pill {
    background: var(--accent-soft);
    border: 1px solid rgba(22, 131, 74, 0.22);
    border-radius: 999px;
    color: var(--accent-dark);
    display: inline-flex;
    font-size: 12px;
    font-weight: 800;
    line-height: 1.25;
    padding: 5px 9px;
}

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

.child-type-list div {
    align-items: center;
    display: grid;
    gap: 10px;
    grid-template-columns: minmax(0, 1fr) auto;
}

.child-type-list span {
    overflow-wrap: anywhere;
}

.child-type-list strong {
    color: #12372a;
    font-weight: 850;
}

.indent-1 { padding-left: 18px !important; }
.indent-2 { padding-left: 26px !important; }
.indent-3 { padding-left: 34px !important; }
.indent-4 { padding-left: 42px !important; }
.indent-5 { padding-left: 50px !important; }
.indent-6 { padding-left: 58px !important; }
.indent-7 { padding-left: 66px !important; }
.indent-8 { padding-left: 74px !important; }

.hierarchy-head {
    align-items: end;
    display: grid;
    gap: 14px;
    grid-template-columns: minmax(0, 1fr) minmax(220px, 360px) auto;
}

.type-filter-label {
    margin-left: auto;
    max-width: 360px;
    width: 100%;
}

.largest-parents-table th:nth-child(1),
.largest-parents-table td:nth-child(1) { width: 30%; }
.largest-parents-table th:nth-child(2),
.largest-parents-table td:nth-child(2) { width: 22%; }
.largest-parents-table th:nth-child(3),
.largest-parents-table td:nth-child(3) { width: 90px; }
.largest-parents-table th:nth-child(4),
.largest-parents-table td:nth-child(4) { width: auto; }

.hierarchy-table {
    min-width: 980px;
}

.hierarchy-table th:nth-child(1),
.hierarchy-table td:nth-child(1) { width: 24%; }
.hierarchy-table th:nth-child(2),
.hierarchy-table td:nth-child(2) { width: 180px; }
.hierarchy-table th:nth-child(3),
.hierarchy-table td:nth-child(3) { width: 24%; }
.hierarchy-table th:nth-child(4),
.hierarchy-table td:nth-child(4) { width: 85px; }
.hierarchy-table th:nth-child(5),
.hierarchy-table td:nth-child(5) { width: auto; }

@media (max-width: 980px) {
    .site-upload-panel,
    .site-summary-grid,
    .hierarchy-head {
        grid-template-columns: 1fr;
    }

    .site-instructions-panel {
        align-items: stretch;
        display: grid;
    }

    .type-filter-label {
        margin-left: 0;
        max-width: none;
    }
}

@media (max-width: 560px) {
    .site-analyzer-layout {
        padding-left: 14px;
        padding-right: 14px;
    }
}

/* ===== Tool page layout helpers ===== */
.tool-home-link {
    align-items: center;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.32);
    border-radius: 8px;
    color: #fff;
    display: inline-flex;
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 600;
    min-height: 32px;
    padding: 0 12px;
    text-decoration: none;
    transition: background 0.18s ease, border-color 0.18s ease;
    white-space: nowrap;
}

.tool-home-link:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.58);
    box-shadow: none;
    color: #fff;
}

.tool-single-col {
    margin: 0 auto;
    max-width: 820px;
    padding: 0 24px 32px;
}

.tool-wide-col {
    margin: 0 auto;
    max-width: 1280px;
    padding: 0 24px 32px;
}

button:disabled,
input[type="submit"]:disabled {
    opacity: 0.45;
    pointer-events: none;
}

/* ===== Theme toggle button ===== */
.theme-toggle {
    align-items: center;
    background: var(--panel);
    border: 1px solid var(--line-strong);
    border-radius: 50%;
    bottom: 22px;
    box-shadow: var(--shadow-soft);
    color: var(--ink);
    cursor: pointer;
    display: flex;
    height: 44px;
    justify-content: center;
    min-height: auto;
    padding: 0;
    position: fixed;
    right: 22px;
    transition: background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, color 0.18s ease, transform 0.18s ease;
    width: 44px;
    z-index: 200;
}

.theme-toggle:hover {
    background: var(--accent-soft);
    border-color: rgba(22, 131, 74, 0.42);
    box-shadow: var(--shadow);
    color: var(--accent-dark);
    transform: translateY(-2px);
}

.theme-toggle svg {
    display: block;
    flex-shrink: 0;
}

/* ===== Dark mode ===== */
[data-theme="dark"] {
    --bg: #111917;
    --bg-soft: #171f1c;
    --panel: #1d2722;
    --ink: #e6eeea;
    --muted: #8ca099;
    --line: #273430;
    --line-strong: #364740;
    --accent: #28b359;
    --accent-dark: #3dce6f;
    --accent-soft: #182e24;
    --danger: #e05c5c;
    --shadow: 0 18px 45px rgba(0, 0, 0, 0.5);
    --shadow-soft: 0 8px 22px rgba(0, 0, 0, 0.35);
}

[data-theme="dark"] body {
    background:
        radial-gradient(circle at top left, rgba(40, 179, 89, 0.07), transparent 32rem),
        linear-gradient(180deg, #0c1410 0%, var(--bg) 100%);
}

[data-theme="dark"] .category,
[data-theme="dark"] .panel,
[data-theme="dark"] .auth-card {
    background: rgba(29, 39, 34, 0.96);
    border-color: rgba(54, 71, 64, 0.88);
}

[data-theme="dark"] button,
[data-theme="dark"] .download {
    background: rgba(29, 39, 34, 0.9);
    border-color: var(--line-strong);
    color: var(--ink);
}

[data-theme="dark"] button:hover,
[data-theme="dark"] .download:hover {
    background: var(--accent-soft);
    border-color: rgba(40, 179, 89, 0.4);
    color: var(--accent-dark);
}

[data-theme="dark"] .primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

[data-theme="dark"] .primary:hover {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
    color: #fff;
}

[data-theme="dark"] .home-topbar,
[data-theme="dark"] .topbar {
    background: linear-gradient(135deg, #0a2018 0%, #0f5c33 100%);
}

[data-theme="dark"] .home-nav a,
[data-theme="dark"] .topbar .download,
[data-theme="dark"] .topbar button {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.24);
    color: #fff;
}

[data-theme="dark"] .home-nav a:hover,
[data-theme="dark"] .topbar .download:hover,
[data-theme="dark"] .topbar button:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.42);
}

[data-theme="dark"] .topbar .primary {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.4);
    color: #fff;
}

[data-theme="dark"] .topbar .primary:hover {
    background: rgba(255, 255, 255, 0.22);
}

[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
    background: #141c18;
    border-color: var(--line-strong);
    color: var(--ink);
}

[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] textarea:focus {
    background: #1d2722;
    border-color: rgba(40, 179, 89, 0.55);
    box-shadow: 0 0 0 4px rgba(40, 179, 89, 0.12);
}

[data-theme="dark"] .category a,
[data-theme="dark"] .dashboard-link {
    background: rgba(23, 31, 28, 0.9);
    border-color: var(--line);
    color: var(--ink);
}

[data-theme="dark"] .category a:hover,
[data-theme="dark"] .dashboard-link:hover {
    background: var(--accent-soft);
    border-color: rgba(40, 179, 89, 0.35);
    color: var(--accent-dark);
}

[data-theme="dark"] .category h2 {
    color: var(--accent-dark);
}

[data-theme="dark"] .binding-table th,
[data-theme="dark"] .admin-table th,
[data-theme="dark"] .site-analyzer-table th {
    background: #1a2420;
    color: var(--muted);
}

[data-theme="dark"] .binding-table td,
[data-theme="dark"] .admin-table td {
    background: rgba(22, 32, 28, 0.9);
}

[data-theme="dark"] .site-analyzer-table td {
    background: rgba(22, 32, 28, 0.85);
}

[data-theme="dark"] .site-analyzer-table tbody tr:hover td {
    background: rgba(26, 36, 32, 0.95);
}

[data-theme="dark"] .flash-message {
    background: var(--accent-soft);
    border-color: rgba(40, 179, 89, 0.3);
    color: var(--accent-dark);
}

[data-theme="dark"] .mode-column-editor,
[data-theme="dark"] .include-column-editor,
[data-theme="dark"] .summary-table-editor,
[data-theme="dark"] .toolbar-option,
[data-theme="dark"] .item-row {
    background: var(--bg-soft);
    border-color: var(--line);
}

[data-theme="dark"] .ahu-box-item {
    background: color-mix(in srgb, var(--panel) 90%, var(--accent) 10%);
    border-color: var(--line);
}

[data-theme="dark"] .grid-preview {
    background-color: #141c18;
    background-image:
        linear-gradient(#1e2c27 1px, transparent 1px),
        linear-gradient(90deg, #1e2c27 1px, transparent 1px);
}

[data-theme="dark"] .fan-coil-schematic {
    background:
        linear-gradient(90deg, rgba(39, 52, 47, 0.45) 1px, transparent 1px),
        linear-gradient(rgba(39, 52, 47, 0.45) 1px, transparent 1px),
        #111917;
    border-color: var(--line);
}

[data-theme="dark"] .grid-cell.body {
    background: rgba(22, 32, 28, 0.85);
}

[data-theme="dark"] .metric-card strong {
    color: var(--accent-dark);
}

[data-theme="dark"] .type-pill {
    background: var(--accent-soft);
    border-color: rgba(40, 179, 89, 0.28);
    color: var(--accent-dark);
}

[data-theme="dark"] .info-panel {
    background: #1d2722;
    border-color: rgba(54, 71, 64, 0.6);
    color: var(--ink);
}

[data-theme="dark"] .request-card {
    background: var(--bg-soft);
    border-color: var(--line);
}

[data-theme="dark"] .auth-links a,
[data-theme="dark"] .reset-link {
    color: var(--accent-dark);
}

[data-theme="dark"] .theme-toggle {
    background: #1d2722;
    border-color: var(--line-strong);
    color: var(--ink);
}
