/* Общие компоненты A·ART. Приоритет задаёт слой, а не вес ID селектора.
   Геометрия макетов, карточек и навигации остаётся в aart-legacy. */
@layer aart-legacy, aart-ui;
@layer aart-ui {
  /* Действия. Кнопки-карточки, навигация и миниатюры сюда не входят. */
  :where(.button,.text-button,.icon-button,.dialog-close,.notification-bell,.notification-close,
    .notification-actions button,.invite-password-toggle,.filter-button,.mp-round-button,.object-more,.review-arrow,#review-lightbox-close,.ui-button) {
    box-sizing:border-box;
    align-items:center;
    justify-content:center;
    gap:var(--ui-space-1);
    min-width:0;
    max-width:100%;
    height:auto;
    min-height:var(--ui-current-control-height);
    max-height:none;
    padding:var(--ui-current-padding-y) var(--ui-current-button-padding-x);
    border:1px solid var(--ui-line);
    border-radius:var(--ui-control-radius);
    background:var(--ui-surface);
    color:var(--ui-text);
    font-family:var(--ui-font-family);
    font-size:var(--ui-current-button-font);
    font-weight:var(--ui-control-weight);
    line-height:var(--ui-control-line);
    letter-spacing:0;
    text-align:center;
    text-decoration:none;
    text-transform:none;
    white-space:normal;
    overflow-wrap:anywhere;
    box-shadow:none;
    transform:none;
    cursor:pointer;
  }
  :where(.text-button,.notification-actions button,.invite-password-toggle,.filter-button,.ui-button) { display:inline-flex; }
  :where(.button,.icon-button,.dialog-close,.notification-bell,.notification-close,
    .filter-button,.mp-round-button,.object-more,.review-arrow,#review-lightbox-close,.ui-button):hover:not(:disabled):not([aria-disabled=true]) {
    background:var(--ui-canvas); color:var(--ui-text); box-shadow:none; transform:none;
  }
  :where(.button-primary) { background:var(--ui-accent); border-color:transparent; color:#fff; }
  :where(.button-primary):hover:not(:disabled):not([aria-disabled=true]) {
    background:var(--ui-accent-hover); border-color:transparent; color:#fff;
  }
  :where(.button-danger) { background:var(--ui-danger); border-color:transparent; color:#fff; }
  :where(.button-danger):hover:not(:disabled):not([aria-disabled=true]) { background:var(--ui-danger-hover); color:#fff; }
  :where(.text-button,.button-quiet,.notification-actions button,.invite-password-toggle) {
    border-color:transparent; background:transparent; color:var(--ui-accent); padding-inline:var(--ui-space-1);
  }
  :where(.text-button,.notification-actions button,.invite-password-toggle):hover:not(:disabled):not([aria-disabled=true]) {
    background:var(--ui-accent-soft); color:var(--ui-accent-hover); text-decoration:none;
  }
  :where(.button-quiet) { color:var(--ui-muted); }
  :where(.button-new) { color:var(--ui-accent); }
  :where(.projects-home-button) { background:var(--ui-accent-soft); color:var(--ui-accent); }
  :where(.workspace:has(.project-view:not([hidden]),.customer-project-view:not([hidden])) .projects-home-button) {
    background:transparent; color:var(--ui-muted);
  }
  :where(.text-button.review-danger,.project-customer>.text-button,.project-invite-row>.text-button,.figma-connection-danger .text-button) { color:var(--ui-danger); }
  :where(.text-button.review-danger,.project-customer>.text-button,.project-invite-row>.text-button,.figma-connection-danger .text-button):hover:not(:disabled):not([aria-disabled=true]) {
    color:var(--ui-danger-hover); background:#fff0f3;
  }
  :where(.button[aria-pressed=true]:not(.button-primary,.button-danger),.filter-button[aria-pressed=true],.filter-button.active),
  :where(.notification-bell)[aria-expanded=true] {
    border-color:#d9c6ff; background:var(--ui-accent-soft); color:var(--ui-accent);
  }
  :where(.home-project-scopes) > .button { border-color:transparent; background:transparent; color:var(--ui-muted); }
  :where(.home-project-scopes) > .button[aria-pressed=true] {
    border-color:transparent; background:var(--ui-surface); color:var(--ui-text);
  }
  :where(.button,.text-button,.icon-button,.dialog-close,.notification-bell,.notification-close,
    .notification-actions button,.invite-password-toggle,.filter-button,.mp-round-button,.object-more,.review-arrow,#review-lightbox-close,.ui-button):is(:disabled,[aria-disabled=true]) {
    opacity:.5; cursor:not-allowed; transform:none; box-shadow:none;
  }
  :where(.icon-button,.dialog-close,.notification-bell,.notification-close,.mp-round-button,.object-more,.review-arrow) {
    flex:0 0 var(--ui-current-control-height);
    width:var(--ui-current-control-height);
    min-width:var(--ui-current-control-height);
    height:var(--ui-current-control-height);
    padding:var(--ui-space-1);
  }
  :where(.button,.text-button,.icon-button,.dialog-close,.notification-bell,.notification-close,
    .notification-actions button,.filter-button,.mp-round-button,.object-more,.review-arrow,#review-lightbox-close,.ui-button) > .icon {
    flex:0 0 18px; width:18px; height:18px;
  }
  :where(.object-more) { border-color:transparent; background:transparent; color:var(--ui-muted); font-size:20px; line-height:20px; }
  :where(.object-more):hover:not(:disabled):not([aria-disabled=true]) { border-color:transparent; background:var(--ui-accent-soft); color:var(--ui-accent); }
  :where(.sidebar-nav-action) { justify-content:flex-start; text-align:left; gap:12px; padding-inline:12px; }
  :where(.notification-close) { font-size:20px; }
  :where(.review-arrow) { font-size:22px; font-weight:400; }
  :where(.review-lightbox) :where(.review-arrow,#review-lightbox-close) {
    border-color:#ffffff40; background:#ffffff0d; color:#fff;
  }
  :where(.review-lightbox) :where(.review-arrow,#review-lightbox-close):hover:not(:disabled) {
    background:#ffffff1a; color:#fff;
  }

  /* Крупное действие на промостранице — явный вариант общей кнопки. */
  :where(.landing-actions) {
    --ui-current-control-height:52px; --ui-current-padding-y:14px;
    --ui-current-button-padding-x:20px;
  }

  /* Одна строка в поле. Нативные специальные контролы не изменяются. */
  :where(input:not([type=checkbox],[type=radio],[type=range],[type=file],[type=hidden],[type=color]),select,textarea) {
    box-sizing:border-box;
    width:100%;
    min-width:0;
    max-width:100%;
    height:var(--ui-current-control-height);
    min-height:var(--ui-current-control-height);
    padding:var(--ui-current-padding-y) var(--ui-field-padding-end,var(--ui-field-padding-x))
      var(--ui-current-padding-y) var(--ui-field-padding-start,var(--ui-field-padding-x));
    border:1px solid var(--ui-line);
    border-radius:var(--ui-control-radius);
    background:var(--ui-surface);
    color:var(--ui-text);
    font-family:var(--ui-font-family);
    font-size:var(--ui-current-field-font);
    font-weight:400;
    line-height:var(--ui-control-line);
    letter-spacing:0;
    box-shadow:none;
  }
  :where(input[type=checkbox],input[type=radio]) {
    box-sizing:border-box; flex:none; width:18px; min-width:18px; max-width:18px;
    height:18px; min-height:18px; max-height:18px; margin:0; padding:0;
    accent-color:var(--ui-accent); vertical-align:middle;
  }
  :where(textarea) { height:auto; min-height:100px; line-height:var(--ui-control-line); resize:vertical; }
  :where(input,textarea)::placeholder { color:var(--ui-muted); opacity:1; }
  :where(input:not([type=checkbox],[type=radio],[type=range],[type=file],[type=hidden],[type=color]),select,textarea):disabled {
    background:var(--ui-canvas); color:var(--ui-muted); opacity:1; cursor:not-allowed;
  }
  :where(label) {
    font-family:var(--ui-font-family);
    font-size:var(--ui-label-font);
    font-weight:var(--ui-label-weight);
    line-height:var(--ui-label-line);
  }
  :where(.button,.text-button,.icon-button,.dialog-close,.notification-bell,.notification-close,
    .notification-actions button,.invite-password-toggle,.filter-button,.mp-round-button,.object-more,.review-arrow,#review-lightbox-close,
    .ui-button,input,select,textarea):focus-visible {
    outline:2px solid var(--ui-focus); outline-offset:2px; box-shadow:none;
  }
  :where(input:not([type=checkbox],[type=radio],[type=range],[type=file],[type=hidden],[type=color]),select,textarea):focus {
    border-color:var(--ui-accent); box-shadow:none;
  }

  /* Поиск резервирует пространство под встроенные значки. */
  :where(.home-search) { --ui-field-padding-start:38px; --ui-field-padding-end:50px; }
  :where(.home-search-icon) { top:50%; transform:translateY(-50%); }

  /* Составное поле пароля: общая внешняя высота без двойной границы. */
  :where(.invite-password-row) { border:0; border-radius:var(--ui-control-radius); }
  :where(.invite-password-row) > input {
    flex:1; width:0; border:1px solid var(--ui-line); border-right:0;
    border-radius:var(--ui-control-radius) 0 0 var(--ui-control-radius);
  }
  :where(.invite-password-row) > .invite-password-toggle {
    flex:none; border:1px solid var(--ui-line); border-left:0;
    border-radius:0 var(--ui-control-radius) var(--ui-control-radius) 0;
  }
  :where(.invite-password-row):focus-within { outline:2px solid var(--ui-focus); outline-offset:2px; }
  :where(.invite-password-row):focus-within > :where(input,.invite-password-toggle) { border-color:var(--ui-accent); }
  :where(.invite-password-row) > input:focus-visible { outline:none; }

  /* Палитра действий сохраняет свою ширину и адаптивное расположение. */
  :where(.workspace-action-trigger) {
    box-sizing:border-box; height:auto; min-height:var(--ui-control-height);
    padding:10px 12px; border-radius:var(--ui-control-radius);
    font-family:var(--ui-font-family); font-size:var(--ui-control-font);
    font-weight:var(--ui-control-weight); line-height:var(--ui-control-line);
  }
  :where(.workspace-action-trigger) > kbd { line-height:14px; }
  /* Подписи шапки не распадаются на буквы при нехватке места. */
  :where(.topbar-actions) > .button { flex-shrink:0; white-space:nowrap; overflow-wrap:normal; }

  /* Только явно обозначенные плотные таблицы; панели и шапка остаются 44px. */
  :where(.ui-compact,[data-ui-density=compact],.production-data-table,.production-product-grid) {
    --ui-current-control-height:var(--ui-compact-height);
    --ui-current-button-font:var(--ui-compact-font);
    --ui-current-field-font:var(--ui-compact-font);
    --ui-current-padding-y:6px;
    --ui-current-button-padding-x:10px;
  }
  :where(.ui-compact,[data-ui-density=compact],.production-data-table,.production-product-grid) textarea { min-height:72px; }

  /* Окна действий. Полноэкранный просмотр слайдов сохраняет свою геометрию. */
  :where(.settings-dialog,.first-plugin-dialog,.object-name-dialog,.figma-connection-dialog) {
    box-sizing:border-box;
    padding:var(--ui-dialog-padding);
    border:1px solid var(--ui-line);
    border-radius:var(--ui-dialog-radius);
    background:var(--ui-surface);
    color:var(--ui-text);
    font-family:var(--ui-font-family);
    font-size:14px;
    line-height:1.5;
    scrollbar-gutter:stable;
    overscroll-behavior:contain;
  }
  :where(.dialog-heading) { gap:16px; margin-bottom:24px; align-items:flex-start; }
  :where(.dialog-heading,.new-project-dialog-heading,.figma-connection-heading) h2 {
    margin:0; font-family:var(--ui-font-family); font-size:22px; font-weight:700; line-height:1.3; letter-spacing:-.025em;
  }
  :where(.settings-dialog,.first-plugin-dialog,.object-name-dialog,.figma-connection-dialog) h3 {
    font-size:16px; font-weight:650; line-height:1.4; letter-spacing:-.015em;
  }
  :where(.dialog-heading) > .dialog-close { margin:0; }
  :where(.project-customers-dialog,.figma-connection-dialog) { padding:0; }
  :where(.project-customers-heading) { margin:0; }
  :where(.settings-dialog) .button { margin-top:0; }
  :where(.notification-panel) { border-radius:var(--ui-dialog-radius); }
  :where(.notification-heading) { padding:12px 16px 8px; }
  :where(.notification-heading) h2 { font-size:18px; font-weight:650; line-height:1.4; }

  /* Общие поверхности, без вмешательства в пропорции изображений и макетов. */
  :where(.workspace .cabinet-panel,.workspace .file-imports-panel,.workspace .first-start-panel,
    .workspace .first-setup-panel,.workspace .first-result-panel,.delivery-page .cabinet-panel,.invite-card) {
    border-radius:var(--ui-panel-radius); border-color:var(--ui-line);
    background:var(--ui-surface); box-shadow:var(--shadow-soft);
  }
  :where(.invite-card) { padding:24px; }
  :where(.invite-page) { background:var(--ui-canvas); }
  :where(.invite-card,.review-collaboration) h2 { font-size:18px; font-weight:650; line-height:1.4; }

  :where(.file-import-manager-workspace) { border:0; border-radius:0; background:transparent; box-shadow:none; }

  /* Завершение прежней миграции формы: не оставляем неявную вторую колонку. */
  :where(#card-create-form) > :where(label,input,.button) { grid-area:auto; min-width:0; }

  /* Готовые PNG: одна проверка, затем единый сохранённый результат. */
  .project-context-tools { min-width:0; }
  .project-context-tools > summary,.ready-source-files > summary {
    min-height:44px; padding:12px 0; cursor:pointer; font-size:14px; line-height:20px;
  }
  .project-context-tools[data-ready="false"],.ready-source-files[data-ready="false"] { display:contents; }
  .project-view .project-layout.has-ready-import:not(.figma-layout) {
    grid-template-columns:minmax(0,1fr); gap:16px; align-items:start;
  }
  .has-ready-import > .project-settings { padding:0; border:0; background:transparent; }
  .has-ready-import .project-context-tools { border-bottom:1px solid var(--ui-line); margin:0 0 12px; }
  .has-ready-import .project-context-tools[open] { padding-bottom:16px; }
  .has-ready-import .project-context-tools .panel-heading { display:none; }
  .has-ready-import .edit-project-form {
    display:grid; grid-template-columns:minmax(180px,1fr) minmax(240px,2fr) minmax(180px,1fr); gap:8px 16px;
  }
  .has-ready-import .edit-project-form label { margin:0; }
  .has-ready-import .edit-project-form :is(input,textarea) { margin:0; width:100%; min-width:0; }
  .has-ready-import .edit-project-form textarea { min-height:80px; resize:vertical; }
  .has-ready-import .edit-project-form label[for="edit-title"] { grid-column:1; grid-row:1; }
  .has-ready-import #edit-title { grid-column:1; grid-row:2; }
  .has-ready-import .edit-project-form label[for="edit-brief"] { grid-column:2; grid-row:1; }
  .has-ready-import #edit-brief { grid-column:2; grid-row:2/4; }
  .has-ready-import .edit-project-form label[for="edit-figma"] { grid-column:3; grid-row:1; }
  .has-ready-import #edit-figma { grid-column:3; grid-row:2; }
  .has-ready-import #figma-link { grid-column:3; grid-row:3; }
  .has-ready-import #save-project { grid-column:1; grid-row:3; margin:0; }
  .has-ready-import #edit-error { grid-column:1/-1; grid-row:4; }
  .has-ready-import .upload-section { margin:0; padding:16px; border:1px solid var(--ui-line); border-radius:var(--ui-panel-radius); background:var(--ui-surface); }
  .has-ready-import .upload-section > :is(.panel-heading,.workspace-asset-hint) { display:none; }
  .has-ready-import .drop-zone { margin:0; min-height:144px; padding:16px; display:flex; flex-direction:column; justify-content:center; gap:5px; }
  .has-ready-import .drop-zone .upload-symbol { width:32px; height:32px; margin:0 0 3px; }
  .has-ready-import .drop-zone strong { font-size:14px; line-height:20px; }
  .has-ready-import .drop-zone > :is(span,small) { margin:0; font-size:12px; line-height:18px; }
  .upload-section.is-file-drag { outline:2px solid var(--ui-primary,var(--primary)); outline-offset:3px; }
  .has-ready-import .workspace-assets-heading { margin:0 0 12px; }
  .has-ready-import .workspace-assets-heading h2 { margin:0 0 4px; font-size:18px; line-height:24px; }
  .has-ready-import .workspace-assets-heading p { font-size:13px; line-height:20px; }
  .has-ready-import .file-import-history-tools { margin-bottom:8px; }
  .has-ready-import .ready-source-files { margin-top:16px; border-top:1px solid var(--ui-line); }
  .has-ready-import .ready-source-files > summary { color:var(--muted); }
  .has-ready-import .ready-source-files[open] > summary { margin-bottom:12px; }

  .cards-panel .card-titlebar { align-items:center; gap:16px; margin:0 0 12px; padding:0 0 12px; }
  .cards-panel .card-title-copy { display:flex; flex-wrap:wrap; align-items:baseline; gap:4px 10px; }
  .cards-panel .card-title-copy h3 { margin:0; font-size:22px; line-height:28px; }
  .cards-panel .card-title-copy p { margin:0; flex-basis:100%; font-size:12px; line-height:18px; }
  .cards-panel .card-heading-actions { display:flex; align-items:center; gap:8px; }
  .cards-panel .card-result-toolbar { margin:0 0 16px; padding:12px; gap:12px; }
  .cards-panel .card-result-toolbar p { margin:3px 0 0; font-size:12px; line-height:18px; }
  .cards-panel .card-result-toolbar > div:last-child { display:flex; flex-wrap:wrap; align-items:center; justify-content:flex-end; gap:10px; }
  .cards-panel .card-slides-heading { margin:0 0 12px; }
  .cards-panel .card-slides { grid-template-columns:repeat(auto-fill,minmax(150px,180px)); gap:14px; align-items:start; }
  .cards-panel .card-slide { background:var(--ui-surface); border-color:var(--ui-line); border-radius:12px; }
  .cards-panel .card-slide-info { padding:10px 10px 0; }
  .cards-panel .card-slide-info > strong { overflow:hidden; white-space:nowrap; text-overflow:ellipsis; font-size:13px; line-height:20px; }
  .cards-panel .card-slide-info > small { font-size:11px; line-height:18px; margin:2px 0 4px; }
  .cards-panel .card-slide-tools { border-top:1px solid var(--ui-line); margin:4px -10px 0; padding:0 10px; }
  .cards-panel .card-slide-tools > summary { min-height:44px; display:list-item; padding:12px 0; font-size:12px; line-height:20px; color:var(--muted); cursor:pointer; }
  .cards-panel .card-slide-tools > div { display:grid; gap:4px; padding-bottom:8px; }
  .cards-panel .card-slide-tools :is(.text-button,.card-slide-download) { justify-content:flex-start; text-align:left; width:100%; }
  .cards-panel .card-revisions { margin:0 -10px; padding:0 10px 10px; font-size:12px; }
  .cards-panel .card-revisions > summary { min-height:44px; padding:12px 0; line-height:20px; }
  .cards-panel .card-revisions > div { margin-top:8px; font-size:11px; }
  .cards-panel .card-archives { margin-top:16px; }
  .storage-summary { min-height:66px; grid-template-rows:20px 5px 20px; }
  .storage-summary-value { white-space:nowrap; }
  .storage-summary-note { min-height:20px; }

  @media(min-width:1000px) {
    .has-ready-import .upload-section { display:grid; grid-template-columns:minmax(270px,1.3fr) minmax(250px,1fr) minmax(200px,.8fr); gap:0 20px; align-items:start; }
    .has-ready-import .upload-section > .drop-zone { grid-column:1; grid-row:1/4; }
    .has-ready-import .upload-section > label[for="file-import-entry-mode"] { grid-column:2; grid-row:1; margin:0; font-size:12px; }
    .has-ready-import #file-import-entry-mode { grid-column:2; grid-row:2; width:100%; margin:4px 0 8px; }
    .has-ready-import .file-import-optimization { grid-column:2; grid-row:3; margin:0; }
    .has-ready-import .file-import-optimization p { margin:4px 0 0; font-size:11px; line-height:16px; }
    .has-ready-import #file-folder-choose { grid-column:3; grid-row:2; margin:4px 0 8px; }
    .has-ready-import #file-import-limits { grid-column:3; grid-row:3; margin:0; font-size:11px; line-height:16px; }
    .has-ready-import #upload-error { grid-column:1/-1; margin-bottom:0; }
  }

  @media(max-width:760px) {
    :where(.topbar-actions) > :where(.account-button,.telegram-button) {
      flex:0 0 44px; width:44px; min-width:44px; height:44px; padding:8px;
    }
    :where(.workspace-action-trigger) { flex:0 0 44px; width:44px; min-width:44px; height:44px; }
  }
  @media(max-width:480px) {
    :where(.workspace .topbar) { margin-inline:8px; padding-inline:4px; gap:4px; }
    :where(.workspace .topbar) > .brand,
    :where(.topbar-actions) > .telegram-button { display:none; }
    :where(.workspace .topbar-actions) { gap:4px; }
    :where(.topbar-actions) > .figma-connection-trigger {
      position:relative; flex:0 0 44px; width:44px; min-width:44px; height:44px; padding:8px;
    }
    :where(.topbar-actions .figma-connection-trigger) > span { display:none; }
    :where(.topbar-actions .figma-connection-trigger)::after { content:"F"; font-weight:700; font-size:16px; }
    :where(.topbar-actions .figma-connection-trigger) > .figma-connection-dot {
      position:absolute; display:block; top:7px; right:7px; width:5px; height:5px;
    }
  }
  @media(max-width:600px) {
    :root { --ui-current-field-font:16px; --ui-dialog-padding:20px; }
    :where(.landing-actions) {
      --ui-current-control-height:48px; --ui-current-padding-y:12px;
      --ui-current-button-padding-x:16px;
    }
    :where(.ui-compact,[data-ui-density=compact],.production-data-table,.production-product-grid) {
      --ui-current-control-height:var(--ui-control-height);
      --ui-current-button-font:var(--ui-control-font);
      --ui-current-field-font:16px;
      --ui-current-padding-y:var(--ui-control-padding-y);
      --ui-current-button-padding-x:var(--ui-control-padding-x);
    }
    :where(.dialog-heading,.new-project-dialog-heading,.figma-connection-heading) h2 { font-size:20px; }
  }
}
