/* Стили, вынесенные из layout/base.html (M5 аудита от 21.08).
 *
 * Раньше это были пять <style>-блоков внутри шаблона: 393 строки, которые Thymeleaf
 * разбирал на каждый рендер, а браузер не мог закешировать — они приезжали с каждым
 * HTML-ответом. Порядок блоков сохранён: он важен, каскад собирался именно так.
 *
 * Подключается после tokens.css — как и было в шаблоне.
 */

/* ── блок 1 из base.html ─────────────────────────────────── */
:root {
            --radius-sm: 0.125rem;
            --radius: 0.25rem;
            --radius-md: 0.375rem;
            --radius-lg: 0.5rem;
            --radius-xl: 0.75rem;
            --radius-2xl: 1rem;
            --radius-3xl: 1.5rem;
        }

/* ── блок 2 из base.html ─────────────────────────────────── */
[id^="panel-"] { transition: opacity 0.08s ease; }
        [id^="panel-"].hidden { opacity: 0; }

/* ── блок 3 из base.html ─────────────────────────────────── */
/* Base colors */
        .bg-base-100  { background-color: var(--color-base-100); }
        .bg-base-200  { background-color: var(--color-base-200); }
        .bg-base-300  { background-color: var(--color-base-300); }
        .text-base-content   { color: var(--color-base-content); }
        .border-base-300     { border-color: var(--color-base-300); }
        .divide-base-300 > * + * { border-color: var(--color-base-300); }
        /* Primary */
        .bg-primary          { background-color: var(--color-primary); }
        .text-primary        { color: var(--color-primary); }
        .text-primary-content{ color: var(--color-primary-content); }
        .border-primary      { border-color: var(--color-primary); }
        /* Semantic */
        .text-error          { color: var(--color-error); }
        .text-success        { color: var(--color-success); }
        .text-warning        { color: var(--color-warning); }
        .text-info           { color: var(--color-info); }
        /* Opacity variants — color-mix() works in all modern browsers */
        .text-base-content\/60 { color: color-mix(in oklch, var(--color-base-content) 60%, transparent); }
        .text-base-content\/50 { color: color-mix(in oklch, var(--color-base-content) 50%, transparent); }
        .text-base-content\/40 { color: color-mix(in oklch, var(--color-base-content) 40%, transparent); }
        .text-base-content\/30 { color: color-mix(in oklch, var(--color-base-content) 30%, transparent); }
        .text-base-content\/25 { color: color-mix(in oklch, var(--color-base-content) 25%, transparent); }
        .bg-primary\/10  { background-color: color-mix(in oklch, var(--color-primary) 10%, transparent); }
        .bg-primary\/20  { background-color: color-mix(in oklch, var(--color-primary) 20%, transparent); }
        .bg-error\/10    { background-color: color-mix(in oklch, var(--color-error) 10%, transparent); }
        .bg-base-content\/5  { background-color: color-mix(in oklch, var(--color-base-content) 5%, transparent); }
        .bg-base-content\/8  { background-color: color-mix(in oklch, var(--color-base-content) 8%, transparent); }
        .bg-base-content\/10 { background-color: color-mix(in oklch, var(--color-base-content) 10%, transparent); }
        .bg-base-content\/15 { background-color: color-mix(in oklch, var(--color-base-content) 15%, transparent); }
        .border-base-300\/40 { border-color: color-mix(in oklch, var(--color-base-300) 40%, transparent); }
        .border-base-content\/20 { border-color: color-mix(in oklch, var(--color-base-content) 20%, transparent); }
        /* Hover variants */
        .hover\:bg-base-content\/10:hover { background-color: color-mix(in oklch, var(--color-base-content) 10%, transparent); }
        .hover\:text-base-content:hover  { color: var(--color-base-content); }
        .hover\:bg-error\/10:hover       { background-color: color-mix(in oklch, var(--color-error) 10%, transparent); }
        .hover\:bg-base-300\/20:hover    { background-color: color-mix(in oklch, var(--color-base-300) 20%, transparent); }
        .hover\:text-error:hover         { color: var(--color-error); }
        .hover\:text-primary:hover       { color: var(--color-primary); }
        .hover\:text-base-content\/70:hover { color: color-mix(in oklch, var(--color-base-content) 70%, transparent); }
        .hover\:text-base-content\/80:hover { color: color-mix(in oklch, var(--color-base-content) 80%, transparent); }
        .hover\:opacity-80:hover         { opacity: 0.8; }
        .hover\:bg-success\/10:hover     { background-color: color-mix(in oklch, var(--color-success) 10%, transparent); }
        .hover\:bg-warning\/10:hover     { background-color: color-mix(in oklch, var(--color-warning) 10%, transparent); }
        .hover\:bg-info\/10:hover        { background-color: color-mix(in oklch, var(--color-info) 10%, transparent); }
        .hover\:bg-primary\/18:hover     { background-color: var(--primary-tint-strong); }
        .hover\:text-info:hover         { color: var(--color-info); }
        .cqs-select { border: none; appearance: none; -webkit-appearance: none; cursor: pointer; font-family: var(--font-mono); }
        /* Inline error banner (post-add errors etc.) */
        .alert-error-soft {
            background-color: color-mix(in oklch, var(--color-error) 10%, transparent);
            border: 1px solid color-mix(in oklch, var(--color-error) 20%, transparent);
            color: var(--color-error);
        }
        [data-theme="light"] .alert-error-soft { background-color: color-mix(in oklch, var(--color-error) 10%, white); }
        /* Muted mono column values (Age / Karma / Checked) */
        .mono-muted { font-family: var(--font-mono); font-size: 12px; color: color-mix(in oklch, var(--color-base-content) 65%, transparent); }
        /* Border opacity variants */
        .border-base-300\/50             { border-color: color-mix(in oklch, var(--color-base-300) 50%, transparent); }
        /* Divide variants */
        .divide-base-300\/0 > * + *      { border-color: transparent; }
        /* Border radius — explicit, !important beats Tailwind CDN var(--radius-xl) when undefined */
        .rounded-sm   { border-radius: 0.125rem !important; }
        .rounded      { border-radius: 0.25rem  !important; }
        .rounded-md   { border-radius: 0.375rem !important; }
        .rounded-lg   { border-radius: 0.5rem   !important; }
        .rounded-xl   { border-radius: 0.75rem  !important; }
        .rounded-2xl  { border-radius: 1rem     !important; }
        .rounded-3xl  { border-radius: 1.5rem   !important; }
        .rounded-full { border-radius: 9999px   !important; }
        /* Overflow & display */
        .overflow-hidden  { overflow: hidden; }
        .overflow-y-auto  { overflow-y: auto; }
        .overflow-x-auto  { overflow-x: auto; }
        .truncate         { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
        .whitespace-nowrap    { white-space: nowrap; }
        .whitespace-pre-wrap  { white-space: pre-wrap; }
        /* Shadows */
        .shadow-lg { box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1); }
        /* Transitions */
        .transition-all     { transition-property: all; transition-timing-function: cubic-bezier(.4,0,.2,1); transition-duration: 150ms; }
        .transition-colors  { transition-property: color, background-color, border-color; transition-timing-function: cubic-bezier(.4,0,.2,1); transition-duration: 150ms; }
        .transition-opacity { transition-property: opacity; transition-timing-function: cubic-bezier(.4,0,.2,1); transition-duration: 150ms; }
        .transition-transform { transition-property: transform; transition-timing-function: cubic-bezier(.4,0,.2,1); transition-duration: 150ms; }
        /* Animations */
        .animate-spin  { animation: spin  1s linear infinite; }
        .animate-pulse { animation: pulse 2s cubic-bezier(.4,0,.6,1) infinite; }
        @keyframes spin  { to { transform: rotate(360deg); } }
        @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
        /* Typography helpers */
        .tabular-nums  { font-variant-numeric: tabular-nums; }
        .line-clamp-2  { overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
        .line-clamp-3  { overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; }
        .select-none   { user-select: none; }
        .cursor-pointer { cursor: pointer; }
        /* Badge border-radius — badge-soft without .badge has no rounding;
           Tailwind CDN can also clobber FlyonUI's .badge radius */
        .badge, .badge-soft { border-radius: 0.375rem !important; }
        .badge-soft { font-size: 10px; }
        /* Input focus ring */
        .input:focus, .input:focus-visible,
        .select:focus, .select:focus-visible,
        .textarea:focus, .textarea:focus-visible {
            outline: 2px solid var(--color-primary) !important;
            outline-offset: 1px;
        }
        /* Collapsible details chevron */
        details summary { list-style: none; }
        details summary::-webkit-details-marker { display: none; }
        .chevron { transition: transform 0.2s ease; }
        details[open] .chevron { transform: rotate(90deg); }
        /* Backdrop-blur (header) */
        .backdrop-blur-md { backdrop-filter: blur(12px); }
        /* group-open rotate */
        .group-open .group-open\:rotate-90 { transform: rotate(90deg); }
        details[open] .group-open\:rotate-90 { transform: rotate(90deg); }

/* ── блок 4 из base.html ─────────────────────────────────── */
/* Row hover — table rows only; lighter in light mode (see handoff doc) */
        .row-hover:hover { background-color: color-mix(in oklch, var(--color-base-content) 4%, transparent); }
        [data-theme="light"] .row-hover:hover { background-color: color-mix(in oklch, var(--color-base-content) 3%, transparent); }
        /* Light mode: soft tints mixed with pure transparency read as almost invisible on white —
           mix with white instead, at a higher ratio, per handoff doc */
        .b b-neutral {
            display: inline-flex; align-items: center; padding: 3px 9px;
            border-radius: 6px; font-size: 11.5px; font-weight: 600; line-height: 1.2;
            white-space: nowrap;
            background-color: color-mix(in oklch, var(--color-base-content) 10%, var(--color-base-200));
            color: color-mix(in oklch, var(--color-base-content) 70%, transparent);
        }
        .b b-primary {
            display: inline-flex; align-items: center; padding: 2px 8px;
            border-radius: 9999px; font-size: 10px; font-weight: 600; line-height: 1.4;
            white-space: nowrap;
            background-color: color-mix(in oklch, var(--color-primary) 14%, transparent);
            color: color-mix(in oklch, var(--color-primary) 25%, white);
        }
        [data-theme="light"] .b b-primary {
            background-color: color-mix(in oklch, var(--color-primary) 14%, white);
            color: var(--color-primary);
        }

        /* Circular avatar treatment for username cells */
        .avatar-primary {
            width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
            display: inline-flex; align-items: center; justify-content: center;
            background-color: color-mix(in oklch, var(--color-primary) 12%, transparent);
            border: 1px solid color-mix(in oklch, var(--color-primary) 30%, transparent);
        }

        /* Row-action icon buttons (Check / Edit) — same footprint, two roles */
        .icon-btn {
            display: inline-flex; align-items: center; justify-content: center;
            width: 26px; height: 26px; border-radius: 6px;
            transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
        }
        .icon-btn-primary {
            background-color: color-mix(in oklch, var(--color-primary) 10%, transparent);
            border: 1px solid color-mix(in oklch, var(--color-primary) 20%, transparent);
            color: var(--color-primary);
        }
        .icon-btn-primary:hover { background-color: var(--primary-tint-strong); }
        .icon-btn-neutral {
            background-color: transparent;
            border: 1px solid var(--color-base-300);
            color: color-mix(in oklch, var(--color-base-content) 60%, transparent);
        }
        .icon-btn-neutral:hover {
            color: var(--color-base-content);
            border-color: color-mix(in oklch, var(--color-base-content) 30%, transparent);
        }

        /* Header action buttons — one filled primary, one outline-neutral, same footprint */
        .btn-header-primary {
            display: inline-flex; align-items: center; gap: 6px;
            background-color: var(--color-primary); color: #fff; border: none;
            padding: 8px 16px; border-radius: 8px; font-weight: 600; font-size: 13px;
            transition: opacity 0.15s ease;
        }
        .btn-header-primary:hover { opacity: 0.9; }
        .btn-header-outline {
            display: inline-flex; align-items: center; gap: 6px;
            background-color: transparent; border: 1px solid var(--color-base-300);
            color: color-mix(in oklch, var(--color-base-content) 80%, transparent);
            padding: 8px 16px; border-radius: 8px; font-weight: 600; font-size: 13px;
            transition: background-color 0.15s ease;
        }
        .btn-header-outline:hover { background-color: color-mix(in oklch, var(--color-base-content) 6%, transparent); }
        .btn-header-outline:disabled { opacity: 0.6; cursor: default; }

/* ── блок 5 из base.html ─────────────────────────────────── */
html, body {
            color: var(--color-base-content);
            background-color: var(--color-base-100);
        }
        .material-symbols-outlined {
            font-size: 18px;
            vertical-align: middle;
            font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 20;
            line-height: 1;
        }
        .sidebar-link.nav-active .material-symbols-outlined {
            font-variation-settings: 'FILL' 1, 'wght' 500, 'GRAD' 0, 'opsz' 20;
        }
        .htmx-indicator { display: none; }
        .htmx-request .htmx-indicator { display: flex; }
        .htmx-request.htmx-indicator { display: flex; }
        /* rpPollRows marks the indicator quiet for the 15s background refresh.
           Three classes, so it outranks the two rules above without !important. */
        .htmx-indicator.rp-quiet.htmx-request { display: none; }
        ::-webkit-scrollbar { width: 5px; height: 5px; }
        ::-webkit-scrollbar-track { background: transparent; }
        ::-webkit-scrollbar-thumb { border-radius: 10px; }
        [data-theme="dark"]  ::-webkit-scrollbar-thumb { background: oklch(40% 0.01 265); }
        [data-theme="light"] ::-webkit-scrollbar-thumb { background: oklch(78% 0.005 265); }
        [hx-swap] > * { animation: fadeIn 0.15s ease; }
        @keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
        /* ── Shadow depth system ──────────────────────────────────── */
        [data-theme="light"] {
            --shadow-card:    0 1px 4px 0 rgb(0 0 0 / 0.07), 0 0 0 1px rgb(0 0 0 / 0.04);
            --shadow-card-lg: 0 4px 16px 0 rgb(0 0 0 / 0.10), 0 1px 4px 0 rgb(0 0 0 / 0.05);
        }
        [data-theme="dark"] {
            --shadow-card:    0 2px 8px 0 rgb(0 0 0 / 0.30), 0 1px 3px 0 rgb(0 0 0 / 0.15);
            --shadow-card-lg: 0 4px 20px 0 rgb(0 0 0 / 0.45), 0 2px 6px 0 rgb(0 0 0 / 0.25);
        }
        .shadow-card    { box-shadow: var(--shadow-card); }
        .shadow-card-lg { box-shadow: var(--shadow-card-lg); }
        /* Apply shadow to FlyonUI card-border (normally has shadow=none) */
        .card-border { box-shadow: var(--shadow-card) !important; }
        /* Stats block depth */
        .stats { box-shadow: var(--shadow-card); }
        /* ── Sidebar v2 shell: grid on desktop, overlay drawer on mobile ────
           No width transition on the grid on purpose — animating
           grid-template-columns reflowed the sticky header and the
           fixed-layout table on every frame. The collapse snaps; only the
           rail handle and the mobile slide-in animate. ──────────────── */
        .sidebar-aside { transition: transform 0.22s cubic-bezier(.4,0,.2,1); }
        @media (max-width: 1023px) {
            .sidebar-aside {
                position: fixed; top: 0; left: 0; height: 100%;
                width: 15rem !important;
                transform: translateX(-100%);
                z-index: calc(var(--z-modal) + 1);
            }
            [data-mobile-menu="open"] .sidebar-aside { transform: translateX(0); }
            /* header space for hamburger button */
            header { padding-left: 3.5rem; }
            /* show hamburger */
            #mobile-hamburger { display: flex; z-index: calc(var(--z-modal) + 2); }
            /* mobile backdrop */
            .mobile-backdrop { display: block; }
            [data-mobile-menu="open"] .mobile-backdrop { opacity: 1; pointer-events: auto; }
        }
        @media (min-width: 1024px) {
            /* The shell grid must only apply to pages that HAVE a sidebar. Scoped
               with :has() rather than a plain `body` selector: login and register
               have no sidebar and set their own `flex items-center justify-center`
               on <body>, but that is a Tailwind utility and Tailwind v4 emits
               utilities inside @layer — and any layered rule loses to unlayered
               CSS like this block, whatever the specificity. So a bare
               `body { display: grid }` silently beat it and dropped the login card
               into the 244px sidebar column, leaving the rest of the page empty. */
            body:has(> .sidebar-aside) {
                display: grid; grid-template-columns: 200px minmax(0, 1fr); min-height: 100vh;
            }
            [data-sidebar="collapsed"] body:has(> .sidebar-aside) { grid-template-columns: 64px minmax(0, 1fr); }
            /* …and the sidebar-less pages get their centring stated here too, rather
               than left to the `flex items-center justify-center` on their <body>:
               that is a layered utility and cannot be relied on to win. Only
               auth/login and auth/register match, and both want a centred card. */
            body:not(:has(> .sidebar-aside)) {
                display: flex; align-items: center; justify-content: center; min-height: 100vh;
            }
            .sidebar-aside { position: sticky; top: 0; height: 100vh; transform: none; width: auto; }
            .mobile-backdrop { display: none !important; }
        }
        /* ── Sidebar collapse state (shared) ────────────────────────── */
        [data-sidebar="collapsed"] .sidebar-text   { display: none; }
        [data-sidebar="collapsed"] .logo-text      { display: none; }
        [data-sidebar="collapsed"] .logo-row       { justify-content: center; padding-left: 0; padding-right: 0; }
        [data-sidebar="collapsed"] .sidebar-toggle { transform: rotate(180deg); }
        .sidebar-link {
            height: 34px; width: 100%;
            display: flex; align-items: center; gap: 10px;
            padding: 0 10px; border: 0; border-radius: var(--r-sm);
            background: transparent; color: var(--text);
            font-family: inherit; font-size: 13px; font-weight: 500;
            white-space: nowrap; cursor: pointer; text-align: left;
        }
        .sidebar-link:hover { background: var(--row-hover); }
        .sidebar-link.nav-active { color: var(--primary); background: var(--primary-tint); font-weight: 600; }
        [data-sidebar="collapsed"] .sidebar-link { justify-content: center; padding: 0; }
        /* Icon-only rail tooltips — the .tt primitive, hover/focus triggered,
           shown only when the sidebar is actually collapsed (in the expanded
           rail the label text next to the icon already says the same thing) */
        .tt-wrap { position: relative; }
        /* display:none, а НЕ visibility:hidden — в этом и был горизонтальный скролл
           сайдбара. Подсказка стоит на left:100%+8px, то есть заведомо за правым краем
           списка; скрытый через visibility элемент всё равно входит в область прокрутки,
           а overflow-y:auto на списке по спецификации делает overflow-x тоже auto. То
           есть скролл создавали подсказки, которых не видно. */
        .tt-wrap > .tt {
            left: calc(100% + 8px); top: 50%; transform: translateY(-50%);
            white-space: nowrap;
            display: none; pointer-events: none;
        }
        [data-sidebar="collapsed"] .tt-wrap:hover > .tt,
        [data-sidebar="collapsed"] .tt-wrap:focus-within > .tt { display: block; }
        /* Вертикальная прокрутка меню — только когда оно правда не влезает. Держать её
           всегда нельзя по той же причине: показанная подсказка снова растянула бы
           список по горизонтали, потому что overflow-x у него был бы auto. */
        .sidebar-nav { overflow: visible; }
        @media (max-height: 720px) {
            .sidebar-nav { overflow-y: auto; overflow-x: hidden; }
            /* На низком экране список прокручивается, и подсказку он бы обрезал —
               в этом режиме её и не показываем, метку видно в развёрнутом сайдбаре. */
            .sidebar-nav .tt-wrap > .tt { display: none !important; }
        }
        /* Theme control: segmented (expanded) vs icon-only cycle button (collapsed) */
        [data-sidebar="collapsed"] .js-theme-seg { display: none; }
        .js-theme-icon { display: none; }
        [data-sidebar="collapsed"] .js-theme-icon { display: block; }
        /* ── Mobile backdrop ──────────────────────────────────────── */
        .mobile-backdrop {
            display: none;
            position: fixed; inset: 0; z-index: var(--z-modal);
            background: rgb(0 0 0 / 0.5);
            opacity: 0; pointer-events: none;
            transition: opacity 0.22s ease;
        }
        /* ── Stats vertical on mobile ─────────────────────────────── */
        @media (max-width: 639px) {
            .stats.stats-horizontal { flex-direction: column; }
            .stats.stats-horizontal .stat { border-left: 0; border-top: 1px solid var(--color-base-300); }
        }
        /* ── Always-visible thin scrollbar (hints horizontal scroll in
           narrow widgets like table pickers, where a hover-only scrollbar
           is easy to miss) ─────────────────────────────────────────── */
        .scroll-hint { scrollbar-width: thin; }
        .scroll-hint::-webkit-scrollbar { height: 6px; }
        .scroll-hint::-webkit-scrollbar-thumb { background: var(--color-base-content); opacity: 0.25; border-radius: 3px; }
        .scroll-hint::-webkit-scrollbar-track { background: transparent; }

        /* ── HTMX request indicators ──────────────────────────────── */
        #htmx-bar {
            position: fixed; top: 0; left: 0; width: 100%; height: 2px;
            z-index: var(--z-toast); pointer-events: none;
            background: var(--color-primary);
            transform-origin: left; transform: scaleX(0); opacity: 0;
        }
        .htmx-req-active { opacity: 0.55 !important; pointer-events: none !important; cursor: wait !important; }
        /* ── Counter popover trigger ──────────────────────────────────────
           Replaces the bare number in a relation cell (Subs / Accounts /
           Posts). 22px tall, not the 32px of a normal control: it lives in a
           36px compact row and must not make the whole row read as a button.
           The primary colour on the number is the only affordance saying "this
           one opens". */
        .rp-count {
            height: 22px; padding: 0 6px;
            font-family: var(--font-mono);
            color: var(--primary);
        }
        .rp-count-arrow { transition: transform var(--motion-ui) var(--ease-ui); }
        .rp-count[aria-expanded="true"] .rp-count-arrow { transform: rotate(180deg); }
        /* Touch: 22px is under the 32px hit-area floor, so grow the padding into
           a negative margin — the hit area reaches 38px, the row height does not move. */
        @media (hover: none) {
            .rp-count { padding: 8px 6px; margin: -8px 0; }
        }

        /* Toast motion only — the .toast-stack / .toast look lives in tokens.css §8.
           Toasts slide in from the right edge they are anchored to (top-right),
           and each is click-to-dismiss, so a long error can be cleared early. */
        .toast {
            cursor: pointer;
            transform: translateX(calc(100% + 24px)); opacity: 0;
            transition: transform 0.22s cubic-bezier(0.34,1.56,0.64,1), opacity 0.18s ease;
        }
        .toast.show    { transform: translateX(0); opacity: 1; }
        .toast.leaving { transform: translateX(calc(100% + 24px)); opacity: 0; }
