/* Aplikacyjne uzupełnienia ponad design tokens (krs-analyzer.css).
 * Tu lądują rzeczy nieobjęte handoff'em: dropdown menu profilu, drobne polifiile. */

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    font-family: var(--ff-sans);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body.app {
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.45;
}

a { color: inherit; }
button { font-family: inherit; }

/* Anchor jako .btn-* — domyślny .app a { color: brand-700 } wygrywał z .btn-primary
   przez większą specyficzność. Wymuszamy poprawne kolory dla button-anchorów. */
.app a.btn, .app a.btn:hover { text-decoration: none; }
.app .btn-primary, .app a.btn-primary,
.app .btn-primary:hover, .app a.btn-primary:hover { color: #fff; }
.app .btn-secondary, .app a.btn-secondary { color: var(--ink); }
.app .btn-ghost, .app a.btn-ghost { color: var(--muted); }
.app .btn-ghost:hover, .app a.btn-ghost:hover { color: var(--ink); }

/* ── UserMenu (dropdown z avatarem) ────────────────────── */
.user-menu-wrap {
    position: relative;
}
.topbar .user {
    cursor: pointer;
    border: 0;
    padding: 0;
    font-family: var(--ff-mono);
    transition: background .12s;
}
.topbar .user:hover {
    background: rgba(255,255,255,.24);
}

/* Ikona w topbarze (zębatka, dzwonek itp.) — guzik z hover effectem */
.topbar .topbar-icon-btn {
    width: 32px; height: 32px;
    display: grid; place-items: center;
    border: 0; background: transparent;
    color: rgba(255,255,255,.78);
    border-radius: 5px;
    cursor: pointer;
    transition: background .12s, color .12s;
}
.topbar .topbar-icon-btn:hover {
    background: rgba(255,255,255,.12);
    color: #fff;
}

/* Input w dialogu/SettingsMenu — wymuszamy kolory bo Bootstrap form-control
   bywał nadpisywany na biały tekst przy theme-bright. */
.dialog-input {
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-size: 13.5px;
    transition: border-color .12s, box-shadow .12s;
}
.dialog-input:focus {
    outline: 0;
    border-color: var(--brand-600);
    box-shadow: 0 0 0 3px rgba(31,78,133,.12);
}

/* User-tile stat-line: pozwól łamać między „Ostatnio…" a „N nieprzejrzanych",
   ale nie wewnątrz tych fraz. Bez tego „0 nieprzejrzanych" wpadało w drugą linię. */
.user-tile .ut-stat { flex-wrap: wrap; row-gap: 2px; }
.user-tile .ut-stat > span:not(.sep) { white-space: nowrap; }

/* Label sekcji w SettingsMenu — szary uppercase nad selectem */
.settings-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted-2);
    font-weight: 600;
    margin-top: 2px;
}

.user-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 220px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2), 0 12px 32px rgba(15,23,42,.12);
    padding: 6px 0;
    z-index: 200;
    color: var(--ink);
}
.user-menu .um-head {
    padding: 8px 14px 10px;
    border-bottom: 1px solid var(--line-2);
    margin-bottom: 4px;
}
.user-menu .um-name {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--ink);
}
.user-menu .um-sub {
    font-size: 11.5px;
    color: var(--muted-2);
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-top: 2px;
}
.user-menu .um-form { margin: 0; }
.user-menu .um-item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    border: 0;
    background: transparent;
    padding: 8px 14px;
    font: inherit;
    font-size: 13px;
    color: var(--ink-2);
    text-align: left;
    cursor: pointer;
}
.user-menu .um-item:hover:not(:disabled) {
    background: var(--surface-2);
    color: var(--brand-700);
}
.user-menu .um-item:disabled {
    opacity: .55;
    cursor: default;
}
.user-menu .um-divider {
    height: 1px;
    background: var(--line-2);
    margin: 4px 0;
}
.user-menu .um-note {
    padding: 8px 14px;
    font-size: 12px;
    color: var(--muted);
}
.user-menu .um-error {
    padding: 4px 14px 8px;
    font-size: 11.5px;
    color: var(--danger-fg);
}

