/* ===== Base ===== */
* { box-sizing: border-box; }

/* ===== Theme CSS Variables ===== */
:root {
    --color-bg:          #f8fafc;
    --color-surface:     #ffffff;
    --color-surface-2:   #f1f5f9;
    --color-border:      #e2e8f0;
    --color-text:        #0f172a;
    --color-text-2:      #475569;
    --color-text-3:      #94a3b8;
    --color-sidebar:     #0f172a;
    --color-sidebar-text:#94a3b8;
    --color-topbar:      #ffffff;
    --color-topbar-border:#e2e8f0;
    --color-primary:     #2563eb;
    --color-primary-light:#eff6ff;
    --color-primary-text:#1d4ed8;
    --color-accent:      #2563eb;
    /* Persistent tint for editable registry columns (spec §2.3). */
    --sheet-editable-bg: color-mix(in srgb, var(--color-primary) 4%, transparent);
    /* Server-rejected cell (save-path role/validation refusal). */
    --sheet-rejected-bg:     #fef2f2;
    --sheet-rejected-border: #f87171;
}

[data-theme="dark"] {
    --color-bg:          #0f172a;
    --color-surface:     #1e293b;
    --color-surface-2:   #334155;
    --color-border:      #334155;
    --color-text:        #f1f5f9;
    --color-text-2:      #94a3b8;
    --color-text-3:      #64748b;
    --color-sidebar:     #020617;
    --color-sidebar-text:#64748b;
    --color-topbar:      #1e293b;
    --color-topbar-border:#334155;
    --color-primary-light:#1e3a8a;
    --color-primary-text:#93c5fd;
    --sheet-editable-bg: color-mix(in srgb, var(--color-primary) 6%, transparent);
    --sheet-rejected-bg:     #7f1d1d40;
    --sheet-rejected-border: #b91c1c;
}

/* Apply theme vars to key elements */
body                        { background: var(--color-bg); color: var(--color-text); }
aside#sidebar               { background: var(--color-sidebar) !important; }
header                      { background: var(--color-topbar) !important; border-color: var(--color-topbar-border) !important; }
.bg-white                   { background: var(--color-surface) !important; }
.bg-gray-50                 { background: var(--color-bg) !important; }
.bg-gray-100                { background: var(--color-surface-2) !important; }
.border-gray-200,
.border-gray-100            { border-color: var(--color-border) !important; }
.text-gray-900              { color: var(--color-text) !important; }
.text-gray-700,
.text-gray-800              { color: var(--color-text-2) !important; }
.text-gray-400,
.text-gray-500              { color: var(--color-text-3) !important; }

