/*
 * Sokół Millennium - panel kolejki zabezpieczeń.
 * Kierunek: pulpit kontroli lotu. Kadłub (złamana biel), konsola (granat),
 * napęd (błękit - jedyny akcent), czerwień paneli tylko dla zatrzymania/błędów.
 * Głębia: pierścień 1px + obramowania o niskim kontraście. Siatka 4px, skala typografii 1.25.
 */

:root {
    /* kadłub - powierzchnie */
    --hull: #f4f2ed;
    --hull-panel: #fcfbf9;
    --hull-inset: #eeebe4;
    --hull-hover: #f0ede6;

    /* konsola - tekst */
    --console: #1c2733;
    --console-2: #46515e;
    --console-3: #6f7883;
    --console-4: #a3aab2;

    /* szwy - obramowania */
    --seam: rgba(28, 39, 51, 0.09);
    --seam-soft: rgba(28, 39, 51, 0.06);
    --seam-strong: rgba(28, 39, 51, 0.16);
    --panel-ring: 0 0 0 1px rgba(28, 39, 51, 0.07), 0 1px 2px -1px rgba(28, 39, 51, 0.06), 0 2px 4px rgba(28, 39, 51, 0.03);

    /* napęd - akcent */
    --thrust: #2f8fbf;
    --thrust-strong: #23739b;
    --thrust-glow: #7fd3f0;
    --thrust-wash: rgba(47, 143, 191, 0.10);
    --focus-ring: 0 0 0 3px rgba(47, 143, 191, 0.28);

    /* sygnały */
    --hull-red: #b3372e;
    --hull-red-wash: rgba(179, 55, 46, 0.09);
    --signal-amber: #b57a10;
    --signal-amber-wash: rgba(181, 122, 16, 0.11);

    /* koszyki decyzji (wykresy i proporcje) */
    --basket-accepted: #3f8f6f;
    --basket-accepted-deep: #2c6b52;
    --basket-selling: #c9922a;
    --basket-selling-deep: #9c6d15;
    --basket-consent: #5b7fa6;

    /* typografia */
    --font-sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
    --text-caption: 11px;
    --text-body: 14px;
    --text-h4: 16px;
    --text-h3: 18px;
    --text-h2: 22px;
    --text-h1: 28px;
    --text-display: 44px;

    /* promienie */
    --radius-control: 6px;
    --radius-panel: 10px;
    --radius-dialog: 14px;

    --ease-out: cubic-bezier(0.23, 1, 0.32, 1);

    /* Bootstrap - powiązanie z tokenami */
    --bs-body-font-family: var(--font-sans);
    --bs-body-font-size: var(--text-body);
    --bs-body-line-height: 1.5;
    --bs-body-color: var(--console);
    --bs-body-bg: var(--hull);
    --bs-border-color: var(--seam);
    --bs-secondary-color: var(--console-3);
    --bs-link-color: var(--thrust-strong);
    --bs-link-hover-color: var(--thrust);
    --bs-emphasis-color: var(--console);
}

html { -webkit-font-smoothing: antialiased; }

body {
    font-family: var(--font-sans);
    font-size: var(--text-body);
    color: var(--console);
    background: var(--hull);
}

h1, h2, h3, h4, h5, h6 { color: var(--console); text-wrap: balance; }

.mono, .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- top bar */

.deck-bar {
    position: sticky;
    top: 0;
    z-index: 1020;
    background: var(--hull);
    border-bottom: 1px solid var(--seam);
}

.deck-bar-inner {
    display: flex;
    align-items: center;
    gap: 32px;
    height: 56px;
}

.deck-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--console);
    text-decoration: none;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.deck-brand:hover { color: var(--console); }

.deck-brand-mark {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--console);
    display: grid;
    place-items: center;
}

.deck-brand-mark::after {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--thrust-glow);
}

.deck-env {
    font-family: var(--font-mono);
    font-size: var(--text-caption);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--console-3);
    box-shadow: inset 0 0 0 1px var(--seam-strong);
}

