:root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --line: #d8dee8;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #1d4ed8;
    --primary-soft: #dbeafe;
    --ok: #15803d;
    --bad: #b91c1c;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

a {
    color: var(--primary);
    text-decoration: none;
}

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

button,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    border: 1px solid var(--primary);
    border-radius: 6px;
    padding: 0 14px;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
}

.button.secondary,
button.secondary {
    background: #fff;
    color: var(--primary);
}

button:disabled {
    opacity: .6;
    cursor: not-allowed;
}

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

.login-card,
.install-card {
    width: min(460px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 28px;
    box-shadow: 0 16px 50px rgba(31, 41, 55, .08);
}

.login-card h1,
.install-card h1 {
    margin: 0 0 6px;
    font-size: 24px;
}

.login-card p,
.install-card p {
    margin: 0 0 22px;
    color: var(--muted);
}

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

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

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 10px;
    background: #fff;
    color: var(--text);
}

textarea {
    min-width: 180px;
    min-height: 38px;
    resize: vertical;
}

.alert,
.notice {
    margin: 12px 0;
    border-radius: 6px;
    padding: 10px 12px;
}

.alert {
    background: #fee2e2;
    color: #7f1d1d;
}

.notice {
    background: #dcfce7;
    color: #14532d;
}

.steps {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 18px 0;
}

.steps span {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px;
    text-align: center;
    color: var(--muted);
}

.steps .active {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary);
}

.check-list {
    display: grid;
    gap: 10px;
    margin-bottom: 18px;
}

.check-list div {
    display: flex;
    justify-content: space-between;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px 12px;
}

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

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

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

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 56px;
    padding: 0 20px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, .96);
}

.topbar div {
    display: flex;
    gap: 12px;
    align-items: baseline;
}

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

.topbar nav {
    display: flex;
    gap: 16px;
}

.page,
.table-page {
    padding: 18px;
}

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

.panel h1 {
    margin: 0 0 16px;
    font-size: 22px;
}

.inline-form {
    display: grid;
    grid-template-columns: repeat(5, minmax(120px, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

.simple-table,
.history-table {
    width: 100%;
    border-collapse: collapse;
}

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

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

.tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.tabs a {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 12px;
    background: #fff;
    color: var(--text);
}

.tabs a.active {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary);
}

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

.switch {
    display: flex;
    grid-template-columns: none;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
}

.switch input {
    width: auto;
}

.sheet-wrap {
    width: 100%;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.sheet {
    min-width: 2500px;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.sheet th,
.sheet td {
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    padding: 7px;
    vertical-align: top;
}

.sheet th {
    position: sticky;
    top: 56px;
    z-index: 3;
    background: #eef2f7;
    color: #374151;
    font-weight: 600;
    white-space: nowrap;
}

.sheet .group-row th {
    top: 56px;
    background: #dbeafe;
    text-align: center;
}

.sheet thead tr:nth-child(2) th {
    top: 94px;
}

.sticky-col {
    position: sticky;
    left: 0;
    z-index: 4;
    min-width: 150px;
    background: #fff;
}

th.sticky-col {
    background: #e5edf9;
}

.sheet input,
.sheet select,
.sheet textarea {
    min-width: 130px;
    border: 1px solid transparent;
    padding: 6px 7px;
    background: transparent;
}

.sheet input:focus,
.sheet select:focus,
.sheet textarea:focus {
    border-color: var(--primary);
    background: #fff;
    outline: none;
}

.sheet textarea {
    min-width: 190px;
}

.status-cell {
    display: grid;
    gap: 4px;
}

.badge {
    display: inline-flex;
    width: fit-content;
    border-radius: 999px;
    padding: 3px 9px;
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
}

small,
.muted {
    color: var(--muted);
}

.not-ready {
    background: #f9fafb;
}

.action-cell {
    min-width: 120px;
}

.action-cell button {
    width: 100%;
    margin-bottom: 6px;
}

.history-row[hidden],
body:not(.show-history) .history-row {
    display: none;
}

.history-row td {
    background: #fbfdff;
    padding: 12px;
}

.history-content {
    max-width: calc(100vw - 70px);
}

.empty-row td {
    padding: 32px;
    text-align: center;
    color: var(--muted);
}

.saving {
    background: #fef3c7 !important;
}

.saved {
    background: #dcfce7 !important;
}

.failed {
    background: #fee2e2 !important;
}

@media (max-width: 760px) {
    .topbar,
    .toolbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .inline-form {
        grid-template-columns: 1fr;
    }

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