/* Spreadsheet table theming */
.sheet-table th             { background: var(--color-surface-2); color: var(--color-text-2); border-color: var(--color-border); }
.sheet-table td             { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.sheet-table tr:hover td    { background: var(--color-surface-2); }
.sheet-cell-edit            { background: var(--color-primary-light) !important; outline: 2px solid var(--color-primary); }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===== Sidebar Nav Active ===== */
.nav-item.active {
    background: rgba(255,255,255,0.1);
    color: #ffffff !important;
}
.nav-item.active i { color: #60a5fa !important; }

/* ===== Dashboard Modules ===== */
.module-card {
    /* Theme tokens (not hardcoded white) so dark mode works — spec C2 dark-fix. */
    background: var(--color-surface);
    border-radius: 16px;
    border: 1px solid var(--color-border);
    overflow: hidden;
    transition: box-shadow 0.2s, transform 0.2s;
    position: relative;
}

/* The current size (S/M/L) is shown directly on the resize control button
   (.module-size-label) instead of a separate header badge — the old badge sat
   in the same top-right corner as .module-controls and was covered in edit mode. */

.module-card:hover {
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}

/* Size classes for grid columns */
.module-sm  { grid-column: span 3; }
.module-md  { grid-column: span 6; }
.module-lg  { grid-column: span 12; }

@media (max-width: 1280px) {
    .module-sm  { grid-column: span 4; }
    .module-md  { grid-column: span 6; }
    .module-lg  { grid-column: span 12; }
}

@media (max-width: 900px) {
    .module-sm, .module-md { grid-column: span 12; }
    .module-lg  { grid-column: span 12; }
}

/* Edit mode */
.edit-mode .module-card {
    border: 2px dashed #93c5fd;
    cursor: grab;
}
.edit-mode .module-card:active { cursor: grabbing; }
.edit-mode .module-card .module-controls { display: flex !important; }

.module-controls {
    display: none;
    position: absolute;
    top: 10px;
    right: 10px;
    gap: 4px;
    z-index: 10;
}

.module-ctrl-btn {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    /* Theme tokens instead of light hardcodes — no white flash in dark mode. */
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 11px;
    color: var(--color-text-2);
    transition: all 0.15s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}
.module-ctrl-btn:hover { background: var(--color-surface-2); color: var(--color-text); }
.module-ctrl-btn.danger:hover {
    background: color-mix(in srgb, #ef4444 14%, var(--color-surface));
    color: #ef4444;
    border-color: color-mix(in srgb, #ef4444 45%, var(--color-border));
}
/* Current module size (S/M/L) shown on the size-cycle button itself. */
.module-ctrl-btn .module-size-label {
    font-weight: 700;
    font-size: 11px;
    line-height: 1;
    letter-spacing: 0.02em;
}

/* Drag & Drop */
.module-dragging {
    opacity: 0.5;
    transform: scale(0.98);
}
.module-drag-over {
    border-color: var(--color-primary) !important;
    background: color-mix(in srgb, var(--color-primary) 10%, var(--color-surface)) !important;
}

/* ===== Stat Cards ===== */
.stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.02em;
}

/* ===== Status Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 600;
}
.badge-green  { background: #dcfce7; color: #16a34a; }
.badge-blue   { background: #dbeafe; color: #2563eb; }
.badge-yellow { background: #fef9c3; color: #ca8a04; }
.badge-red    { background: #fee2e2; color: #dc2626; }
.badge-gray   { background: #f1f5f9; color: #64748b; }
.badge-orange { background: #ffedd5; color: #ea580c; }

/* ===== Progress Bar ===== */
.progress-bar {
    height: 6px;
    border-radius: 99px;
    background: #e2e8f0;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    border-radius: 99px;
    transition: width 0.6s ease;
}

/* ===== Chat Module ===== */
.chat-msg { display: flex; gap: 8px; align-items: flex-start; }
.chat-msg.own { flex-direction: row-reverse; }
.chat-bubble {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.4;
}
.chat-bubble.other { background: #f1f5f9; color: #1e293b; border-bottom-left-radius: 4px; }
.chat-bubble.own   { background: #2563eb; color: #fff; border-bottom-right-radius: 4px; }

/* ===== Topbar Search ===== */
#globalSearch:focus + div kbd { opacity: 0; }

/* ===== Org Modal z-index ===== */
.z-60 { z-index: 60; }

/* ===== Animations ===== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.animate-in { animation: fadeIn 0.25s ease forwards; }

/* ===== Module Library modal: open/close animation (spec C1) ===== */
#moduleLibraryModal .library-modal-backdrop {
    opacity: 0;
    -webkit-backdrop-filter: blur(0px);
    backdrop-filter: blur(0px);
    transition: opacity 250ms cubic-bezier(0.16, 1, 0.3, 1),
                -webkit-backdrop-filter 250ms cubic-bezier(0.16, 1, 0.3, 1),
                backdrop-filter 250ms cubic-bezier(0.16, 1, 0.3, 1);
}
#moduleLibraryModal .library-modal-panel {
    opacity: 0;
    transform: scale(0.96) translateY(8px);
    transition: opacity 250ms cubic-bezier(0.16, 1, 0.3, 1),
                transform 250ms cubic-bezier(0.16, 1, 0.3, 1);
}
#moduleLibraryModal.modal-open .library-modal-backdrop {
    opacity: 1;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}
#moduleLibraryModal.modal-open .library-modal-panel {
    opacity: 1;
    transform: scale(1) translateY(0);
}
/* Closing runs faster than opening. */
#moduleLibraryModal.modal-closing .library-modal-backdrop,
#moduleLibraryModal.modal-closing .library-modal-panel {
    transition-duration: 180ms;
}

/* =========================================================================
   Widget store gallery (spec C1, Phase 2) — магазин-галерея виджетов.
   Вертикальные карточки с живыми превью, чипы-фильтры, конфигуратор.
   Только токены темы (--color-*) — тёмная тема работает из коробки.
   ========================================================================= */

/* --- Чипы-фильтры категорий --- */
.store-filter-chip {
    display: inline-flex;
    align-items: center;
    padding: 5px 12px;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-2);
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.store-filter-chip:hover { background: var(--color-surface-2); }
.store-filter-chip.is-active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #ffffff;
}