.deck-env[data-env="prod"] { color: var(--hull-red); box-shadow: inset 0 0 0 1px rgba(179, 55, 46, 0.35); }
.deck-env[data-env="test"] { color: var(--signal-amber); box-shadow: inset 0 0 0 1px rgba(181, 122, 16, 0.35); }

.deck-nav { display: flex; align-items: stretch; gap: 4px; height: 100%; }

.deck-nav a {
    display: flex;
    align-items: center;
    padding: 0 12px;
    color: var(--console-3);
    font-weight: 500;
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 150ms var(--ease-out);
}

.deck-nav a:hover { color: var(--console); }
.deck-nav a[aria-current="page"] { color: var(--console); border-bottom-color: var(--thrust); }

.deck-logout { margin-left: auto; }

/* ---------------------------------------------------------------- layout */

.deck { padding-top: 32px; padding-bottom: 64px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-title { font-size: var(--text-h1); font-weight: 600; letter-spacing: -0.02em; margin: 0; }
.page-subtitle { color: var(--console-3); margin: 4px 0 0; }

.section-label {
    font-size: var(--text-caption);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--console-3);
    margin: 0 0 12px;
}

.panel {
    background: var(--hull-panel);
    border-radius: var(--radius-panel);
    box-shadow: var(--panel-ring);
    padding: 20px;
}

.panel + .panel, .panel-stack > * + * { margin-top: 16px; }

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel-title { font-size: var(--text-h4); font-weight: 600; margin: 0; }
.panel-meta { color: var(--console-3); font-size: 12px; }

/* ---------------------------------------------------------------- controls */

.btn {
    --bs-btn-font-weight: 500;
    --bs-btn-font-size: var(--text-body);
    --bs-btn-padding-y: 7px;
    --bs-btn-padding-x: 14px;
    --bs-btn-border-radius: var(--radius-control);
    transition: background-color 150ms var(--ease-out), color 150ms var(--ease-out), box-shadow 150ms var(--ease-out), transform 120ms var(--ease-out);
}

.btn:active { transform: scale(0.97); }
.btn:focus-visible { box-shadow: var(--focus-ring); }

.btn-primary {
    --bs-btn-bg: var(--thrust-strong);
    --bs-btn-border-color: var(--thrust-strong);
    --bs-btn-hover-bg: #1d6284;
    --bs-btn-hover-border-color: #1d6284;
    --bs-btn-active-bg: #1d6284;
    --bs-btn-active-border-color: #1d6284;
    --bs-btn-disabled-bg: var(--thrust-strong);
    --bs-btn-disabled-border-color: var(--thrust-strong);
}

.btn-quiet {
    --bs-btn-color: var(--console-2);
    --bs-btn-bg: transparent;
    --bs-btn-border-color: var(--seam-strong);
    --bs-btn-hover-color: var(--console);
    --bs-btn-hover-bg: var(--hull-hover);
    --bs-btn-hover-border-color: var(--seam-strong);
    --bs-btn-active-color: var(--console);
    --bs-btn-active-bg: var(--hull-inset);
    --bs-btn-active-border-color: var(--seam-strong);
}

.btn-stop {
    --bs-btn-color: var(--hull-red);
    --bs-btn-bg: transparent;
    --bs-btn-border-color: rgba(179, 55, 46, 0.4);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--hull-red);
    --bs-btn-hover-border-color: var(--hull-red);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: #97291f;
    --bs-btn-active-border-color: #97291f;
}

.btn-sm { --bs-btn-padding-y: 4px; --bs-btn-padding-x: 10px; --bs-btn-font-size: 13px; }

.form-label { font-size: 13px; font-weight: 500; color: var(--console-2); margin-bottom: 6px; }

.form-control, .form-select {
    font-size: var(--text-body);
    color: var(--console);
    background-color: var(--hull-inset);
    border: 1px solid transparent;
    border-radius: var(--radius-control);
    padding: 8px 12px;
    transition: border-color 150ms var(--ease-out), box-shadow 150ms var(--ease-out), background-color 150ms var(--ease-out);
}

