/* Цветовете са като в десктоп програмата (konvertor/theme.py): светла и тъмна тема. */
:root, :root[data-theme="light"] {
    --header: #1c56a6; --header-fg: #ffffff; --header-muted: #c9daf5; --header-btn: #2f6cc0;
    --bg: #f3f6fa; --panel: #c9d0da; --card: #ffffff; --fg: #1d2330; --muted: #5b6474;
    --border: #b4bfce; --entry: #ffffff; --accent: #1f5fbf; --accent-hover: #174a96; --accent-fg: #ffffff;
    --success: #1f9d55; --success-hover: #17834a; --button: #ffffff; --button-hover: #e6eefb; --button-fg: #1f5fbf;
    --disabled: #9aa3b2; --tree: #ffffff; --tree-alt: #eef3fa; --tree-head: #2a63b8; --tree-head-fg: #ffffff;
    --select: #9cc3ef; --select-fg: #10233f; --row-error: #f8d7da; --row-note: #fff3cd; --row-purchase: #1f4e9c;
    --warn: #b45309; --info: #1f4e9c; --log-error: #b00020; --log-warn: #9a5b00; --log-ok: #1b7f3b; --log-info: #1d2330;
    --overlay: rgba(16, 24, 40, .45);
    color-scheme: light;
}
:root[data-theme="dark"] {
    --header: #2d2d30; --header-fg: #f1f1f1; --header-muted: #9d9d9d; --header-btn: #3e3e42;
    --bg: #1e1e1e; --panel: #252526; --card: #252526; --fg: #d4d4d4; --muted: #9d9d9d;
    --border: #3f3f46; --entry: #3c3c3c; --accent: #0e639c; --accent-hover: #1177bb; --accent-fg: #ffffff;
    --success: #16825d; --success-hover: #1a9b6f; --button: #3a3d41; --button-hover: #45494e; --button-fg: #e6e6e6;
    --disabled: #6b6b6b; --tree: #1e1e1e; --tree-alt: #262628; --tree-head: #333337; --tree-head-fg: #e6e6e6;
    --select: #094771; --select-fg: #ffffff; --row-error: #5a1d1d; --row-note: #4b3f13; --row-purchase: #4fc1ff;
    --warn: #e0a64a; --info: #4fc1ff; --log-error: #f48771; --log-warn: #cca700; --log-ok: #89d185; --log-info: #d4d4d4;
    --overlay: rgba(0, 0, 0, .6);
    color-scheme: dark;
}

/* Четирите тъмни стила с цветен акцент (синя, лилава, зелена, оранжева): един акцент --neon,
   от него се смесват фонът, панелите, редовете и светенето (--glow); общите ефекти - най-долу. */