/* --- Секции («Все» — подзаголовки по категориям) и сетка 1/2/3 колонки --- */
.store-section { margin-bottom: 22px; }
.store-section:last-child { margin-bottom: 0; }
.store-section-title {
    margin: 0 0 10px 2px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-3);
}
.store-section-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
}
@media (min-width: 640px)  { .store-section-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .store-section-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* --- Вертикальная карточка виджета --- */
.store-card {
    position: relative;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--color-border);
    border-radius: 16px;
    background: var(--color-surface);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease,
                transform 0.2s ease, background-color 0.2s ease;
}
.store-card:hover {
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.08);
    transform: translateY(-2px);
}
/* Лёгкий primary-tint для уже добавленных виджетов. */
.store-card.is-added {
    border-color: color-mix(in srgb, var(--color-primary) 45%, var(--color-border));
    background: color-mix(in srgb, var(--color-primary) 4%, var(--color-surface));
}
.store-card.is-expanded {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 1px var(--color-primary);
}

/* --- Рамка-превью с живой миниатюрой (фикс. аспект, внутренний градиент) --- */
.store-preview {
    position: relative;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    /* Превью «мёртвое»: inline-обработчики отрендеренного виджета не кликабельны. */
    pointer-events: none;
    background: var(--color-surface-2);
    background-image: linear-gradient(165deg,
        color-mix(in srgb, var(--color-surface) 65%, transparent), transparent 55%);
    border-bottom: 1px solid var(--color-border);
}
.store-preview-scale {
    width: 200%;               /* компенсирует scale(0.5): итоговая ширина = 100% */
    transform: scale(0.5);
    transform-origin: top left;
    pointer-events: none;
    padding: 24px;
    /* Нижняя fade-маска: обрез высокого виджета выглядит намеренным. */
    -webkit-mask-image: linear-gradient(to bottom, #000 82%, transparent);
    mask-image: linear-gradient(to bottom, #000 82%, transparent);
}
/* Псевдо-карточка модуля внутри превью — как настоящая на дашборде. */
.store-preview-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

/* --- Бейдж-галочка «добавлен» в углу превью: scale 0 -> 1 spring --- */
.store-added-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    box-shadow: 0 0 0 2px var(--color-surface);
    transform: scale(0);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.store-card.is-added .store-added-badge { transform: scale(1); }

/* --- Мета карточки: название, чип категории, дефолтный размер, кнопка --- */
.store-card-meta {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px 14px;
}
.store-card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
}
.store-card-sub {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
/* Цвет чипа задаётся классами iconBg/iconColor виджета из реестра. */
.store-cat-chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 600;
}
.store-size-hint {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--color-text-3);
}

/* Футер действий карточки: [Настроить] + [Добавить] — два отдельных <button>. */
.store-card-actions {
    display: flex;
    gap: 8px;
}
.store-card-actions .store-card-btn { flex: 1; }
.store-card-actions .store-configure-btn { flex: 1; }

/* Кнопка «Настроить» (secondary): раскрывает конфигуратор, шеврон — состояние. */
.store-configure-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 10px;
    border-radius: 10px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-2);
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.store-configure-btn:hover { background: var(--color-surface-2); }
.store-configure-btn .store-configure-chevron {
    font-size: 9px;
    transition: transform 0.2s ease;
}
.store-configure-btn[aria-expanded="true"] .store-configure-chevron { transform: rotate(180deg); }

/* Кнопка «Добавить» карточки: «+ Добавить» (primary) / «✓ На дашборде» (secondary). */
.store-card-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 10px;
    border-radius: 10px;
    border: none;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    white-space: nowrap;
    cursor: pointer;
    background: var(--color-primary);
    color: #ffffff;
    transition: background-color 0.25s ease, color 0.25s ease;
}
.store-card-btn:hover { background: color-mix(in srgb, var(--color-primary) 85%, #000000); }
.store-card-btn .store-btn-ic { font-size: 10px; }
.store-card-btn .store-btn-ic-check { display: none; }
.store-card-btn.is-added {
    background: var(--color-surface-2);
    color: var(--color-text-2);
}
.store-card-btn.is-added .store-btn-ic-add { display: none; }
.store-card-btn.is-added .store-btn-ic-check { display: inline; }

/* --- Конфигуратор: full-width панель под рядом карточки --- */
.store-configurator {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px;
    border: 1px solid color-mix(in srgb, var(--color-primary) 35%, var(--color-border));
    border-radius: 16px;
    background: color-mix(in srgb, var(--color-primary) 3%, var(--color-surface));
    animation: storeConfigIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
@media (min-width: 768px) {
    .store-configurator { grid-template-columns: minmax(0, 5fr) minmax(0, 4fr); }
}
@keyframes storeConfigIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.store-configurator .store-preview {
    aspect-ratio: 16 / 10;
    border: 1px solid var(--color-border);
    border-radius: 14px;
}
/* Пилюли размеров дают визуальный отклик в предпросмотре: ширина
   псевдо-карточки повторяет ширину модуля в колонках дашборда (S уже, L шире). */
.store-preview--config .store-preview-card { margin: 0 auto; }
.store-preview--config .store-preview-card[data-size="sm"] { max-width: 56%; }
.store-preview--config .store-preview-card[data-size="md"] { max-width: 78%; }
.store-preview--config .store-preview-card[data-size="lg"] { max-width: 100%; }
.store-config-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}
.store-config-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--color-text);
}
.store-config-label {
    margin-bottom: 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-3);
}