.form-control:hover, .form-select:hover { border-color: var(--seam-strong); }

.form-control:focus, .form-select:focus {
    background-color: var(--hull-panel);
    border-color: var(--thrust);
    box-shadow: var(--focus-ring);
    color: var(--console);
}

.form-control::placeholder { color: var(--console-4); }
.form-hint { font-size: 12px; color: var(--console-3); margin-top: 6px; }

.invalid-feedback { font-size: 12px; color: var(--hull-red); }

/* segmentowy przełącznik (zakresy dat, zakładki wykresów) */
.segmented {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    border-radius: 8px;
    background: var(--hull-inset);
}

.segmented button, .segmented .nav-link {
    border: 0;
    background: transparent;
    color: var(--console-3);
    font-size: 13px;
    font-weight: 500;
    padding: 5px 12px;
    border-radius: var(--radius-control);
    transition: color 150ms var(--ease-out), background-color 150ms var(--ease-out), box-shadow 150ms var(--ease-out);
}

.segmented button:hover, .segmented .nav-link:hover { color: var(--console); }

.segmented .nav-link.active, .segmented button.active {
    background: var(--hull-panel);
    color: var(--console);
    box-shadow: var(--panel-ring);
}

/* zakładki z podkreśleniem (ustawienia) */
.deck-tabs { border-bottom: 1px solid var(--seam); gap: 4px; margin-bottom: 24px; }

.deck-tabs .nav-link {
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    background: none;
    color: var(--console-3);
    font-weight: 500;
    padding: 10px 12px;
    margin-bottom: -1px;
}

.deck-tabs .nav-link:hover { color: var(--console); }
.deck-tabs .nav-link.active { color: var(--console); border-bottom-color: var(--thrust); background: none; }

/* ---------------------------------------------------------------- tables */

.deck-table { width: 100%; margin: 0; border-collapse: collapse; }

.deck-table th {
    font-size: var(--text-caption);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--console-3);
    padding: 0 12px 10px;
    text-align: left;
    border-bottom: 1px solid var(--seam);
}

.deck-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--seam-soft);
    vertical-align: middle;
}

.deck-table tbody tr:last-child td { border-bottom: 0; }
.deck-table tbody tr:hover td { background: var(--hull-hover); }
.deck-table .empty-row td { color: var(--console-3); text-align: center; padding: 24px 12px; }
.deck-table .empty-row:hover td { background: none; }
.deck-table .col-action { text-align: right; width: 1%; white-space: nowrap; }

/* ---------------------------------------------------------------- status chips */

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--hull-inset);
    color: var(--console-2);
    white-space: nowrap;
}

.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.chip-done { color: var(--basket-accepted-deep); background: rgba(63, 143, 111, 0.12); }
.chip-running { color: var(--thrust-strong); background: var(--thrust-wash); }
.chip-failed { color: var(--hull-red); background: var(--hull-red-wash); }
.chip-queued { color: var(--console-3); }

/* ---------------------------------------------------------------- notices */

.notice {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 14px;
    border-radius: var(--radius-control);
    font-size: 13px;
    margin-bottom: 16px;
    background: var(--hull-panel);
    box-shadow: var(--panel-ring);
}

.notice::before { content: ""; flex: 0 0 3px; align-self: stretch; border-radius: 2px; background: var(--console-4); }
.notice-success::before { background: var(--basket-accepted); }
.notice-error { color: var(--hull-red); }
.notice-error::before { background: var(--hull-red); }

.toast {
    --bs-toast-bg: var(--hull-panel);
    --bs-toast-border-color: transparent;
    --bs-toast-border-radius: var(--radius-panel);
    --bs-toast-font-size: 13px;
    box-shadow: var(--panel-ring), 0 8px 24px rgba(28, 39, 51, 0.10);
    color: var(--console);
}

.toast.is-success { border-left: 3px solid var(--basket-accepted); }
.toast.is-error { border-left: 3px solid var(--hull-red); }

/* ---------------------------------------------------------------- flight status (pulpit) */