:root[data-theme="blue"] { --neon: #2f8cff; --neon-2: #6cb6ff; --base: #050a14; }
:root[data-theme="purple"] { --neon: #a43cff; --neon-2: #c98bff; --base: #0a0614; }
:root[data-theme="green"] { --neon: #16c46a; --neon-2: #5fe39d; --base: #040d09; }
:root[data-theme="orange"] { --neon: #ff8a1f; --neon-2: #ffb36b; --base: #0e0904; }
:root:is([data-theme="blue"], [data-theme="purple"], [data-theme="green"], [data-theme="orange"]) {
    --bg: var(--base);
    --panel: color-mix(in srgb, var(--neon) 5%, #0b1019);
    --card: color-mix(in srgb, var(--neon) 6%, #0d121c);
    --header: color-mix(in srgb, var(--neon) 7%, #070b12); --header-fg: #eef2f8; --header-muted: #8c97a8;
    --header-btn: color-mix(in srgb, var(--neon) 14%, #121822);
    --fg: #dde4ee; --muted: #8b96a7;
    --border: color-mix(in srgb, var(--neon) 22%, #1a212d); --entry: color-mix(in srgb, var(--neon) 4%, #0a0f17);
    --accent: var(--neon); --accent-hover: var(--neon-2); --accent-fg: #ffffff;
    --success: #12a35b; --success-hover: #18bd6a;
    --button: color-mix(in srgb, var(--neon) 8%, #10161f); --button-hover: color-mix(in srgb, var(--neon) 18%, #121925);
    --button-fg: color-mix(in srgb, var(--neon-2) 55%, #e6ebf2);
    --disabled: #4c5666;
    --tree: color-mix(in srgb, var(--neon) 3%, #080c13); --tree-alt: color-mix(in srgb, var(--neon) 7%, #0b1019);
    --tree-head: color-mix(in srgb, var(--neon) 12%, #0e141e); --tree-head-fg: #eef2f8;
    --select: color-mix(in srgb, var(--neon) 30%, #0b1019); --select-fg: #ffffff;
    --row-error: color-mix(in srgb, #ff4d6a 16%, #0b1019); --row-note: color-mix(in srgb, #f2c14e 9%, #0a0e15); --row-purchase: var(--neon-2);
    --warn: #f0a94a; --info: var(--neon-2); --log-error: #ff7a7a; --log-warn: #f2c14e; --log-ok: #5fd68f; --log-info: #dde4ee;
    --overlay: rgba(0, 0, 0, .7);
    --glow: 0 0 14px color-mix(in srgb, var(--neon) 55%, transparent);
    --glow-soft: 0 0 22px color-mix(in srgb, var(--neon) 18%, transparent);
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    background: var(--bg); color: var(--fg);
    font: 14px/1.35 "Segoe UI", system-ui, -apple-system, sans-serif;
}
button, input, select { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- горна лента */
.topbar {
    display: flex; align-items: center; gap: 14px;
    background: var(--header); color: var(--header-fg); padding: 10px 16px;
}
.topbar .brand { font-size: 18px; font-weight: 700; }
.topbar .brand small { font-size: 13px; font-weight: 400; color: var(--header-muted); margin-left: 8px; }
.topbar .spacer { flex: 1; }
.topbar .version { color: var(--header-muted); font-size: 13px; }

/* ---------------------------------------------------------------- бутони */
.btn {
    display: inline-flex; align-items: center; gap: 6px; position: relative;
    border: 1px solid var(--button-fg); background: var(--button); color: var(--button-fg);
    padding: 6px 14px; border-radius: 3px; cursor: pointer; white-space: nowrap; overflow: hidden;
}
.btn:hover:not(:disabled) { background: var(--button-hover); }
.btn:disabled { color: var(--disabled); border-color: var(--disabled); cursor: default; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.accent:hover:not(:disabled) { background: var(--accent-hover); }
.btn.success { background: var(--success); border-color: var(--success); color: var(--accent-fg); }
.btn.success:hover:not(:disabled) { background: var(--success-hover); }
.btn.success:disabled, .btn.accent:disabled { background: var(--disabled); color: var(--bg); }
.btn.header { background: var(--header-btn); border-color: var(--header-btn); color: var(--header-fg); }
.btn input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ---------------------------------------------------------------- главен екран */
.page { display: flex; flex-direction: column; height: calc(100vh - 50px); padding: 10px 12px 12px; gap: 8px; }
.panel {
    background: var(--panel); padding: 10px 14px; display: grid; gap: 8px;
    grid-template-columns: max-content 1fr;
    align-items: center;
}
.panel label.title { font-weight: 700; }
.panel .row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.panel select { min-width: 270px; padding: 4px 6px; background: var(--entry); border: 1px solid var(--border); }
.panel .choice { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.panel .group { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-left: 18px; }
.muted { color: var(--muted); }
.busy::before {
    content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 6px; vertical-align: -1px;
    border: 2px solid var(--accent); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.banner { padding: 8px 12px; border-left: 4px solid var(--log-error); background: var(--card); white-space: pre-line; }
.banner button { float: right; border: 0; background: none; cursor: pointer; color: var(--muted); }

/* ---------------------------------------------------------------- таблица */
.table-wrap { flex: 1; min-height: 160px; overflow: auto; border: 1px solid var(--border); background: var(--tree); }
table.grid { border-collapse: collapse; width: max-content; min-width: 100%; table-layout: fixed; }
table.grid th {
    position: sticky; top: 0; z-index: 1; background: var(--tree-head); color: var(--tree-head-fg);
    font-weight: 600; padding: 6px 8px; text-align: left; white-space: nowrap;
}
table.grid td {
    height: 26px; padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    border-bottom: 1px solid transparent;
}
table.grid .num { text-align: right; }
table.grid tr.odd td { background: var(--tree-alt); }
table.grid tr.note td { background: var(--row-note); }
table.grid tr.error td { background: var(--row-error); }
table.grid tr.purchase td { color: var(--row-purchase); }
table.grid td.note { max-width: 520px; }

.dropzone {
    flex: 1; min-height: 160px; position: relative; display: flex; align-items: center; justify-content: center;
    flex-direction: column; gap: 8px; border: 2px dashed var(--border); background: var(--card); color: var(--muted);
    text-align: center; padding: 20px;
}
.dropzone strong { color: var(--fg); font-size: 16px; }
.dropzone.active { border-color: var(--accent); background: var(--button-hover); }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.actions { display: flex; align-items: center; gap: 8px; }
.actions .summary { flex: 1; font-weight: 700; }

/* ---------------------------------------------------------------- съобщения */
.log { background: var(--card); border: 1px solid var(--border); padding: 6px 10px; }
.log h3 { margin: 0 0 4px; font-size: 14px; }
.log ul { list-style: none; margin: 0; padding: 0; max-height: 140px; overflow: auto; }
.log li.error { color: var(--log-error); }
.log li.warn { color: var(--log-warn); }
.log li.ok { color: var(--log-ok); }
.log li.info { color: var(--log-info); }

/* ---------------------------------------------------------------- диалог */
.overlay {
    position: fixed; inset: 0; background: var(--overlay); z-index: 10;
    display: flex; align-items: center; justify-content: center; padding: 20px;
}
.dialog {
    background: var(--bg); color: var(--fg); width: min(980px, 100%); max-height: 90vh;
    display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0, 0, 0, .35);
}
.dialog header { background: var(--header); color: var(--header-fg); padding: 10px 14px; font-size: 16px; font-weight: 700; }
.dialog header small { font-weight: 400; color: var(--header-muted); margin-left: 8px; }
.dialog .body { padding: 10px 14px; overflow: auto; }
.dialog .body p { margin: 0 0 10px; }
.dialog footer { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 14px; }
.dialog footer .error { flex: 1; color: var(--log-error); white-space: pre-line; align-self: center; }
.goods { border-collapse: collapse; width: 100%; }
.goods th { text-align: left; padding: 4px 6px; font-weight: 700; }
.goods td { padding: 3px 6px; }
.goods td.num, .goods th.num { text-align: right; }
.goods input[type=text] { width: 130px; padding: 3px 6px; background: var(--entry); border: 1px solid var(--border); }
.goods .missing { color: var(--warn); font-weight: 700; }

/* ---------------------------------------------------------------- редове: избор, клетки, ▶ */
table.grid tbody tr { cursor: default; user-select: none; }
table.grid tr.selected td { background: var(--select) !important; color: var(--select-fg) !important; }
table.grid td.cell-edit { cursor: pointer; }
table.grid td.cell-edit.changed { font-style: italic; }
table.grid td .cell-select { width: 100%; height: 22px; font-size: 13px; background: var(--entry); border: 1px solid var(--accent); }
table.grid td .cell-select.wide { width: 330px; position: relative; z-index: 3; }
table.grid th.post, table.grid td.post { position: sticky; right: 0; text-align: center; border-left: 1px solid var(--border); }
table.grid th.post { z-index: 2; }
table.grid td.post { background: var(--tree); color: var(--info, #1f4e9c); font-weight: 700; cursor: pointer; }
table.grid tr.odd td.post { background: var(--tree-alt); }
table.grid tr.note td.post { background: var(--row-note); }
table.grid tr.error td.post { background: var(--row-error); cursor: default; }

/* „Общо“ - винаги видим най-долу на таблицата */
table.grid tfoot td {
    position: sticky; bottom: 0; z-index: 1; height: 28px; background: var(--tree-head); color: var(--tree-head-fg);
    font-weight: 700; border-top: 2px solid var(--border);
}
table.grid tfoot td.post { z-index: 2; background: var(--tree-head); }
table.grid td.month { text-align: center; }

/* „Месец за експорт“ - календар с месеци */
.month-backdrop { position: fixed; inset: 0; z-index: 30; }
.month-picker {
    position: fixed; z-index: 31; visibility: hidden; width: 228px; padding: 8px; outline: none;
    background: var(--card); color: var(--fg); border: 1px solid var(--border); box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
}
.month-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.month-head .btn { padding: 2px 10px; }
.month-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.month-grid button {
    padding: 7px 0; border: 1px solid var(--border); background: var(--button); color: var(--button-fg); cursor: pointer;
}
.month-grid button:hover { background: var(--button-hover); }
.month-grid button.today { font-weight: 700; }
.month-grid button.active { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.month-grid button.cursor { outline: 2px solid var(--accent); outline-offset: 1px; }
.month-foot { display: flex; justify-content: space-between; margin-top: 6px; }
.month-foot .link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 2px 0; font-size: 13px; }
:root[data-theme="dark"] .month-foot .link { color: var(--info); }
.banner.ok { border-left-color: var(--log-ok); color: var(--log-ok); }

/* ---------------------------------------------------------------- контиране */
.dialog.posting { width: min(1180px, 100%); height: min(760px, 94vh); max-height: 94vh; }
.dialog.posting header .edited { float: right; font-weight: 400; font-size: 13px; }
.tabs.inner { padding: 8px 14px 0; }
.dialog.posting .body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.posting-page { display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 0; }
.posting-page[hidden] { display: none; }
.posting-head { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 24px; background: var(--panel); padding: 8px 12px; }
.posting-fields { display: grid; grid-template-columns: max-content 1fr; gap: 3px 10px; align-items: center; }
.posting-fields input, .posting-fields select { width: 100%; padding: 3px 6px; background: var(--entry); border: 1px solid var(--border); }
.posting-lines { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; flex: 1; min-height: 160px; }
.posting-lines .side { display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--border); min-height: 0; }
.posting-lines .side-head, .posting-lines .line {
    display: grid; grid-template-columns: 90px 1fr 70px 80px 90px 26px; gap: 4px; align-items: center;
}
.posting-lines .side-head { background: var(--tree-head); color: var(--tree-head-fg); font-weight: 600; padding: 4px 6px; }
.posting-lines .side-rows { flex: 1; overflow: auto; padding: 4px 6px; display: flex; flex-direction: column; gap: 2px; }
.posting-lines .line input { width: 100%; padding: 2px 5px; background: var(--entry); border: 1px solid var(--border); min-width: 0; }
.posting-lines .line input.name { background: transparent; border-color: transparent; color: var(--muted); }
.posting-lines .line .icon { border: 1px solid var(--border); background: var(--button); color: var(--button-fg); cursor: pointer; height: 24px; }
.posting-lines .side-foot { display: flex; justify-content: space-between; align-items: center; padding: 6px; }
.num { text-align: right; }
.posting-lines .line input.num { text-align: right; }
.balance { margin: 0; font-weight: 700; }
.posting-foot { align-items: center; }
.posting-foot .left { flex: 1; display: flex; gap: 12px; align-items: center; }
.posting-warning { color: var(--log-error); font-weight: 700; margin: 0 14px 8px; min-height: 1.2em; }
.posting-errors { margin: 0 14px 10px; padding: 8px 12px; border-left: 4px solid var(--log-error); background: var(--card); }
.posting-errors ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------------------------------------------------------------- сметкоплан, вход за онлайн експорт */
.firm-tab { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; }
.chart-head, .chart-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chart-head h3 { margin: 6px 0; }
.chart-head .spacer, .chart-tools .spacer { flex: 1; }
.chart-tools input[type=search], .chart-tools #chart-search { width: 220px; padding: 4px 8px; background: var(--entry); border: 1px solid var(--border); }
.chart-table { flex: 1; min-height: 200px; }
.chart-table table.grid { width: 100%; }
.tree-toggle { width: 18px; border: 0; background: none; color: var(--fg); cursor: pointer; padding: 0; margin-right: 2px; }
.tree-leaf { display: inline-block; width: 20px; }
.dialog .form .form-title { grid-column: 1 / -1; margin: 10px 0 0; }
.dialog .form .hint { grid-column: 1 / -1; margin: 0; }
.dialog .form .full { grid-column: 1 / -1; margin: 4px 0 0; }
.dialog footer .btn { align-self: center; }
.dialog.firm-editor { max-height: 94vh; }

/* ---------------------------------------------------------------- нов вид файл */
.dialog.profile-editor { width: min(1060px, 100%); height: min(780px, 94vh); }
.dialog.profile-editor .body { flex: 1; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.profile-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.profile-top select, .profile-top input { padding: 4px 6px; background: var(--entry); border: 1px solid var(--border); }
.profile-top input.small { width: 70px; }
.profile-top input.name { flex: 1; min-width: 240px; }
.profile-top select { min-width: 160px; }
.profile-body { display: flex; gap: 14px; flex: 1; min-height: 0; }
.profile-fields { flex: 1; border-collapse: collapse; display: block; overflow: auto; }
.profile-fields th { text-align: left; padding: 4px 6px; position: sticky; top: 0; background: var(--bg); }
.profile-fields td { padding: 2px 6px; }
.profile-fields td input { width: 260px; padding: 3px 6px; background: var(--entry); border: 1px solid var(--border); }
.profile-fields td.sample { color: var(--info); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-fields td.section { padding-top: 12px; }
.profile-side { width: 280px; }
.profile-side h4 { margin: 8px 0 4px; }
.dialog footer .result { flex: 1; align-self: center; }

/* ---------------------------------------------------------------- телефон / тесен екран */
@media (max-width: 760px) {
    .topbar { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
    .topbar .brand small { display: block; margin: 0; }
    .topbar .spacer { display: none; }
    .page { height: auto; min-height: calc(100vh - 60px); padding: 8px; }
    .panel { grid-template-columns: 1fr; gap: 4px; }
    .panel label.title { margin-top: 6px; }
    .panel select { min-width: 0; width: 100%; }
    .panel .group { margin-left: 0; }
    .dropzone { min-height: 220px; }
    .table-wrap { min-height: 55vh; }
    .actions { flex-wrap: wrap; }
    .actions .summary { flex-basis: 100%; }
    .actions .btn { flex: 1; justify-content: center; }
    .dialog .body { padding: 8px; }
}

/* ---------------------------------------------------------------- фирма в горната лента */
.firmbox { position: relative; display: flex; width: min(520px, 60vw); }
.firmbox-input {
    flex: 1; font-size: 17px; font-weight: 700; padding: 5px 8px; border: 1px solid var(--border);
    background: var(--entry); color: var(--fg); border-radius: 3px 0 0 3px; min-width: 0;
}
.firmbox-arrow { width: 30px; border: 1px solid var(--border); border-left: 0; background: var(--entry); color: var(--fg); cursor: pointer; border-radius: 0 3px 3px 0; }
.firmbox-list {
    position: absolute; top: 100%; left: 0; right: 0; z-index: 30; margin: 2px 0 0; padding: 0; list-style: none;
    background: var(--entry); color: var(--fg); border: 1px solid var(--border); max-height: 360px; overflow: auto;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.firmbox-list li { padding: 6px 10px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.firmbox-list li.active, .firmbox-list li:hover { background: var(--accent); color: var(--accent-fg); }
.firmbox-list li.add { border-top: 1px solid var(--border); color: var(--accent); font-weight: 600; }
.firmbox-list li.add.active, .firmbox-list li.add:hover { color: var(--accent-fg); }

/* ---------------------------------------------------------------- раздели */
.tabs { display: flex; gap: 2px; padding: 8px 12px 0; }
.tab {
    border: 1px solid var(--border); border-bottom: 0; background: var(--panel); color: var(--fg); padding: 6px 22px;
    cursor: pointer; border-radius: 3px 3px 0 0;
}
.tab.active { background: var(--card); color: var(--accent); font-weight: 700; }
.page.with-tabs { height: calc(100vh - 50px - 38px); padding-top: 0; }
.tab-page, .convert { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; }
.tab-page[hidden] { display: none; }
.tab-page { padding-top: 8px; }

table.grid tr.exported td { color: var(--disabled); }

/* ---------------------------------------------------------------- настройки */
.settings { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; padding-top: 8px; }
.settings-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.settings-top select { min-width: 300px; padding: 4px 6px; background: var(--entry); border: 1px solid var(--border); }
.settings-body { display: flex; gap: 14px; flex: 1; min-height: 0; }
.settings-templates { flex: 1; overflow: auto; background: var(--card); border: 1px solid var(--border); padding: 6px 10px; }
.settings-templates table { border-collapse: collapse; width: 100%; }
.settings-templates th { text-align: left; padding: 4px 6px; position: sticky; top: 0; background: var(--card); }
.settings-templates td { padding: 2px 6px; white-space: nowrap; }
.settings-templates input { width: 100%; padding: 3px 6px; background: var(--entry); border: 1px solid var(--border); }
.settings-side { width: 380px; overflow: auto; background: var(--card); border: 1px solid var(--border); padding: 8px 12px; }
.settings-side h4 { margin: 12px 0 4px; }
.settings-side h4:first-child { margin-top: 0; }
.settings-side .accounts { display: grid; grid-template-columns: 1fr 110px; gap: 3px 8px; align-items: center; margin-left: 8px; }
.settings-side .accounts input, .settings-side select, .settings-side input.wide {
    padding: 3px 6px; background: var(--entry); border: 1px solid var(--border);
}
.settings-side input.wide, .settings-side select { width: 100%; }
.settings-side .choice.block { display: flex; margin: 2px 0; }
.settings-side .choice { margin-right: 12px; }
.settings-buttons { display: flex; gap: 8px; margin-top: 12px; }
.settings-buttons .btn { flex: 1; justify-content: center; }
.placeholders { display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; margin: 0; }
.placeholders dt { font-family: Consolas, monospace; }
.placeholders dd { margin: 0; color: var(--muted); }
.ok-text { color: var(--log-ok); }
.error-text { color: var(--log-error); white-space: pre-line; }
.choice { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }

/* ---------------------------------------------------------------- фирма */
.firm-tab { padding-top: 8px; }
.firm-data { grid-template-columns: 1fr auto; }
.firm-name { font-weight: 700; font-size: 16px; }
.firm-tab h3 { margin: 16px 0 4px; }

/* ---------------------------------------------------------------- малки диалози */
.dialog.small { width: min(560px, 100%); }
.dialog .pre { white-space: pre-line; }
.dialog.firm-editor { width: min(680px, 100%); }
.dialog .form { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; align-items: center; }
.dialog .form .row { display: flex; gap: 8px; }
.dialog .form input { width: 100%; padding: 4px 8px; background: var(--entry); border: 1px solid var(--border); }
.dialog .form .status { grid-column: 1 / -1; margin: 4px 0 0; }

@media (max-width: 760px) {
    .firmbox { width: 100%; }
    .settings-body { flex-direction: column; }
    .settings-side { width: auto; }
    .page.with-tabs { height: auto; }
    /* „Нов вид файл“: всичко едно под друго, превърта се целият диалог */
    .dialog.profile-editor .body { overflow: auto; }
    .profile-body { flex-direction: column; flex: none; }
    .profile-fields { overflow: visible; }
    .profile-fields td input { width: 100%; min-width: 120px; }
    .profile-fields td.sample { max-width: 80px; }
    .profile-top input.name { min-width: 0; }
    .profile-side { width: auto; }
}

#blazor-error-ui {
    display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: #ffe9a8; color: #222; padding: 8px 16px;
}
#blazor-error-ui .reload, #blazor-error-ui .dismiss { margin-left: 10px; cursor: pointer; }

/* „Плащане в брой – по правила“ (Настройки) */
.cash-rules { display: grid; gap: 4px; margin: 4px 0 6px; }
.cash-rule { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) 64px 32px; gap: 4px; align-items: center; }
.cash-rule select, .cash-rule input { padding: 3px 4px; background: var(--entry); color: var(--fg); border: 1px solid var(--border); }
.settings-side .cash-rule select, .settings-side .cash-rule input { width: 100%; min-width: 0; }
.cash-rule .btn { padding: 2px 0; }
.cash-rules > .btn { justify-self: start; }

/* Проверката във VIES - лента над таблицата, докато тече */
.vat-progress {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 8px 12px;
    background: var(--card); border-left: 4px solid var(--accent);
}
.vat-progress progress { width: 220px; height: 10px; accent-color: var(--accent); }

/* ---------------------------------------------------------------- вход / регистрация, екип */
.topbar .user { color: var(--header-muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.auth-page { display: flex; justify-content: center; padding: 40px 16px; }
.auth-card { width: min(440px, 100%); background: var(--card); border: 1px solid var(--border); padding: 20px 24px; }
.auth-card h1 { font-size: 20px; margin: 0 0 12px; }
.auth-tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.auth-form { display: grid; gap: 4px; }
.auth-form label { font-weight: 600; margin-top: 6px; }
.auth-form input { padding: 6px 8px; background: var(--entry); color: var(--fg); border: 1px solid var(--border); }
.auth-form .btn { margin-top: 12px; justify-self: start; }
.auth-form .auth-section { margin-top: 14px; font-weight: 700; border-top: 1px solid var(--border); padding-top: 10px; }
.team { display: grid; gap: 12px; max-width: 1100px; }
.team .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.team input, .team select { padding: 5px 8px; background: var(--entry); color: var(--fg); border: 1px solid var(--border); }
.team .org-name { min-width: 280px; }
.team-grid { width: 100%; }
.team-grid .actions-cell { display: flex; gap: 6px; justify-content: flex-end; }
@media (max-width: 760px) {
    .topbar .user { display: none; }
    .team .org-name { min-width: 0; flex: 1; }
}
@media (max-width: 760px) {
    /* разделите се превъртат вместо да излизат извън екрана */
    nav.tabs { overflow-x: auto; flex-wrap: nowrap; max-width: 100%; }
    nav.tabs .tab { flex: none; }
}
.team-box { background: var(--panel); padding: 10px 14px; display: grid; gap: 8px; }
.team-box .title { font-weight: 700; }
.team-box p { margin: 0; }
.team-add input { width: 200px; }
.team-password input { width: 220px; }
@media (max-width: 760px) {
    .team-add input, .team-password input { width: 100%; }
}

/* изискванията за парола - отмятат се при писане */
.password-rules { list-style: none; margin: 4px 0 0; padding: 0; font-size: 13px; color: var(--log-error); }
.password-rules li.ok { color: var(--log-ok); }

/* ---------------------------------------------------------------- избор на тема (горната лента) */
.theme-select {
    background: var(--header-btn); color: var(--header-fg); border: 1px solid var(--header-btn);
    border-radius: 3px; padding: 6px 8px; cursor: pointer;
}
.theme-select option { background: var(--entry); color: var(--fg); }
input[type=radio], input[type=checkbox] { accent-color: var(--accent); }

/* ---------------------------------------------------------------- четирите тъмни стила: светене по ръбовете */
:root:is([data-theme="blue"], [data-theme="purple"], [data-theme="green"], [data-theme="orange"]) {
    & body {
        background:
            linear-gradient(118deg, transparent 58%, color-mix(in srgb, var(--neon) 9%, transparent) 66%, transparent 74%),
            linear-gradient(128deg, transparent 70%, color-mix(in srgb, var(--neon) 6%, transparent) 76%, transparent 82%),
            radial-gradient(1100px 520px at 92% -12%, color-mix(in srgb, var(--neon) 22%, transparent), transparent 62%),
            var(--bg);
        background-attachment: fixed;
    }
    & .topbar { border-bottom: 1px solid color-mix(in srgb, var(--neon) 35%, transparent); box-shadow: var(--glow-soft); }
    & .panel, & .settings-templates, & .settings-side, & .team-box, & .log {
        border: 1px solid var(--border); border-radius: 6px; background: color-mix(in srgb, var(--panel) 88%, transparent);
    }
    & .tab { background: var(--button); border-color: var(--border); border-bottom: 0; color: var(--fg); border-radius: 4px 4px 0 0; }
    & .tab.active { background: var(--neon); border-color: var(--neon); color: var(--accent-fg); box-shadow: var(--glow); }
    & .btn { border-radius: 4px; border-color: color-mix(in srgb, var(--neon) 55%, transparent); }
    & .btn.accent {
        background: linear-gradient(135deg, var(--neon), var(--neon-2)); border-color: var(--neon); box-shadow: var(--glow);
    }
    & .btn.accent:hover:not(:disabled) { filter: brightness(1.1); }
    & .btn.success { box-shadow: 0 0 12px color-mix(in srgb, var(--success) 50%, transparent); }
    & .btn.accent:disabled, & .btn.success:disabled { background: var(--disabled); box-shadow: none; }
    & .table-wrap {
        border: 1px solid color-mix(in srgb, var(--neon) 50%, transparent); border-radius: 6px;
        box-shadow: var(--glow-soft), inset 0 0 30px color-mix(in srgb, var(--neon) 5%, transparent);
    }
    & table.grid th { border-bottom: 2px solid var(--neon); box-shadow: 0 6px 14px -8px var(--neon); }
    & table.grid tbody tr:hover td { background: color-mix(in srgb, var(--neon) 12%, var(--tree)); }
    & table.grid tr.selected td { box-shadow: inset 0 1px 0 var(--neon), inset 0 -1px 0 var(--neon); }
    & table.grid tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--neon), inset 0 1px 0 var(--neon), inset 0 -1px 0 var(--neon); }
    & table.grid td.post { color: var(--neon); }
    & table.grid tfoot td { border-top: 2px solid var(--neon); box-shadow: 0 -6px 14px -8px var(--neon); color: var(--neon-2); }
    & .dropzone { border-color: color-mix(in srgb, var(--neon) 45%, transparent); border-radius: 8px; }
    & .dropzone.active { box-shadow: var(--glow); }
    & .dialog { border: 1px solid color-mix(in srgb, var(--neon) 45%, transparent); border-radius: 6px; overflow: hidden;
        box-shadow: 0 10px 50px rgba(0, 0, 0, .6), var(--glow-soft); }
    & .dialog header { border-bottom: 1px solid color-mix(in srgb, var(--neon) 40%, transparent); }
    & input:focus, & select:focus { outline: 1px solid var(--neon); box-shadow: var(--glow); }
    & .firmbox-input, & .firmbox-arrow { border-color: color-mix(in srgb, var(--neon) 40%, transparent); }
    & .month-picker, & .firmbox-list { border-color: color-mix(in srgb, var(--neon) 45%, transparent); box-shadow: var(--glow-soft); }
}

/* ---------------------------------------------------------------- профил (горе вдясно): настройки, фирма, екип, тема, изход */
.profile { position: relative; }
.profile-btn {
    display: inline-flex; align-items: center; gap: 8px; padding: 3px 10px 3px 3px; cursor: pointer;
    background: var(--header-btn); color: var(--header-fg); border: 1px solid var(--header-btn); border-radius: 20px;
}
.profile-btn:hover, .profile-btn[aria-expanded=true] { filter: brightness(1.15); }
.profile-btn .caret { font-size: 11px; color: var(--header-muted); }
.avatar {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    width: 30px; height: 30px; border-radius: 50%; font-size: 13px; font-weight: 700;
    background: var(--accent); color: var(--accent-fg); box-shadow: var(--glow, none);
}
.avatar.big { width: 42px; height: 42px; font-size: 16px; }
.menu-backdrop { position: fixed; inset: 0; z-index: 40; }
.profile-menu {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 41; width: 280px; padding: 6px 0;
    background: var(--card); color: var(--fg); border: 1px solid var(--border); border-radius: 6px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .3), var(--glow-soft, 0 0 0 transparent);
}
.menu-head { display: flex; gap: 10px; align-items: center; padding: 8px 14px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-head > div { min-width: 0; }
.menu-head .muted { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-item, .menu-row {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 14px;
    border: 0; background: none; color: var(--fg); text-align: left; cursor: pointer;
}
.menu-item:hover:not(:disabled) { background: var(--button-hover); }
.menu-item.active { color: var(--accent); font-weight: 700; }
.menu-item:disabled { color: var(--disabled); cursor: default; }
.menu-item.danger { color: var(--log-error); }
.menu-item .icon, .menu-row .icon { width: 18px; text-align: center; }
.menu-row { cursor: default; }
.menu-row select { margin-left: auto; padding: 3px 6px; background: var(--entry); color: var(--fg); border: 1px solid var(--border); }
.menu-sep { height: 1px; background: var(--border); margin: 4px 0; }
.tab.menu-page { display: inline-flex; align-items: center; gap: 6px; cursor: default; }
.tab-close { border: 0; background: none; color: inherit; cursor: pointer; padding: 0 0 0 4px; font-size: 12px; opacity: .8; }
.tab-close:hover { opacity: 1; }

/* ---------------------------------------------------------------- банкови извлечения (засега - само разделът) */
.bank-tab { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; padding-top: 8px; }
.bank-soon span { max-width: 640px; }