/* Пилюли размеров S/M/L (рендерятся только доступные из def.sizes). */
.store-size-pills { display: flex; gap: 6px; }
.store-size-pill {
    min-width: 44px;
    padding: 7px 0;
    border-radius: 10px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-2);
    font-size: 12px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.store-size-pill:hover { background: var(--color-surface-2); }
.store-size-pill.is-active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #ffffff;
}

/* Generic select-поле настроек из configSchema. */
.store-config-select {
    width: 100%;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 13px;
    font-family: inherit;
}
.store-config-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 20%, transparent);
}

/* Кнопка «Добавить на дашборд» / «Добавить ещё». */
.store-add-btn {
    margin-top: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 12px;
    border: none;
    background: var(--color-primary);
    color: #ffffff;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.15s ease;
}
.store-add-btn:hover { background: color-mix(in srgb, var(--color-primary) 85%, #000000); }
.store-add-btn:active { transform: scale(0.98); }

/* Кнопка «Сбросить раскладку» в шапке модалки: hover-тона через color-mix
   от токенов темы — Tailwind red-50/red-200 не покрыты токен-ремапами и
   вспыхивали розовым в тёмной теме. */
.store-reset-btn:hover {
    color: #ef4444;
    background: color-mix(in srgb, #ef4444 14%, var(--color-surface));
    border-color: color-mix(in srgb, #ef4444 45%, var(--color-border));
}

/* Пустая выдача поиска/фильтра. */
.store-empty {
    padding: 48px 0;
    text-align: center;
    font-size: 13px;
    color: var(--color-text-3);
}

/* Подсветка только что добавленного из магазина модуля на дашборде:
   scale 0.85 -> 1 + кольцо primary; кольцо гаснет по transition .module-card. */
.module-just-added {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 55%, transparent);
    animation: moduleJustAdded 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes moduleJustAdded {
    from { opacity: 0; transform: scale(0.85); }
    to   { opacity: 1; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    #moduleLibraryModal .library-modal-backdrop,
    #moduleLibraryModal .library-modal-panel,
    .store-card,
    .store-added-badge,
    .store-filter-chip,
    .store-size-pill,
    .store-card-btn,
    .store-configure-btn,
    .store-configure-btn .store-configure-chevron,
    .store-reset-btn,
    .store-add-btn { transition: none; }
    .store-card:hover { transform: none; }
    .store-configurator { animation: none; }
    .module-just-added { animation: none; }
    .animate-in { animation: none; }
}

/* ===== Tooltip ===== */
[data-tooltip] { position: relative; }
[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #fff;
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 6px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 100;
}

/* ===== Spreadsheet Table ===== */
.sheet-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 13px;
}
.sheet-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 8px 10px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 2px solid var(--color-border);
    border-right: 1px solid var(--color-border);
    white-space: nowrap;
    user-select: none;
}
.sheet-table th:last-child { border-right: none; }
/* Editable-column header: pen hint + sortable affordance. */
.sheet-th-edit { margin-left: 6px; font-size: 12px; color: var(--color-text-3); }
.sheet-th-edit:hover { color: var(--color-primary); }
.sheet-th--sortable { cursor: pointer; }
.sheet-th--sortable:hover { background: var(--color-surface-2); }
.sheet-sort-icon { margin-left: 6px; font-size: 12px; color: var(--color-text-3); }
.sheet-th--sorted { color: var(--color-text); }
.sheet-th--sorted .sheet-sort-icon { color: var(--color-primary); }
.sheet-table th:focus-visible,
.sheet-table td.cell-editable:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 2px var(--color-primary-light, #bfdbfe);
    border-color: var(--color-primary, #2563eb);
}
.sheet-table td {
    padding: 0;
    border-bottom: 1px solid var(--color-border);
    border-right: 1px solid var(--color-border);
    vertical-align: middle;
    min-width: 80px;
}
.sheet-table td:last-child { border-right: none; }
/* Persistent editable-column tint (spec §2.3). */
.sheet-table td.cell-editable { background: var(--sheet-editable-bg); }
.sheet-table td.cell-editable { position: relative; cursor: cell; }
/* Single-click selection: outline only, no edit (spec Q2). */
.sheet-table td.cell-selected {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}
/* Editable cells carry a faint left rail as a persistent at-rest affordance. */
.sheet-table td.cell-editable::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--color-primary);
    opacity: 0.22;
    transition: opacity 0.15s;
}
/* Pencil hint: faint at rest, fully lit on hover/focus. */
.cell-edit-hint {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: var(--color-primary);
    opacity: 0.28;
    pointer-events: none;
    transition: opacity 0.15s, font-size 0.15s;
}
.sheet-table td.cell-editable:hover { background: var(--color-surface-2); }
.sheet-table td.cell-editable:hover::before,
.sheet-table td.cell-editable:focus-visible::before,
.sheet-table td.cell-selected::before { opacity: 1; }
.sheet-table td.cell-editable:hover .cell-edit-hint,
.sheet-table td.cell-editable:focus-visible .cell-edit-hint {
    opacity: 1;
    font-size: 14px;
}
.sheet-table td .cell-inner {
    display: block;
    padding: 6px 10px;
    min-height: 36px;
    cursor: inherit;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Reserve room for the pencil hint + left rail in editable cells. */
.sheet-table td.cell-editable .cell-inner {
    padding-left: 12px;
    padding-right: 24px;
}
.sheet-table td input.cell-input,
.sheet-table td select.cell-input {
    width: 100%;
    padding: 6px 10px;
    border: none;
    outline: 2px solid var(--color-primary, #2563eb);
    background: var(--color-primary-light, #eff6ff);
    font-size: 13px;
    font-family: inherit;
    color: var(--color-text, #0f172a);
    min-height: 36px;
}
.sheet-table td.cell-dirty .cell-inner::after {
    content: '';
    position: absolute;
    top: 2px; right: 2px;
    width: 5px; height: 5px;
    border-radius: 50%;
    background: #f59e0b;
}
.sheet-table td.cell-dirty { position: relative; }
/* Server-rejected cell — themed via variables (both light and dark). */
.sheet-table td.cell-rejected {
    background: var(--sheet-rejected-bg);
    box-shadow: inset 0 0 0 1px var(--sheet-rejected-border);
}
/* Numeric columns (money / number / percent): right-aligned tabular figures so
   digits line up vertically for scan-reading amounts. */
.sheet-table th.sheet-th--num { text-align: right; }
.sheet-table td.cell-num .cell-inner {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.sheet-table td.cell-num input.cell-input {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.sheet-row-new td { background: #f0fdf4 !important; }
[data-theme="dark"] .sheet-row-new td { background: #14532d33 !important; }

/* Custom scrollbar for the registry scroll area (spec §2.3: 5px → 10px). */
.accounting-sheet-scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.accounting-sheet-scroll::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 999px;
}
.accounting-sheet-scroll::-webkit-scrollbar-track { background: transparent; }

/* ===== Registry history disclosure (moved out from under the grid) ===== */
.acc-history__toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 2px 0;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
}
.acc-history__chevron {
    font-size: 12px;
    transition: transform 0.2s var(--ease-out, ease);
}
.acc-history[data-history-open="true"] .acc-history__chevron { transform: rotate(90deg); }
.acc-history__toggle:hover .acc-history__chevron { color: var(--color-primary); }
.acc-history__count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--color-surface-2);
    color: var(--color-text-2);
    font-size: 11px;
    font-weight: 600;
}
/* Collapsed by default: hide the panel and the descriptive hint. */
.acc-history__panel { display: none; }
.acc-history__hint { display: none; }
.acc-history[data-history-open="true"] .acc-history__panel { display: block; }
.acc-history[data-history-open="true"] .acc-history__hint { display: block; }

/* ===== Severity dot (replaces the border-l-4 strip) ===== */
.acc-sev-dot {
    position: absolute;
    right: -2px;
    bottom: -2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    box-shadow: 0 0 0 2px var(--color-surface);
}
.acc-sev-dot--info    { background: var(--color-primary); }
.acc-sev-dot--warning { background: #f59e0b; }
.acc-sev-dot--error   { background: #ef4444; }

/* ===== Reusable pager (spec §2.2) ===== */
.pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-top: 1px solid var(--color-border);
}
.pager-count { font-size: 13px; color: var(--color-text-3); }
.pager-controls { display: flex; align-items: center; gap: 4px; }
.pager-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border-radius: 10px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--color-text-2);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.pager-btn:hover:not(:disabled) { background: var(--color-surface-2); }
.pager-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.pager-btn--active { background: var(--color-primary); color: #fff; }
.pager-btn--active:hover { background: var(--color-primary); }
.pager-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--color-primary-light, #bfdbfe);
    border-color: var(--color-primary, #2563eb);
}
.pager-ellipsis { padding: 0 4px; color: var(--color-text-3); }

/* ===== Theme Switcher Panel ===== */
/* Panel is built and styled entirely via JS (theme.js) */
.theme-swatch {
    width: 28px; height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s;
}
.theme-swatch:hover { transform: scale(1.15); }
.theme-swatch.active { outline: 2px solid var(--color-primary, #2563eb); outline-offset: 2px; transform: scale(1.15); }

/* =========================================================================
   Auth / Login  (spec T2 — one centered card, token-driven, theme-aware)
   Self-contained: does not rely on Tailwind utility classes so the login
   surface stays intact even without the CDN. Colors come from --color-*
   tokens, so light/dark both work via [data-theme].
   ========================================================================= */
.auth-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2.5rem 1.25rem;
    background: var(--color-bg);
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.08);
    padding: 2rem 1.75rem 1.75rem;
}
[data-theme="dark"] .auth-card { box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45); }

.auth-head { text-align: center; }
.auth-logo {
    width: 52px;
    height: 52px;
    margin: 0 auto;
    border-radius: 14px;
    background: var(--color-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    box-shadow: 0 6px 18px color-mix(in srgb, var(--color-primary) 35%, transparent);
}
.auth-org {
    margin-top: 0.85rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text-3);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    word-break: break-word;
}
.auth-title {
    margin-top: 0.35rem;
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--color-text);
}
.auth-subtitle {
    margin-top: 0.4rem;
    font-size: 0.875rem;
    line-height: 1.45;
    color: var(--color-text-2);
}

.auth-alert {
    margin-top: 1.25rem;
    border-radius: 12px;
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: #b91c1c;
    padding: 0.75rem 0.9rem;
    font-size: 0.8125rem;
    line-height: 1.4;
    display: flex;
    gap: 0.55rem;
    align-items: flex-start;
}
.auth-alert i { margin-top: 0.1rem; }
[data-theme="dark"] .auth-alert {
    border-color: #7f1d1d;
    background: #450a0a;
    color: #fca5a5;
}

.auth-form { margin-top: 1.5rem; display: flex; flex-direction: column; gap: 1.1rem; }
.auth-field { display: flex; flex-direction: column; gap: 0.4rem; }
.auth-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text-2);
}
.auth-input {
    width: 100%;
    border-radius: 11px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    padding: 0.65rem 0.8rem;
    font-size: 0.9375rem;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.auth-input::placeholder { color: var(--color-text-3); }
.auth-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 20%, transparent);
}

.auth-remember {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    color: var(--color-text-2);
    user-select: none;
    cursor: pointer;
}
.auth-remember input { width: 15px; height: 15px; accent-color: var(--color-primary); cursor: pointer; }

.auth-submit {
    width: 100%;
    border: none;
    border-radius: 11px;
    background: var(--color-primary);
    color: #fff;
    padding: 0.7rem 1rem;
    font-size: 0.9375rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: filter 0.15s, opacity 0.15s;
}
.auth-submit:hover:not(:disabled) { filter: brightness(0.94); }
.auth-submit:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 30%, transparent);
}
.auth-submit:disabled { opacity: 0.75; cursor: progress; }
.auth-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-top-color: #fff;
    border-radius: 50%;
    animation: authSpin 0.7s linear infinite;
}
@keyframes authSpin { to { transform: rotate(360deg); } }

.auth-support {
    margin-top: 1.4rem;
    padding-top: 1.1rem;
    border-top: 1px solid var(--color-border);
    text-align: center;
    font-size: 0.8125rem;
    color: var(--color-text-3);
    line-height: 1.5;
}
.auth-support a { color: var(--color-primary); text-decoration: none; font-weight: 600; }
.auth-support a:hover { text-decoration: underline; }