.flight {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr) minmax(0, 420px);
    gap: 0;
    padding: 0;
    overflow: hidden;
}

.flight-ship {
    position: relative;
    background: #fff;
    display: grid;
    place-items: center;
    padding: 20px;
    border-right: 1px solid var(--seam-soft);
}

.flight-ship img { width: 100%; max-width: 200px; height: auto; }

.flight[data-state="flying"] .flight-ship img { animation: cruise 4s var(--ease-out) infinite alternate; }

@keyframes cruise {
    from { transform: translate3d(0, 0, 0); }
    to { transform: translate3d(-3px, -2px, 0); }
}

.flight-state { padding: 24px 28px; display: flex; flex-direction: column; justify-content: center; gap: 4px; }

.flight-kicker {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: var(--text-caption);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--console-3);
}

.flight-lamp { width: 8px; height: 8px; border-radius: 50%; background: var(--signal-amber); }
.flight[data-state="flying"] .flight-lamp { background: var(--thrust); box-shadow: 0 0 0 4px var(--thrust-wash); }
.flight[data-state="offline"] .flight-lamp { background: var(--hull-red); }

.flight-title { font-size: var(--text-h1); font-weight: 600; letter-spacing: -0.02em; margin: 0; }
.flight-desc { color: var(--console-2); margin: 0 0 12px; }
.flight-actions { display: flex; gap: 8px; align-items: center; }
.flight-actions .btn:disabled { display: none; }
.flight-msg { font-size: 12px; color: var(--console-3); min-height: 18px; margin-top: 8px; }
.flight-msg.is-error { color: var(--hull-red); }

/* pasek napędu - pojawia się, gdy robot pracuje */
.flight-thrust { grid-column: 1 / -1; height: 3px; background: var(--seam-soft); overflow: hidden; }
.flight[data-state="flying"] .flight-thrust {
    background: linear-gradient(90deg, transparent 0%, var(--thrust-glow) 45%, var(--thrust) 55%, transparent 100%);
    background-size: 40% 100%;
    background-repeat: no-repeat;
    animation: thrust 2.4s linear infinite;
}
.flight[data-state="offline"] .flight-thrust { background: var(--hull-red); }

@keyframes thrust {
    from { background-position: 160% 0; }
    to { background-position: -60% 0; }
}

.flight-telemetry {
    border-left: 1px solid var(--seam-soft);
    display: grid;
    grid-template-columns: 1fr 1fr;
}

.telemetry {
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.telemetry:nth-child(odd) { border-right: 1px solid var(--seam-soft); }
.telemetry:nth-child(-n+2) { border-bottom: 1px solid var(--seam-soft); }

.telemetry-label { font-size: 12px; font-weight: 500; color: var(--console-3); }
.telemetry-value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: var(--text-h1); font-weight: 500; line-height: 1.15; }
.telemetry-value.is-hero { font-size: var(--text-display); font-weight: 500; letter-spacing: -0.02em; }
.telemetry[data-attention="true"] .telemetry-value { color: var(--signal-amber); }

/* na pokładzie - aktualnie przetwarzane */
.aboard { display: flex; flex-wrap: wrap; gap: 8px; }

.aboard-item {
    font-family: var(--font-mono);
    font-size: 13px;
    padding: 6px 10px;
    border-radius: var(--radius-control);
    background: var(--thrust-wash);
    color: var(--thrust-strong);
    animation: board 240ms var(--ease-out);
}

@keyframes board { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }

.aboard-empty { color: var(--console-3); }

/* decyzje - proporcje koszyków */
.decisions { display: grid; grid-template-columns: minmax(0, 220px) minmax(0, 1fr); gap: 32px; align-items: center; }
.decisions-total .telemetry-value { font-size: var(--text-display); }
.decisions-today { font-size: 13px; color: var(--console-2); margin-top: 4px; }
.decisions-today .num { color: var(--console); font-weight: 500; }

