:root {
    color-scheme: light;
    --bg: #f6f8fb;
    --panel: #ffffff;
    --ink: #17202a;
    --muted: #5f6b7a;
    --line: #d9e0e7;
    --accent: #0f766e;
    --accent-ink: #ffffff;
    --danger: #b42318;
    --ok: #047857;
    --warn: #b45309;
    --shadow: 0 10px 30px rgba(18, 32, 45, 0.07);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

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

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

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    padding: 9px 10px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus,
select:focus {
    outline: 0;
    border-color: #0f766e;
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

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

button {
    border: 0;
    border-radius: 6px;
    background: var(--accent);
    color: var(--accent-ink);
    padding: 9px 14px;
    cursor: pointer;
    white-space: nowrap;
    font-weight: 650;
}

button.secondary {
    background: #e8edf2;
    color: var(--ink);
}

button.danger {
    background: var(--danger);
}

.ghost-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: #ffffff;
    color: var(--ink);
    padding: 8px 12px;
    font-weight: 650;
}

code,
pre {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.app {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 232px 1fr;
}

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

.brand {
    font-weight: 700;
    font-size: 18px;
    padding: 0 8px 8px;
}

.sidebar nav {
    display: grid;
    gap: 4px;
}

.sidebar a {
    padding: 10px 12px;
    border-radius: 6px;
    color: var(--muted);
    font-weight: 600;
}

.sidebar a.active,
.sidebar a:hover {
    background: #e6f3f1;
    color: #0b4f49;
}

.logout-form {
    margin-top: auto;
}

.content {
    padding: 32px;
    max-width: 1280px;
    width: 100%;
}

.page-head {
    margin-bottom: 18px;
}

.hero-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.page-head h1 {
    margin: 0 0 4px;
    font-size: 26px;
}

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

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

.setup-flow {
    display: grid;
    gap: 16px;
}

.setup-card {
    display: grid;
    grid-template-columns: 48px minmax(220px, 0.7fr) minmax(320px, 1.3fr);
    gap: 18px;
    align-items: start;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 20px;
}

.step-badge {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: #0f766e;
    color: #ffffff;
    font-weight: 800;
}

.setup-copy h2 {
    margin: 0 0 6px;
    font-size: 18px;
}

.setup-copy p {
    margin: 0;
    color: var(--muted);
}

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

.setup-fields .wide {
    grid-column: 1 / -1;
}

.sticky-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(246, 248, 251, 0.92);
    border-top: 1px solid var(--line);
    padding: 14px 0;
    backdrop-filter: blur(8px);
}

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

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.stats-grid article {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

.stats-grid strong {
    display: block;
    font-size: 28px;
}

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

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

.form-grid button {
    justify-self: start;
}

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

label input,
label textarea {
    color: var(--ink);
}

.table {
    display: grid;
    gap: 8px;
}

.row {
    display: grid;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fbfcfd;
}

.table .head {
    background: #eef3f7;
    color: var(--muted);
    font-weight: 700;
}

.table:not(.labels-table):not(.usage-table):not(.group-table):not(.discovered-table):not(.task-table) .row {
    grid-template-columns: 180px 120px 1fr;
}

.labels-table .row {
    grid-template-columns: 160px minmax(220px, 1.4fr) minmax(180px, 1fr) minmax(180px, 1fr);
}

.usage-table .row {
    grid-template-columns: 140px 1fr 1fr 100px 100px;
}

.group-table .row {
    grid-template-columns: 150px 72px 72px 1fr 1fr 1fr;
}

.discovered-table .row {
    grid-template-columns: 160px 1fr 100px 120px;
}

.task-table .row {
    grid-template-columns: 150px 160px 110px 1fr;
}

.kv {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
}

.kv:last-child {
    border-bottom: 0;
}

.status-ok {
    color: var(--ok);
    font-weight: 700;
}

.status-bad {
    color: var(--warn);
    font-weight: 700;
}

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

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

.check-list.compact {
    grid-template-columns: 1fr;
}

.check-list article {
    border-radius: 8px;
    border: 1px solid var(--line);
    padding: 14px;
    background: #fff;
}

.check-list strong,
.check-list span {
    display: block;
}

.check-list span {
    margin-top: 4px;
    font-weight: 700;
}

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

.ok-card {
    border-color: #a6f4c5 !important;
}

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

.bad-card {
    border-color: #fedf89 !important;
}

.bad-card span {
    color: var(--warn);
}

.inline-wide {
    flex: 1 1 520px;
    display: flex;
    gap: 8px;
}

.check-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 20px;
    margin: 14px 0;
}

.check-row label,
.group-table label,
.check-inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

.check-row input,
.group-table input[type="checkbox"],
.check-inline input {
    width: auto;
}

.split {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 18px;
}

.file-list {
    display: grid;
    align-content: start;
    gap: 6px;
}

.file-list a {
    border-radius: 6px;
    padding: 11px 12px;
    color: var(--muted);
    font-weight: 650;
}

.file-list a.active,
.file-list a:hover {
    background: #e6f3f1;
    color: #0b4f49;
}

.editor textarea {
    width: 100%;
    min-height: 520px;
    white-space: pre;
}

.log-view {
    min-height: 520px;
    max-height: 65vh;
    overflow: auto;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #0f1720;
    color: #d7e1ea;
}

.chat-view {
    min-height: 320px;
    max-height: 65vh;
    overflow: auto;
    display: grid;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f8fafc;
}

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

.chat-message {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    padding: 10px 12px;
}

.chat-message.assistant {
    background: #eefaf8;
}

.chat-message header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: var(--muted);
    margin-bottom: 6px;
}

.chat-message p {
    margin: 0;
    white-space: pre-wrap;
}

.alert {
    margin: 0 0 14px;
    padding: 12px;
    border-radius: 6px;
    white-space: pre-wrap;
}

.alert.success {
    background: #ecfdf3;
    color: #05603a;
    border: 1px solid #a6f4c5;
}

.alert.error {
    background: #fff1f3;
    color: #b42318;
    border: 1px solid #fecdca;
}

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

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

.auth-card h1 {
    margin: 0 0 14px;
}

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

@media (max-width: 980px) {
    .app {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
    }

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

    .content {
        padding: 18px;
    }

    .stats-grid,
    .form-grid,
    .split,
    .setup-card,
    .setup-fields {
        grid-template-columns: 1fr;
    }

    .labels-table .row,
    .usage-table .row,
    .group-table .row,
    .discovered-table .row,
    .task-table .row,
    .table:not(.labels-table):not(.usage-table):not(.group-table):not(.discovered-table):not(.task-table) .row,
    .kv,
    .check-list {
        grid-template-columns: 1fr;
    }

    .inline-wide {
        flex-direction: column;
    }
}
