:root { color-scheme: light dark; }
    body { font-family: system-ui, sans-serif; max-width: 880px; margin: 32px auto; padding: 0 16px; line-height: 1.45; }
    h1 { font-size: 1.4rem; } h2 { font-size: 1.1rem; margin-top: 24px; }
    .card { border: 1px solid #8884; border-radius: 12px; padding: 14px; margin: 14px 0; }
    button { font-size: .95rem; padding: 7px 14px; border-radius: 8px; border: 1px solid #8888; cursor: pointer; background: #f6f6f8; color: #1c1c1e; }
    button.primary { background: #3b82f6; color: #fff; border-color: #3b82f6; }
    /* Тёмная тема: у обычных кнопок фон захардкожен светлым (#f6f6f8), а текст
       под color-scheme:dark становился светлым → белым по светло-серому = нечитаемо.
       Дадим кнопкам/полям тёмный фон и светлый текст. .primary остаётся синей
       (её селектор специфичнее, фон здесь не переопределяем). */
    @media (prefers-color-scheme: dark) {
      button { background: #2c2c2e; color: #f2f2f7; border-color: #ffffff33; }
      textarea, select, input { background: #1c1c1e; color: #f2f2f7; }
    }
    button:disabled { opacity: .5; cursor: default; }
    button.mini { padding: 2px 8px; font-size: .8rem; }
    textarea { width: 100%; box-sizing: border-box; font: inherit; font-size: .85rem; padding: 6px; border-radius: 8px; border: 1px solid #8886; }
    .thumb { display: flex; gap: 10px; align-items: center; border: 1px solid #8884; border-radius: 10px; padding: 6px; margin: 6px 0; }
    .thumb img { width: 130px; height: 90px; object-fit: cover; border-radius: 6px; background: #8882; }
    .thumb .n { font-weight: 600; width: 1.4em; text-align: center; }
    .photo { display: flex; gap: 12px; }
    .photo img { width: 160px; height: 110px; object-fit: cover; border-radius: 8px; background: #8882; }
    .photo .meta { flex: 1; }
    .scenario { margin: 8px 0 8px 40px; padding: 8px 12px; border-left: 3px solid #3b82f6; }
    .gap { margin: 4px 0 4px 40px; font-size: .8rem; opacity: .6; }
    .bar { height: 8px; background: #8883; border-radius: 4px; overflow: hidden; margin: 8px 0; }
    .bar > div { height: 100%; width: 0; background: #3b82f6; transition: width .3s; }
    .vid { display: flex; gap: 12px; align-items: center; border: 1px solid #8884; border-radius: 10px; padding: 8px; margin: 8px 0; }
    .vid.excluded { opacity: .4; }
    .vid video { width: 220px; border-radius: 8px; }
    /* Монтаж: фото1 фото2 / сценарий / видео + контролы */
    .montage { border: 1px solid #8884; border-radius: 12px; padding: 10px 12px; margin: 10px 0; }
    .montage.excluded { opacity: .45; }
    .montage .mhead { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 6px; }
    .montage .photo { gap: 10px; }
    .montage .mphoto { display: flex; flex-direction: column; align-items: center; gap: 4px; }
    .montage .mphoto img { width: 180px; height: 120px; object-fit: cover; border-radius: 8px; background: #8882; }
    .montage .mscenario { width: 100%; margin: 8px 0; }
    .montage .mclip { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
    .montage .mclip video { width: 280px; border-radius: 8px; }
    .montage .mctl { display: flex; flex-direction: column; gap: 6px; }
    .montage .mnoclip { font-size: .85rem; color: #b45309; padding: 8px 0; }
    .frame { display: flex; gap: 10px; align-items: center; border: 1px solid #8884; border-radius: 10px; padding: 8px; margin: 6px 0; }
    .frame img { width: 150px; height: 100px; object-fit: cover; border-radius: 6px; background: #8882; }
    /* Ревью улучшения: пара оригинал→результат + контролы; reverted = отдаём оригинал */
    .efr { border: 1px solid #8884; border-radius: 10px; padding: 10px; margin: 8px 0; }
    .efr.reverted { border-color: #f59e0b88; background: #f59e0b0d; }
    .efr .pair { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
    .efr .col { display: flex; flex-direction: column; align-items: center; gap: 4px; }
    .efr .col img { width: 220px; height: 150px; object-fit: cover; border-radius: 8px; background: #8882; }
    .efr .col small { opacity: .7; }
    .efr .arrow { align-self: center; font-size: 1.4rem; opacity: .5; }
    .efr .ectl { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
    .efr .used { font-size: .8rem; padding: 2px 8px; border-radius: 999px; }
    .efr .used.enh { background: #16a34a22; color: #16a34a; }
    .efr .used.orig { background: #f59e0b22; color: #b45309; }
    .badge { font-size: .75rem; padding: 2px 8px; border-radius: 999px; }
    .badge.enhanced { background: #16a34a22; color: #16a34a; }
    .badge.passthrough { background: #f59e0b22; color: #b45309; }
    .badge.warn { background: #f59e0b22; color: #b45309; }
    .scenario.weak { border-left-color: #f59e0b; background: #f59e0b0d; }
    .warnnote { font-size: .8rem; color: #b45309; margin: 4px 0; }
    #steps { font-family: ui-monospace, monospace; font-size: .8rem; white-space: pre-wrap; opacity: .8; }
    small { opacity: .7; } label.tag { font-size: .8rem; opacity: .7; }
    /* !important — чтобы .hidden побеждал ID-правила с display (#lightbox/#userbox вне #app) */
    .hidden { display: none !important; }
    video.final { width: 100%; border-radius: 12px; margin-top: 8px; }
    #topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
    #userbox { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
    #who { opacity: .8; }
    #dropzone, .dropzone { border: 2px dashed #8888; border-radius: 12px; padding: 30px; text-align: center;
      cursor: pointer; background: #8881; transition: background .15s, border-color .15s; user-select: none; }
    #dropzone:hover, .dropzone:hover { background: #8882; }
    #dropzone.drag, .dropzone.drag { border-color: #3b82f6; background: #3b82f622; }
    .enh-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 10px 0;
      border: 1px solid #8884; border-radius: 10px; padding: 10px; }
    .enh-pair figure { margin: 0; }
    .enh-pair img { width: 100%; height: auto; border-radius: 6px; background: #8882; cursor: pointer; }
    .enh-pair figcaption { font-size: .8rem; opacity: .7; margin-top: 4px; }
    @media (max-width: 640px) { .enh-pair { grid-template-columns: 1fr; } }
    /* Список проектов раздела (Видео/Фото/Дизайн) — только свой тип */
    .projlist { margin: 18px 0 0; }
    .projlist h3 { font-size: 1rem; margin: 0 0 8px; }
    .projgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
    .projcard { border: 1px solid #8884; border-radius: 10px; overflow: hidden; cursor: pointer;
      background: #8881; text-align: left; padding: 0; font: inherit; color: inherit; }
    .projcard:hover { border-color: #3b82f6; }
    .projcard img { width: 100%; height: 104px; object-fit: cover; display: block; background: #8882; }
    .projcard .noimg { height: 104px; display: flex; align-items: center; justify-content: center; opacity: .35; font-size: 1.6rem; }
    .projcard .meta { padding: 7px 9px; font-size: .78rem; line-height: 1.35; }
    .projcard .meta b { font-weight: 600; }
    .projcard .st { font-size: .72rem; opacity: .7; }
    .dsn-item { margin: 10px 0 18px; }
    .dsn-prompt { margin-top: 4px; }
    .dsn-prompt summary { cursor: pointer; font-size: .78rem; opacity: .7; }
    .dsn-prompt pre { white-space: pre-wrap; font-size: .74rem; line-height: 1.5; opacity: .85;
      background: #8881; border: 1px solid #8883; border-radius: 8px; padding: 10px 12px; margin: 6px 0 0; max-height: 260px; overflow-y: auto; }
    select { font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid #8888; }
    #nav { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
    .nav-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
    #nav button.active { background: #3b82f6; color: #fff; border-color: #3b82f6; }
    #nav .nav-row.product button { font-weight: 600; }
    /* Под-вкладки внутри раздела: Генерация / Проекты / Медиатека */
    .subnav { display: flex; gap: 4px; margin: 10px 0 14px; border-bottom: 1px solid #8883; }
    .subnav button { border: none; background: none; border-radius: 0; padding: 8px 14px;
      font: inherit; color: inherit; opacity: .6; cursor: pointer; border-bottom: 2px solid transparent; }
    .subnav button:hover { opacity: .9; }
    .subnav button.active { opacity: 1; font-weight: 600; border-bottom-color: #3b82f6; }
    #stats-cards { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
    .stat { flex: 1; min-width: 130px; border: 1px solid #8884; border-radius: 12px; padding: 14px; text-align: center; }
    .stat .num { font-size: 1.9rem; font-weight: 700; }
    .stat .lbl { font-size: .8rem; opacity: .7; margin-top: 4px; }
    table.stats { width: 100%; border-collapse: collapse; }
    table.stats th, table.stats td { padding: 6px 8px; border-bottom: 1px solid #8883; font-size: .9rem; }
    table.stats th { text-align: left; opacity: .7; font-weight: 600; }
    table.stats td.num, table.stats th.num { text-align: right; font-variant-numeric: tabular-nums; }
    table.stats tr.clickable { cursor: pointer; }
    table.stats tr.clickable:hover td { background: #3b82f611; }
    .muted { opacity: .7; font-size: .85rem; }
    .chip { display: inline-block; padding: 2px 8px; margin: 2px 0; border-radius: 999px;
            background: #3b82f622; font-size: .8rem; }
    .fullprompt { margin-top: .4em; }
    .fullprompt > summary { cursor: pointer; font-size: .8rem; opacity: .7; }
    #detail-meta { display: flex; gap: 16px; flex-wrap: wrap; font-size: .9rem; margin: 6px 0 14px; }
    #detail-meta b { font-variant-numeric: tabular-nums; }
    /* Детали проекта: сворачиваемые разделы (фото+сценарии / части видео / итог).
       По умолчанию открыт только первый (у него атрибут open). */
    .dsection { border: 1px solid #8884; border-radius: 12px; margin: 10px 0; padding: 0 14px; }
    .dsection[open] { padding-bottom: 14px; }
    .dsection > summary { cursor: pointer; font-size: 1.05rem; font-weight: 600;
      padding: 12px 0; list-style: none; user-select: none; }
    .dsection > summary::-webkit-details-marker { display: none; }
    .dsection > summary::before { content: "▸"; display: inline-block; width: 1em;
      transition: transform .15s; }
    .dsection[open] > summary::before { transform: rotate(90deg); }
    .verpick { display: flex; gap: 16px; align-items: center; margin: 4px 0 8px; }
    .verpick label { font-size: .9rem; }
    /* В деталях фото и видео — крупно (в превью-флоу остаются компактными). */
    #detail-body .frame { flex-wrap: wrap; align-items: flex-start; }
    #detail-body .frame img { width: 480px; height: auto; max-width: 46%; object-fit: contain; }
    #detail-body .vid { flex-wrap: wrap; }
    #detail-body .vid video { width: 720px; max-width: 100%; }
    #detail-body video.final { max-width: 720px; }
    /* Клик по фото -> лайтбокс */
    #view-generate img, #view-detail img, #view-photos img, #view-rejected img { cursor: zoom-in; }
    .pgroup.rej { border-color: #dc262655; }
    .pgroup .rej-reason { color: #b91c1c; font-size: .85rem; margin: 4px 0 8px; }
    .pgrid .rejcell { position: relative; }
    .pgrid .rejcell .issue { position: absolute; left: 4px; bottom: 4px; background: #dc2626dd;
      color: #fff; font-size: .68rem; padding: 1px 6px; border-radius: 999px; }
    /* Медиатека: группа = проект (кликабельный заголовок) + сетка миниатюр */
    .pgroup { border: 1px solid #8884; border-radius: 12px; padding: 12px; margin: 12px 0; }
    .pgroup.bucket { border-style: dashed; background: #8881; }
    .pgroup-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
                   cursor: pointer; margin-bottom: 10px; }
    .pgroup-head:hover .pgroup-id { text-decoration: underline; }
    .pgroup-id { font-weight: 600; }
    .pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
    .pgrid img { width: 100%; height: 110px; object-fit: cover; border-radius: 8px; background: #8882; }
    .pcell { position: relative; }
    .pcell .goproj { position: absolute; top: 4px; right: 4px; border: none; cursor: pointer;
      background: rgba(0,0,0,.62); color: #fff; font-size: .68rem; line-height: 1;
      padding: 3px 7px; border-radius: 999px; opacity: 0; transition: opacity .12s; }
    .pcell:hover .goproj, .pcell .goproj:focus-visible { opacity: 1; }
    .pcell .goproj:hover { background: rgba(0,0,0,.82); }
    #lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex;
                align-items: center; justify-content: center; z-index: 1000; cursor: zoom-out; }
    #lightbox img { max-width: 94vw; max-height: 94vh; border-radius: 10px;
                    box-shadow: 0 10px 40px rgba(0,0,0,.5); }
    #gen-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
    #gen-current { font-size: .85rem; opacity: .7; }
    button.danger { color: #b91c1c; border-color: #dc262655; }
    button.danger:hover:not(:disabled) { background: #dc26261a; }