/* ── Info „po co JSON, po co PDF" nad listą dokumentów ── */
.format-info {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    margin-bottom: 14px;
    background: var(--new-bg);
    border: 1px solid #cdd9ec;
    border-radius: var(--radius);
    color: var(--new-fg);
    font-size: 12.5px;
    line-height: 1.45;
}
.format-info .fi-icon { flex-shrink: 0; opacity: .85; padding-top: 1px; }
.format-info .fi-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.format-info .fi-row { display: flex; align-items: baseline; gap: 8px; }
.format-info .fi-tag {
    flex-shrink: 0;
    font-weight: 600;
    font-size: 10.5px;
    letter-spacing: .03em;
    padding: 1px 8px;
    border-radius: 999px;
    border: 1px solid transparent;
    text-transform: uppercase;
    line-height: 1.6;
}
.format-info .fi-tag.json { background: #e8f3ec; color: #285a3a; border-color: #bfdcc5; }
.format-info .fi-tag.pdf  { background: #f1f3f7; color: #4a4f5e; border-color: #d6dbe6; }

/* ── Content wrapper ──────────────────────────────────── */
.content {
    /* .page już ma max-width 1440 + padding; tu tylko fallback dla starych stron bez .page */
    min-height: calc(100vh - 56px);
}

/* ── Alert (sukces/błąd/info) – ponad tokeny semantyczne ── */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius);
    border: 1px solid;
    font-size: 13px;
    margin-bottom: 16px;
}
.alert .alert-close {
    margin-left: auto;
    border: 0;
    background: transparent;
    color: inherit;
    opacity: .6;
    cursor: pointer;
    padding: 0 4px;
}
.alert .alert-close:hover { opacity: 1; }
.alert.success { background: var(--ok-bg); color: var(--ok-fg); border-color: #bfdcc5; }
.alert.error   { background: var(--danger-bg); color: var(--danger-fg); border-color: #f3c9c9; }
.alert.warn    { background: var(--warn-bg); color: var(--warn-fg); border-color: #f5d0a4; }
.alert.info    { background: var(--new-bg); color: var(--new-fg); border-color: #cdd9ec; }

/* ── Banner zdrowia autosprawdzania (pod topbarem, pełna szerokość) ── */
.health-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 40px;
    font-size: 13px;
    border-bottom: 1px solid;
}
.health-banner.error { background: var(--danger-bg); color: var(--danger-fg); border-color: #f3c9c9; }
.health-banner.warn  { background: var(--warn-bg); color: var(--warn-fg); border-color: #f5d0a4; }
.health-banner > svg { flex-shrink: 0; }
.health-banner .hb-text {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 10px;
    min-width: 0;
}
.health-banner .hb-detail { opacity: .85; }
.health-banner .hb-close {
    margin-left: auto;
    border: 0;
    background: transparent;
    color: inherit;
    opacity: .6;
    cursor: pointer;
    padding: 2px;
    display: flex;
    flex-shrink: 0;
}
.health-banner .hb-close:hover { opacity: 1; }

/* ── Wskaźnik stanu autosprawdzania (przy „Sprawdź wszystkie") ── */
.poll-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    cursor: help;
}
.poll-status .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.poll-status .dot.ok   { background: var(--ok-fg); }
.poll-status .dot.err  { background: var(--danger-fg); }
.poll-status .dot.warn { background: var(--warn-fg); }
.poll-status .dot.off  { background: #9ca3af; }

/* ── Modal / dialog – proste, do formularzy ────────────── */
.dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .32);
    backdrop-filter: blur(2px);
    display: grid;
    place-items: center;
    z-index: 1000;
}
.dialog {
    width: 480px;
    max-width: calc(100vw - 32px);
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 64px rgba(15,23,42,.24), 0 0 0 1px rgba(15,23,42,.06);
    overflow: hidden;
}
.dialog-head {
    padding: 16px 22px 12px;
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid var(--line-2);
}
.dialog-head h3 { margin: 0; font-size: 15px; font-weight: 600; color: var(--ink); }
.dialog-head .close {
    border: 0; background: transparent; color: var(--muted-2);
    cursor: pointer; padding: 4px;
}
.dialog-body { padding: 18px 22px; }
.dialog-body .field { margin-bottom: 12px; }
.dialog-body .field label {
    display: block;
    font-size: 12px; font-weight: 500;
    color: var(--muted);
    margin-bottom: 4px;
}
.dialog-body .field input,
.dialog-body .field textarea,
.dialog-body .field select {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-size: 13.5px;
    transition: border-color .12s, box-shadow .12s;
}
.dialog-body .field input:focus,
.dialog-body .field textarea:focus,
.dialog-body .field select:focus {
    outline: 0;
    border-color: var(--brand-600);
    box-shadow: 0 0 0 3px rgba(31,78,133,.12);
}
.dialog-body .field-error { color: var(--danger-fg); font-size: 12px; margin-top: 4px; }
.dialog-foot {
    padding: 14px 22px;
    background: var(--surface-2);
    border-top: 1px solid var(--line);
    display: flex; justify-content: flex-end; gap: 8px;
}

/* ── Native <select> w stylu .select ───────────────────── */
.select-native {
    appearance: none;
    -webkit-appearance: none;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 7px 28px 7px 10px;
    font-size: 13.5px;
    color: var(--ink);
    cursor: pointer;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
    background-repeat: no-repeat;
    background-position: right 8px center;
}
.select-native:hover { border-color: #cfd2d8; }
.select-native:focus {
    outline: 0;
    border-color: var(--brand-600);
    box-shadow: 0 0 0 3px rgba(31,78,133,.12);
}

/* ── Empty state ───────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--muted);
    background: var(--surface);
    border: 1px dashed var(--line);
    border-radius: var(--radius-lg);
}
.empty-state .es-title {
    color: var(--ink);
    font-weight: 600;
    margin-top: 12px;
    font-size: 14px;
}
.empty-state .es-sub {
    font-size: 13px;
    margin-top: 4px;
}
.empty-state .es-ico {
    color: var(--faint);
    display: inline-flex;
}

/* ── Skeleton ──────────────────────────────────────────── */
.skeleton-bar {
    height: 12px;
    background: linear-gradient(90deg, var(--bg-2) 0%, var(--line-2) 50%, var(--bg-2) 100%);
    background-size: 200% 100%;
    animation: skeleton-pulse 1.4s ease-in-out infinite;
    border-radius: 4px;
}
@keyframes skeleton-pulse {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Drobne pomocnicze ─────────────────────────────────── */
.text-mono { font-family: var(--ff-mono); font-feature-settings: "tnum" 1; }
.text-muted { color: var(--muted); }
.text-faint { color: var(--faint); }
.spacer { flex: 1; }

.page-foot {
    margin-top: 14px;
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--muted-2);
}
.page-foot .right { font-family: var(--ff-mono); }

/* Group color tint – mapowanie color name z bazy na badge */
.badge.color-primary   { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.badge.color-success   { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.badge.color-warning   { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.badge.color-danger    { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.badge.color-info      { background: #cffafe; color: #155e75; border-color: #a5f3fc; }
.badge.color-secondary { background: var(--bg-2); color: var(--muted); border-color: var(--line); }
.badge.color-dark      { background: #e5e7eb; color: #1f2937; border-color: #d1d5db; }

/* Akcent grupy w nagłówku – mała kropka koloru */
.group-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 5px;
    vertical-align: middle;
}
.group-dot.color-primary   { background: #3b82f6; }
.group-dot.color-success   { background: #22c55e; }
.group-dot.color-warning   { background: #f59e0b; }
.group-dot.color-danger    { background: #ef4444; }
.group-dot.color-info      { background: #06b6d4; }
.group-dot.color-secondary { background: var(--muted-2); }
.group-dot.color-dark      { background: var(--ink); }

/* Search input — szersza wersja .input */
.input.input-search { min-width: 320px; flex: 0 1 320px; }

/* Toolbar - dopasowanie do mockupu (lekko padding) */
.toolbar { font-size: 13px; }
.toolbar .info-text {
    font-size: 12px;
    color: var(--muted-2);
    font-family: var(--ff-mono);
}

/* Akcje w wierszu tabeli — kebab */
.tbl .kebab {
    background: transparent;
    border: 0;
    color: var(--muted-2);
    padding: 4px 6px;
    border-radius: var(--radius);
    cursor: pointer;
}
.tbl .kebab:hover { background: var(--bg-2); color: var(--ink); }
.tbl .kebab-wrap { position: relative; display: inline-block; }
.tbl .kebab-menu {
    position: absolute;
    right: 0; top: calc(100% + 4px);
    min-width: 200px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2);
    padding: 6px 0;
    z-index: 50;
    text-align: left;
}
.tbl .kebab-menu .km-item {
    display: flex; align-items: center; gap: 9px;
    width: 100%;
    padding: 7px 14px;
    border: 0; background: transparent;
    font: inherit; font-size: 13px;
    color: var(--ink-2);
    cursor: pointer;
    text-align: left;
}
.tbl .kebab-menu .km-item:hover { background: var(--surface-2); color: var(--brand-700); }
.tbl .kebab-menu .km-item.danger { color: var(--danger-fg); }
.tbl .kebab-menu .km-item.danger:hover { background: var(--danger-bg); color: var(--danger-fg); }
.tbl .kebab-menu .km-divider {
    height: 1px; background: var(--line-2); margin: 4px 0;
}
.tbl .kebab-menu .km-section {
    padding: 6px 14px 4px;
    font-size: 10.5px; text-transform: uppercase;
    color: var(--muted-2); letter-spacing: .06em; font-weight: 600;
}
.tbl .kebab-menu .km-check {
    display: flex; align-items: center; gap: 8px;
    padding: 5px 14px; font-size: 13px; cursor: pointer;
}
.tbl .kebab-menu .km-check input { margin: 0; accent-color: var(--brand-700); }
.tbl .kebab-menu .km-check:hover { background: var(--surface-2); }

/* Klikalność wiersza tabeli */
.tbl tbody tr.clickable { cursor: pointer; }

/* Soft-deleted (ukryte) wiersze — wyszarzone z subtelnym oznaczeniem */
.tbl tbody tr.row-hidden td {
    opacity: 0.55;
    background: repeating-linear-gradient(
        135deg,
        transparent 0,
        transparent 8px,
        rgba(148, 163, 184, 0.06) 8px,
        rgba(148, 163, 184, 0.06) 16px
    );
}
.tbl tbody tr.row-hidden:hover td { opacity: 0.8; }
.tbl tbody tr.row-hidden .badge.warn { opacity: 1; }

/* Karta zawierająca tabelę z kebab-popupami — pozwala dropdownom wystawać
   poza krawędzie. Roundowanie utrzymane na thead/last-row żeby nie było
   ostrych rogów na zaokrąglonej karcie. */
.card.allow-overflow { overflow: visible; }
.card.allow-overflow .tbl thead th:first-child { border-top-left-radius: var(--radius-lg); }
.card.allow-overflow .tbl thead th:last-child  { border-top-right-radius: var(--radius-lg); }
.card.allow-overflow .tbl tbody tr:last-child td:first-child { border-bottom-left-radius: var(--radius-lg); }
.card.allow-overflow .tbl tbody tr:last-child td:last-child  { border-bottom-right-radius: var(--radius-lg); }

/* Status pobrania jako pełny badge zamiast samej kropki — lepiej widoczny */
.dl-state {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 11.5px;
    font-weight: 500;
    padding: 3px 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--bg-2);
    color: var(--muted);
    white-space: nowrap;
}
.dl-state .dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: currentColor; flex: 0 0 6px;
}
.dl-state.cached {
    background: var(--ok-bg);
    color: var(--ok-fg);
    border-color: #bfdcc5;
}
.dl-state.loading {
    background: var(--new-bg);
    color: var(--new-fg);
    border-color: #cdd9ec;
}
.dl-state.loading .dot {
    animation: pulse-fade 1.4s ease-in-out infinite;
}
.dl-state.notdl {
    background: var(--bg-2);
    color: var(--muted);
    border-color: var(--line);
}
@keyframes pulse-fade { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* Banner „ta firma jest ukryta" */
.hidden-banner {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 12px 16px;
    margin-bottom: 16px;
    background: var(--warn-bg);
    border: 1px solid #f5d0a4;
    border-radius: var(--radius-lg);
    color: var(--warn-fg);
}
.hidden-banner .body { flex: 1; }
.hidden-banner .title { font-weight: 600; font-size: 13.5px; margin-bottom: 2px; }
.hidden-banner .sub { font-size: 12.5px; opacity: 0.85; }
.hidden-banner .actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* ── Chat: korekty + stan loading w modalu ────────────── */
.chat-wrap { max-width: 1440px; margin: 0 auto; }
.chat-side .ctx-head h3 button {
    border: 0; background: transparent;
    cursor: pointer; color: var(--muted-2);
    padding: 2px 6px; border-radius: 4px;
}
.chat-side .ctx-head h3 button:hover { background: var(--bg-2); color: var(--ink); }
.chat-side .filter-row {
    padding: 8px 14px 0;
    display: flex; gap: 4px; flex-wrap: wrap;
}
.chat-side .filter-row .chip { padding: 3px 9px; font-size: 11.5px; }

/* Spinner w modal-step active */
.modal-step.loading .num {
    background: var(--brand-100);
    color: var(--brand-700);
    position: relative;
}
.modal-step.loading .num::after {
    content: "";
    position: absolute; inset: 2px;
    border-radius: 50%;
    border: 1.5px solid var(--brand-700);
    border-top-color: transparent;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Avatar in chat */
.msg .ava.user-ava {
    background: var(--brand-100);
    color: var(--brand-700);
}

/* Klikalny wiersz firmy w drzewie chat */
.tree-firm > .firm-row { user-select: none; }
.tree-firm > .firm-row:hover { color: var(--brand-700); }

/* Sidebar chat: filtr grupy jako select w jednej linii z headerem */
.chat-side .filter-row {
    padding: 8px 14px 4px;
}
.chat-side .filter-row .select-native {
    width: 100%;
    font-size: 12.5px;
    padding: 5px 26px 5px 9px;
}

/* Sticky/footer fixes dla chat-composer */
.chat-composer .hints .ic { color: var(--muted-2); vertical-align: middle; margin-right: 3px; }

/* Empty state w czacie */
.chat-empty {
    flex: 1;
    display: grid;
    place-items: center;
    color: var(--muted);
    text-align: center;
    padding: 40px 20px;
}
.chat-empty .ico {
    width: 56px; height: 56px;
    border-radius: 14px;
    background: var(--brand-50);
    color: var(--brand-700);
    display: grid; place-items: center;
    margin: 0 auto 14px;
}
.chat-empty .title {
    font-size: 15px; font-weight: 600; color: var(--ink);
    margin-bottom: 6px;
}
.chat-empty .examples {
    margin-top: 14px;
    display: flex; flex-direction: column; gap: 6px;
    font-size: 13px;
    color: var(--muted);
    font-style: italic;
}
.chat-empty .examples span { color: var(--muted-2); }

/* Status pill */
.ctx-pill {
    background: var(--bg-2);
    padding: 3px 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
}

