/*
 * Termobot — arkusz stylów aplikacji (makieta).
 * Bez frameworka i bez stylów w HTML: CSP pozwala tylko na style z własnej domeny.
 */

:root {
    --ink: #0f1f2a;
    --ink-2: #334155;
    --muted: #64748b;
    --line: #e2e8f0;
    --line-strong: #cbd5e1;
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-2: #f8fafc;

    --primary: #0f6b78;
    --primary-dark: #0b525c;
    --primary-soft: #e3f1f3;
    --heat: #e8590c;
    --dark: #0f2a33;

    --ok: #15803d;
    --ok-soft: #dcfce7;
    --warn: #b45309;
    --warn-soft: #fef3c7;
    --error: #b91c1c;
    --error-soft: #fee2e2;
    --info: #1d4ed8;
    --info-soft: #dbeafe;

    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 2px rgba(15, 31, 42, .06), 0 1px 3px rgba(15, 31, 42, .04);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.05rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 650; }
p { margin: 0; }

a { color: var(--primary); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--primary-dark); }

code {
    font-family: var(--mono);
    font-size: .85em;
    background: #eef2f6;
    padding: 1px 5px;
    border-radius: 4px;
}

small { font-size: .8rem; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.muted { color: var(--muted); }
.strong { font-weight: 600; }
.block { display: block; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ------------------------------------------------------------------ */
/* Marka                                                                */
/* ------------------------------------------------------------------ */

.brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 750;
    font-size: 1.1rem;
    letter-spacing: -.01em;
    color: inherit;
    text-decoration: none;
}
.brand:hover { color: inherit; }
.logo-mark { width: 28px; height: 28px; flex: none; }
.logo-bulb { fill: var(--heat); }
.brand-light { color: #fff; }

/* ------------------------------------------------------------------ */
/* Przyciski                                                            */
/* ------------------------------------------------------------------ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font: inherit;
    font-weight: 600;
    font-size: .9rem;
    line-height: 1.3;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color .12s, border-color .12s, color .12s;
}
.btn:disabled { cursor: not-allowed; opacity: .55; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--primary); border-color: var(--line-strong); }
.btn-secondary:hover { border-color: var(--primary); color: var(--primary-dark); }
.btn-ghost { background: transparent; color: inherit; border-color: transparent; }
.btn-ghost:hover { background: rgba(127, 127, 127, .12); color: inherit; }
.btn-danger { background: var(--surface); color: var(--error); border-color: #fca5a5; }
.btn-danger:hover:not(:disabled) { background: var(--error); color: #fff; border-color: var(--error); }
.btn-sm { padding: 5px 10px; font-size: .82rem; }
.btn-block { width: 100%; }

/* ------------------------------------------------------------------ */
/* Komunikaty i odznaki                                                 */
/* ------------------------------------------------------------------ */

.alert {
    margin-bottom: 16px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border-left: 4px solid;
    font-size: .92rem;
}
.alert-success { background: var(--ok-soft); border-color: var(--ok); color: #14532d; }
.alert-error { background: var(--error-soft); border-color: var(--error); color: #7f1d1d; }
.alert-warning { background: var(--warn-soft); border-color: var(--warn); color: #78350f; }
.alert-info { background: var(--info-soft); border-color: var(--info); color: #1e3a8a; }
.alert a { color: inherit; font-weight: 600; }

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.6em;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: .74rem;
    font-weight: 650;
    line-height: 1.6;
    white-space: nowrap;
    background: #eef2f6;
    color: var(--ink-2);
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-error { background: var(--error-soft); color: var(--error); }
.badge-warning { background: var(--warn-soft); color: var(--warn); }
.badge-muted { background: #eef2f6; color: var(--muted); }
.badge-status-draft { background: #eef2f6; color: var(--ink-2); }
.badge-status-calculated { background: var(--info-soft); color: var(--info); }
.badge-status-documents { background: var(--ok-soft); color: var(--ok); }
.badge-status-archived { background: #f1f5f9; color: var(--muted); }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }

/* ------------------------------------------------------------------ */
/* Formularze                                                           */
/* ------------------------------------------------------------------ */

input[type="text"],
input[type="password"],
input[type="email"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-size: .92rem;
    line-height: 1.35;
}
textarea { resize: vertical; min-height: 5.5em; }
select { padding-right: 6px; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 107, 120, .18);
}
input::placeholder, textarea::placeholder { color: #94a3b8; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; }

input.is-invalid, select.is-invalid, textarea.is-invalid,
.field.is-invalid input, .field.is-invalid select, .field.is-invalid textarea,
[aria-invalid="true"] {
    border-color: var(--error);
    background: #fffafa;
}

.stack { display: flex; flex-direction: column; gap: 16px; }

.field label {
    display: block;
    margin-bottom: 4px;
    font-size: .84rem;
    font-weight: 600;
    color: var(--ink-2);
}
.field-wide { grid-column: 1 / -1; }
.req { margin-left: 3px; color: var(--error); font-weight: 700; }

.control.has-unit { display: flex; flex-wrap: wrap; align-items: stretch; }
.control.has-unit input { flex: 1 1 0; min-width: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.control .unit {
    display: inline-flex;
    align-items: center;
    padding: 0 10px;
    border: 1px solid var(--line-strong);
    border-left: 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: var(--surface-2);
    color: var(--muted);
    font-size: .82rem;
    white-space: nowrap;
}
.control.has-unit .cell-error { flex-basis: 100%; order: 3; }

.check {
    display: inline-flex !important;
    align-items: center;
    gap: 8px;
    margin: 0 !important;
    padding: 8px 0;
    font-weight: 500 !important;
    cursor: pointer;
}

.help { margin-top: 4px; font-size: .8rem; color: var(--muted); }
.error-text { margin-top: 4px; font-size: .8rem; color: var(--error); font-weight: 600; }
.cell-error { display: block; margin-top: 2px; font-size: .74rem; color: var(--error); font-weight: 600; line-height: 1.3; }
.field .cell-error { font-size: .8rem; }

.grid-fields {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 14px 18px;
}

fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 4px; font-weight: 650; font-size: 1rem; }

.form-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sticky-actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin-top: 8px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, .96);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 -4px 12px rgba(15, 31, 42, .06);
}
.sticky-actions .muted { font-size: .84rem; }

.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { min-width: 320px; }

.danger-zone {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px dashed var(--line-strong);
    font-size: .85rem;
}

/* ------------------------------------------------------------------ */
/* Karty i tabele                                                       */
/* ------------------------------------------------------------------ */

.card {
    margin-bottom: 16px;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-flush { padding: 0; overflow: hidden; }
.card-header { margin-bottom: 14px; }
.card-header .help { max-width: 72ch; }
.card-flush .card-header { margin: 0; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.card-header-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card.empty { padding: 40px; text-align: center; }
.card.empty p { max-width: 60ch; margin: 8px auto 0; color: var(--muted); }

.empty-note { padding: 16px 20px; color: var(--muted); font-size: .9rem; }
.list-foot { padding: 10px 20px; border-top: 1px solid var(--line); font-size: .84rem; }

.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th {
    padding: 8px 12px;
    text-align: left;
    font-size: .76rem;
    font-weight: 650;
    color: var(--muted);
    background: var(--surface-2);
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.table td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table th.num { text-align: right; }
.table-compact td { padding: 7px 12px; }
.table-select tbody tr:hover td { background: var(--surface-2); }
.table-select tr.is-active td { background: var(--primary-soft); }
.table-select tr.is-active a { font-weight: 650; color: var(--primary-dark); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); margin-top: 8px; }
.table-input td { padding: 4px 6px; vertical-align: top; }
.table-input th { padding: 7px 6px; }
.table-input input, .table-input select { padding: 5px 7px; font-size: .86rem; }
.table-input td.num, .table-input td.col-lp { padding-top: 10px; }
.col-lp { width: 3rem; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.col-num { width: 8.5rem; }
.col-int { width: 5.5rem; }
.col-check { width: 3.5rem; text-align: center; }
td.col-check { padding-top: 10px !important; }
.table-input .col-num input, .table-input .col-int input { text-align: right; }

/* ------------------------------------------------------------------ */
/* Układ aplikacji                                                      */
/* ------------------------------------------------------------------ */

body.app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 28px;
    height: 56px;
    padding: 0 20px;
    background: var(--dark);
    color: #fff;
}
.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    color: rgba(255, 255, 255, .75);
    text-decoration: none;
    font-weight: 550;
    font-size: .92rem;
}
.topnav a:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.topnav a.is-active { color: #fff; background: rgba(255, 255, 255, .12); }
.account { display: flex; align-items: center; gap: 12px; }
.account form { margin: 0; }
.account-name { text-align: right; font-size: .88rem; font-weight: 600; line-height: 1.2; }
.account-name small { display: block; font-weight: 400; color: rgba(255, 255, 255, .65); font-size: .75rem; }
.topbar .btn-ghost { color: rgba(255, 255, 255, .85); border-color: rgba(255, 255, 255, .25); }
.topbar .btn-ghost:hover { color: #fff; background: rgba(255, 255, 255, .1); }

.page { flex: 1; width: 100%; max-width: 1200px; margin: 0 auto; padding: 28px 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }

.shell { flex: 1; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar {
    padding: 20px 12px;
    background: var(--surface);
    border-right: 1px solid var(--line);
}
.main { min-width: 0; padding: 24px 32px 32px; max-width: 1320px; }

.steps ul { list-style: none; margin: 0 0 16px; padding: 0; }
.steps-group {
    margin: 0 0 6px;
    padding: 0 12px;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
}
.step {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--ink-2);
    text-decoration: none;
    font-size: .92rem;
    font-weight: 550;
}
.step:hover { background: var(--surface-2); color: var(--ink); }
.step.is-active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 650; }

.project-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.crumbs { margin-bottom: 4px; font-size: .84rem; color: var(--muted); }
.crumbs a { color: var(--muted); }
.project-meta { display: flex; gap: 20px; margin: 0; }
.project-meta dt { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.project-meta dd { margin: 0; font-family: var(--mono); font-size: .85rem; font-weight: 600; }

.footer { padding: 16px; text-align: center; font-size: .78rem; color: var(--muted); }

/* Lista + szczegóły (przegrody, strefy) */
.split { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 16px; align-items: start; }
.split .card { margin-bottom: 0; }
.split-list { position: sticky; top: 72px; }
.split-detail.placeholder { padding: 48px 32px; text-align: center; }
.split-detail.placeholder p { max-width: 56ch; margin: 8px auto 0; }

.result-inline {
    display: flex;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
    padding: 12px 16px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
}
.result-inline dl { display: flex; gap: 28px; margin: 0; }
.result-inline dt { font-size: .78rem; color: var(--muted); }
.result-inline dd { margin: 0; font-size: 1.15rem; font-weight: 700; }
.result-inline .help { margin: 0; }

/* ------------------------------------------------------------------ */
/* Wyniki                                                               */
/* ------------------------------------------------------------------ */

.engine { display: flex; align-items: center; justify-content: space-between; gap: 20px; border-left: 4px solid; }
.engine > div { display: flex; flex-direction: column; gap: 4px; }
.engine .muted { font-size: .85rem; }
.engine-off { border-left-color: var(--warn); }
.engine-ok { border-left-color: var(--ok); }

.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.kpi {
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.kpi-symbol { font-weight: 750; color: var(--primary); font-size: 1rem; }
.kpi-value { margin-top: 6px; font-size: 2rem; font-weight: 750; line-height: 1.1; color: var(--line-strong); }
.kpi-unit { font-size: .8rem; color: var(--muted); }
.kpi-label { margin-top: 8px; font-size: .8rem; color: var(--ink-2); }

.ep-scale { padding: 4px 0; }
.ep-bar {
    height: 18px;
    border-radius: 999px;
    background: linear-gradient(90deg, #15803d 0%, #65a30d 22%, #eab308 45%, #f97316 68%, #dc2626 100%);
    opacity: .35;
}
.ep-ticks { display: flex; justify-content: space-between; margin-top: 6px; font-size: .78rem; color: var(--muted); }
.ep-empty { margin-top: 8px; text-align: center; font-size: .88rem; color: var(--muted); }

.section-title { margin: 24px 0 12px; }
.doc-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-bottom: 16px; }
.doc-tile {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.doc-tile p { font-size: .86rem; color: var(--ink-2); }
.doc-tile.is-locked { background: var(--surface-2); border-style: dashed; }
.doc-tile .doc-lock { margin-top: auto; padding-top: 8px; font-size: .8rem; color: var(--muted); font-weight: 600; }

.model-json summary { cursor: pointer; font-weight: 650; }
.model-json pre {
    max-height: 520px;
    margin: 14px 0 0;
    padding: 14px;
    overflow: auto;
    background: #0f172a;
    color: #e2e8f0;
    border-radius: var(--radius-sm);
    font-size: .8rem;
    line-height: 1.45;
}
.model-json pre code { background: none; padding: 0; font-size: inherit; color: inherit; }

/* ------------------------------------------------------------------ */
/* Logowanie i strony błędów                                            */
/* ------------------------------------------------------------------ */

body.auth { background: var(--surface); }
.auth-wrap { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); min-height: 100vh; }
.auth-brand {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 40px;
    padding: 40px 56px;
    color: #fff;
    background:
        radial-gradient(circle at 85% 15%, rgba(232, 89, 12, .28), transparent 45%),
        linear-gradient(160deg, #0f2a33 0%, #0f4c56 60%, #0f6b78 100%);
}
.auth-pitch { max-width: 460px; }
.auth-pitch h2 { font-size: 2.1rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.15; }
.auth-list { list-style: none; margin: 28px 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.auth-list li { position: relative; padding-left: 28px; font-size: 1rem; }
.auth-list li::before {
    content: "";
    position: absolute;
    left: 0;
    top: .3em;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--heat);
    box-shadow: inset 0 0 0 4px rgba(255, 255, 255, .85);
}
.auth-note { font-size: .9rem; color: rgba(255, 255, 255, .78); }
.auth-foot { font-size: .8rem; color: rgba(255, 255, 255, .6); }

.auth-panel { display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 40px 24px; }
.auth-panel > .alert { width: 100%; max-width: 380px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 1.6rem; }
.auth-card > .muted { margin: 4px 0 24px; }
.auth-card .alert { margin-bottom: 16px; }
.auth-card input { padding: 10px 12px; font-size: 1rem; }
.auth-card .btn-block { margin-top: 4px; padding: 11px 16px; font-size: 1rem; }
.auth-help { margin-top: 24px; font-size: .82rem; color: var(--muted); }
.error-code { font-size: 3.2rem; font-weight: 800; line-height: 1; color: var(--primary); margin-bottom: 8px; }
.error-message { margin: 12px 0 24px; color: var(--ink-2); }

/* ------------------------------------------------------------------ */
/* Węższe ekrany                                                        */
/* ------------------------------------------------------------------ */

@media (max-width: 1100px) {
    .split { grid-template-columns: minmax(0, 1fr); }
    .split-list { position: static; }
}

@media (max-width: 860px) {
    .shell { grid-template-columns: minmax(0, 1fr); }
    .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
    .steps { display: flex; flex-wrap: wrap; gap: 4px 16px; }
    .steps ul { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
    .steps-group { width: 100%; margin-top: 4px; }
    .main { padding: 20px 16px; }
    .auth-wrap { grid-template-columns: minmax(0, 1fr); }
    .auth-brand { padding: 24px; gap: 16px; }
    .auth-pitch, .auth-foot { display: none; }
    .account-name { display: none; }
    .inline-form { width: 100%; }
    .inline-form input { min-width: 0; flex: 1; }
    .project-meta { display: none; }
}

@media print {
    .topbar, .sidebar, .footer, .sticky-actions, .danger-zone { display: none; }
    .shell { display: block; }
    .card { box-shadow: none; }
}
