:root {
    color-scheme: light;
    --bg: #f4f7f2;
    --ink: #1e2528;
    --muted: #617077;
    --line: #d8e0dc;
    --panel: #ffffff;
    --accent: #1f7a5a;
    --accent-strong: #15543f;
    --warn: #b45309;
    --danger: #b42318;
    --soft: #edf5f0;
    --bubble: #f6efe7;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.locked .shell {
    filter: blur(2px);
    pointer-events: none;
    user-select: none;
}

button,
input {
    font: inherit;
}

button {
    border: 0;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    min-height: 42px;
    padding: 0 16px;
    font-weight: 700;
}

button:hover {
    background: var(--accent-strong);
}

button:disabled {
    cursor: wait;
    opacity: .65;
}

.ghost {
    background: #e8eee9;
    color: var(--ink);
}

.ghost:hover {
    background: #d9e3dd;
}

.shell {
    width: min(1480px, calc(100vw - 32px));
    margin: 0 auto;
    padding: 24px 0;
}

.hidden {
    display: none !important;
}

.login-screen {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    background: rgba(244, 247, 242, .92);
    padding: 20px;
}

.login-box {
    width: min(420px, 100%);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 18px 50px rgba(32, 48, 46, .14);
    padding: 24px;
    display: grid;
    gap: 16px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

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

.user-pill {
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel);
    padding: 8px 12px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 30px;
    line-height: 1.1;
}

h2 {
    font-size: 18px;
}

p {
    color: var(--muted);
    margin-top: 4px;
}

.health {
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel);
    min-width: 116px;
    padding: 8px 12px;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.health.ok {
    color: var(--accent-strong);
    border-color: #a9d4bf;
    background: #edf8f1;
}

.health.fail {
    color: var(--danger);
    border-color: #f1b8b2;
    background: #fff1ef;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(340px, 460px) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 18px;
}

.tab {
    background: #e8eee9;
    color: var(--ink);
}

.tab.active {
    background: var(--accent);
    color: #fff;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 10px 24px rgba(32, 48, 46, .07);
}

.panel-head {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--line);
    padding: 18px;
}

.chat-panel {
    min-height: 720px;
    display: grid;
    grid-template-rows: auto auto 1fr auto;
}

.field {
    display: grid;
    gap: 7px;
    padding: 0;
}

.field span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.field input,
.composer input,
.inline-input {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    padding: 0 12px;
    outline: none;
}

.field input:focus,
.composer input:focus,
.inline-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(31, 122, 90, .14);
}

.check-field {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.check-field input {
    width: 18px;
    height: 18px;
}

.check-field.compact {
    min-height: 0;
}

.chat-panel > .field {
    padding: 16px 18px 0;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: auto;
    min-height: 380px;
    padding: 18px;
}

.message {
    max-width: 86%;
    border-radius: 8px;
    padding: 10px 12px;
    white-space: pre-wrap;
    line-height: 1.35;
    font-size: 14px;
}

.message.client {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
}

.message.bot {
    align-self: flex-start;
    background: var(--bubble);
    color: var(--ink);
}

.message.error {
    align-self: stretch;
    max-width: 100%;
    background: #fff1ef;
    color: var(--danger);
}

.composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    border-top: 1px solid var(--line);
    padding: 16px 18px;
}

.data-panel {
    overflow: hidden;
}

.filters {
    display: grid;
    grid-template-columns: minmax(220px, 1.2fr) minmax(130px, .6fr) minmax(130px, .6fr) auto;
    gap: 12px;
    align-items: end;
    padding: 18px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    padding: 0 18px 18px;
}

.metric {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--soft);
    padding: 14px;
}

.metric span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.metric strong {
    display: block;
    margin-top: 6px;
    font-size: 24px;
}

.table-wrap {
    overflow: auto;
    border-top: 1px solid var(--line);
}

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

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

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

.items-cell {
    max-width: 320px;
}

.status-paid {
    color: var(--accent-strong);
    font-weight: 800;
}

.status-pending {
    color: var(--warn);
    font-weight: 800;
}

.empty {
    color: var(--muted);
    text-align: center;
}

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

.form-panel {
    overflow: hidden;
}

.form-body,
.user-form {
    display: grid;
    gap: 12px;
    padding: 18px;
}

.user-form {
    grid-template-columns: minmax(160px, 1fr) minmax(180px, 1fr) minmax(160px, 1fr) auto auto;
    align-items: end;
    border-bottom: 1px solid var(--line);
}

.form-message {
    min-height: 20px;
    color: var(--accent-strong);
    font-size: 14px;
    font-weight: 700;
}

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

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

    .chat-panel {
        min-height: 620px;
    }

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

    .security-grid,
    .user-form {
        grid-template-columns: 1fr;
    }

    .filters button {
        grid-column: 1 / -1;
    }
}

@media (max-width: 620px) {
    .shell {
        width: min(100vw - 20px, 1480px);
        padding: 14px 0;
    }

    .topbar,
    .panel-head {
        align-items: stretch;
        flex-direction: column;
    }

    .filters,
    .summary-grid,
    .composer {
        grid-template-columns: 1fr;
    }

    h1 {
        font-size: 25px;
    }
}
