:root {
    --bg: #f5f7fa;
    --panel: #ffffff;
    --panel-soft: #f9fbfc;
    --border: #d9e1e8;
    --text: #111827;
    --muted: #607080;
    --accent: #0f766e;
    --accent-dark: #115e59;
    --warning: #b45309;
    --danger: #b91c1c;
    --success: #15803d;
    --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

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

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

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

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

button:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

label {
    display: block;
    margin: 16px 0 7px;
    color: #334155;
    font-size: 13px;
    font-weight: 800;
}

select,
input,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: #ffffff;
    color: var(--text);
    outline: none;
}

select,
input {
    height: 44px;
    padding: 0 12px;
}

textarea {
    min-height: 520px;
    resize: vertical;
    padding: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
}

select:focus,
input:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.13);
}

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

.login-panel {
    width: min(420px, 100%);
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
    padding: 30px;
}

.brand-mark {
    display: grid;
    width: 48px;
    height: 48px;
    place-items: center;
    border-radius: 8px;
    background: #0f766e;
    color: #ffffff;
    font-weight: 900;
}

.login-panel h1,
.topbar h1,
.panel-head h2 {
    margin: 0;
}

.login-panel h1 {
    margin-top: 18px;
    font-size: 26px;
}

.muted,
.panel-head p,
#resultMeta {
    color: var(--muted);
}

.login-form button {
    width: 100%;
    margin-top: 18px;
}

.app-shell {
    width: min(1500px, calc(100% - 36px));
    margin: 0 auto;
    padding: 22px 0 30px;
}

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

.eyebrow {
    margin-bottom: 3px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0;
    text-transform: uppercase;
}

.topbar h1 {
    font-size: 24px;
}

.topbar-actions,
.form-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logout-link,
.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    border-radius: 7px;
    padding: 0 11px;
    font-size: 13px;
    font-weight: 800;
    text-decoration: none;
}

.logout-link {
    border: 1px solid var(--border);
    color: #334155;
    background: #ffffff;
}

.status-pill {
    border: 1px solid var(--border);
    background: #ffffff;
    color: var(--muted);
}

.status-ok {
    border-color: rgba(21, 128, 61, 0.25);
    background: #ecfdf3;
    color: var(--success);
}

.status-warn {
    border-color: rgba(180, 83, 9, 0.25);
    background: #fff7ed;
    color: var(--warning);
}

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

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

.panel-head {
    display: flex;
    min-height: 46px;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 14px;
}

.panel-head h2 {
    font-size: 18px;
}

.panel-head p {
    margin: 4px 0 0;
    font-size: 13px;
}

.counter {
    border-radius: 7px;
    background: var(--panel-soft);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    padding: 7px 9px;
    white-space: nowrap;
}

.form-actions {
    margin-top: 14px;
}

.history-panel {
    margin-top: 18px;
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.history-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.history-head h2 {
    margin: 0;
    font-size: 16px;
}

.history-head p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.history-list {
    display: grid;
    max-height: 310px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
}

.history-list.empty-state {
    display: block;
}

.recover-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    margin-bottom: 10px;
}

.recover-form input {
    height: 38px;
    font-size: 13px;
}

.history-row {
    display: grid;
    width: 100%;
    min-height: auto;
    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    background: #ffffff;
    color: var(--text);
    gap: 3px;
    padding: 10px 12px;
    text-align: left;
}

.history-row:hover {
    background: var(--panel-soft);
}

.history-row:last-child {
    border-bottom: 0;
}

.history-row strong {
    font-size: 13px;
}

.history-row span,
.history-row small {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.secondary-button {
    border: 1px solid var(--border);
    background: #ffffff;
    color: #334155;
}

.secondary-button:hover {
    background: #f1f5f9;
}

.compact-button {
    min-height: 34px;
    padding: 0 12px;
    font-size: 13px;
}

.message-area {
    min-height: 44px;
    padding-top: 14px;
}

.alert {
    border-radius: 7px;
    padding: 11px 12px;
    font-size: 14px;
    font-weight: 700;
}

.alert-info {
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    color: #1d4ed8;
}

.alert-success {
    border: 1px solid #bbf7d0;
    background: #f0fdf4;
    color: var(--success);
}

.alert-warning {
    border: 1px solid #fed7aa;
    background: #fff7ed;
    color: var(--warning);
}

.alert-error {
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: var(--danger);
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
}

.tab-button {
    min-height: 34px;
    border: 1px solid var(--border);
    background: #ffffff;
    color: #334155;
    padding: 0 12px;
    font-size: 13px;
}

.tab-button.active {
    border-color: rgba(15, 118, 110, 0.35);
    background: #ecfdf5;
    color: var(--accent-dark);
}

.tab-panels {
    padding-top: 14px;
}

.tab-panel {
    display: none;
}

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

.code-block {
    min-height: 500px;
    max-height: 660px;
    overflow: auto;
    margin: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #0f172a;
    color: #e5eef8;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 13px;
    line-height: 1.55;
    padding: 16px;
    white-space: pre-wrap;
    word-break: break-word;
}

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

table {
    width: 100%;
    min-width: 780px;
    border-collapse: collapse;
    background: #ffffff;
}

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

th {
    background: var(--panel-soft);
    color: #334155;
    font-weight: 900;
}

.empty-state {
    border: 1px dashed var(--border);
    border-radius: 8px;
    color: var(--muted);
    padding: 18px;
}

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

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

.insight-grid.empty-state {
    display: block;
}

.insight-card {
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
    overflow: hidden;
}

.insight-card h3 {
    margin: 0;
    border-bottom: 1px solid var(--border);
    background: var(--panel-soft);
    color: #334155;
    font-size: 13px;
    padding: 10px 12px;
}

.insight-card pre {
    max-height: 280px;
    overflow: auto;
    margin: 0;
    color: #111827;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 12px;
    line-height: 1.45;
    padding: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}

.issue-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
    padding: 12px;
}

.issue-row strong,
.issue-row span {
    display: block;
}

.issue-row span {
    margin-top: 4px;
    color: var(--muted);
    font-size: 13px;
}

.issue-row small {
    border-radius: 7px;
    background: var(--panel-soft);
    color: #334155;
    font-weight: 800;
    padding: 5px 8px;
    white-space: nowrap;
}

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

    textarea {
        min-height: 360px;
    }

    .code-block {
        min-height: 360px;
    }

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

@media (max-width: 640px) {
    .app-shell {
        width: min(100% - 20px, 1500px);
        padding-top: 12px;
    }

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

    .topbar-actions,
    .form-actions,
    .recover-form {
        width: 100%;
    }

    .topbar-actions > *,
    .form-actions > *,
    .recover-form > * {
        width: 100%;
        justify-content: center;
    }
}