.basket-bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--hull-inset); gap: 2px; }
.basket-bar span { display: block; height: 100%; transition: flex-grow 400ms var(--ease-out); flex-grow: 0; flex-basis: 0; }
.basket-bar .is-accepted { background: var(--basket-accepted); }
.basket-bar .is-selling { background: var(--basket-selling); }
.basket-bar .is-consent { background: var(--basket-consent); }

.basket-legend { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.basket-legend-item { display: flex; flex-direction: column; gap: 2px; }
.basket-legend-label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--console-3); font-weight: 500; }
.basket-legend-label::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--swatch); }
.basket-legend-value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: var(--text-h3); font-weight: 500; }
.basket-legend-share { font-size: 12px; color: var(--console-3); font-family: var(--font-mono); }

.durations { display: flex; flex-wrap: wrap; gap: 8px 24px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--seam-soft); font-size: 13px; color: var(--console-3); }
.durations .num { color: var(--console); font-weight: 500; margin-left: 6px; white-space: nowrap; }

/* historia - wykresy */
.chart-area { position: relative; height: 320px; }
.chart-area.is-short { height: 260px; }
.chart-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.chart-controls .form-control { width: auto; padding-top: 5px; padding-bottom: 5px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 12px; font-size: 12px; color: var(--console-3); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend span::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--swatch); }

/* ---------------------------------------------------------------- logowanie */

.hangar {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px 16px;
}

.hangar-card {
    width: 100%;
    max-width: 380px;
    background: var(--hull-panel);
    border-radius: var(--radius-dialog);
    box-shadow: var(--panel-ring), 0 12px 32px rgba(28, 39, 51, 0.08);
    overflow: hidden;
}

.hangar-ship { background: #fff; padding: 28px 40px 12px; border-bottom: 1px solid var(--seam-soft); }
.hangar-ship img { width: 100%; height: auto; display: block; }
.hangar-body { padding: 24px 28px 28px; }
.hangar-title { font-size: var(--text-h2); font-weight: 600; letter-spacing: -0.01em; margin: 0; }
.hangar-subtitle { color: var(--console-3); margin: 2px 0 20px; }
.hangar-body .btn { width: 100%; margin-top: 8px; padding-top: 9px; padding-bottom: 9px; }
.hangar-foot { text-align: center; margin-top: 16px; font-size: 12px; color: var(--console-4); }

/* ---------------------------------------------------------------- responsywność */

@media (max-width: 991.98px) {
    .flight { grid-template-columns: 180px minmax(0, 1fr); }
    .flight-telemetry { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--seam-soft); grid-template-columns: repeat(4, 1fr); }
    .telemetry:nth-child(-n+2) { border-bottom: 0; }
    .telemetry { border-right: 1px solid var(--seam-soft); }
    .telemetry:last-child { border-right: 0; }
    .decisions { grid-template-columns: 1fr; gap: 16px; }
}

@media (max-width: 575.98px) {
    .deck-bar-inner { gap: 8px; }
    .deck-brand-text, .deck-env { display: none; }
    .deck-nav a { padding: 0 8px; }
    .flight { grid-template-columns: 1fr; }
    .flight-ship { border-right: 0; border-bottom: 1px solid var(--seam-soft); }
    .flight-telemetry { grid-template-columns: 1fr 1fr; }
    .telemetry:nth-child(even) { border-right: 0; }
    .basket-legend { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    .flight[data-state="flying"] .flight-ship img, .flight[data-state="flying"] .flight-thrust, .aboard-item { animation: none; }
    .flight[data-state="flying"] .flight-thrust { background: var(--thrust); }
    .btn:active { transform: none; }
}

/* ---------------------------------------------------------------- raporty */

.report-error {
    display: inline-block;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
    font-size: 12px;
    color: var(--hull-red);
}

/* ---------------------------------------------------------------- ustawienia */

.settings-panel { max-width: 880px; }
.settings-panel .panel-head { align-items: flex-start; }
.settings-panel .panel-meta { max-width: 560px; }
.settings-actions { display: flex; justify-content: flex-end; padding-top: 16px; margin-top: 4px; border-top: 1px solid var(--seam-soft); }
