*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-bg:           var(--pr-bg);
  --color-bg-secondary: var(--pr-bg-secondary);
  --color-border:       var(--pr-border);
  --color-border-light: var(--pr-border-light);
  --color-text:         var(--pr-text);
  --color-text-muted:   var(--pr-text-muted);
  --color-text-sub:     var(--pr-text-sub);

  --font-sans: var(--pr-font-sans);
  --font-size-base: var(--pr-font-size-base);

  /* Keep legacy var names but map them to the blue theme */
  --color-green:        var(--pr-primary);
  --color-green-dark:   var(--pr-primary-hover);
  --color-green-light:  var(--pr-primary-weak);
  --color-green-border: var(--pr-primary-border);
  --color-blue:         var(--pr-primary);
  --color-blue-light:   var(--pr-primary-weak);
  --radius-sm: var(--pr-radius-sm);
  --radius-md: var(--pr-radius-md);
  --radius-lg: var(--pr-radius-lg);

  --color-surface: var(--color-bg);
  --color-on-accent: #ffffff;

  --color-danger: #b4233a;
  --color-danger-bg: #fff1f2;
  --color-danger-border: #f8b4bf;
  --color-danger-border-strong: #ef8ea0;
  --color-danger-hover-bg: #ffe4e8;
  --color-danger-weak-bg: #fee2e2;
  --color-danger-strong: #dc2626;

  --color-file-xlsx-bg: #EAF3DE;
  --color-file-xlsx-text: #3B6D11;
  --color-file-xlsx-border: #C3E09A;

  --color-file-xls-bg: #F1EFE8;
  --color-file-xls-text: #5F5E5A;
  --color-file-xls-border: #D6D3C9;

  --color-file-xml-border: #A8C8F0;

  --font-mono: var(--pr-font-mono);
}

body {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  line-height: var(--pr-line-height-body);
  color: var(--color-text);
  background: var(--color-bg-secondary);
  min-height: 100vh;
}

/* ── Кнопки: модалки, таблица заказов, легаси-карточки (единый прод-стиль) ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--pr-btn-gap);
  min-height: var(--pr-btn-min-height);
  padding: var(--pr-btn-padding-y) var(--pr-btn-padding-x);
  border: 1px solid var(--color-border);
  border-radius: var(--pr-btn-radius);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: var(--pr-btn-font-size);
  font-weight: var(--pr-btn-font-weight);
  line-height: var(--pr-btn-line-height);
  letter-spacing: var(--pr-letter-spacing-ui);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease,
    filter 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: var(--color-bg-secondary);
  border-color: color-mix(in srgb, var(--color-border) 65%, var(--pr-primary));
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn:focus-visible {
  outline: var(--pr-focus-ring);
  outline-offset: var(--pr-focus-offset);
}

.btn-sm {
  min-height: var(--pr-btn-min-height-sm);
  padding: var(--pr-btn-padding-y-sm) var(--pr-btn-padding-x-sm);
  font-size: var(--pr-btn-font-size-sm);
  border-radius: var(--radius-sm);
}

.btn-primary {
  background: var(--color-green);
  color: var(--color-on-accent);
  border-color: var(--color-green);
  box-shadow: 0 2px 10px color-mix(in srgb, var(--color-green) 28%, transparent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-green-dark);
  border-color: var(--color-green-dark);
  filter: brightness(1.03);
}

.btn-secondary {
  background: var(--color-bg-secondary);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-bg-secondary) 82%, var(--color-border));
  border-color: color-mix(in srgb, var(--color-border) 75%, var(--pr-primary));
}

.btn-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger-strong);
  border-color: var(--color-danger-border);
}

.btn-danger:hover:not(:disabled) {
  background: var(--color-danger-hover-bg);
  border-color: var(--color-danger-border-strong);
}

/* .tbtn — тот же визуальный язык, другой API классов (legacy pages & modals). */
.tbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--pr-btn-gap);
  min-height: var(--pr-btn-min-height);
  padding: var(--pr-btn-padding-y) var(--pr-btn-padding-x);
  border: 1px solid var(--color-border);
  border-radius: var(--pr-btn-radius);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: var(--pr-btn-font-size);
  font-weight: var(--pr-btn-font-weight);
  line-height: var(--pr-btn-line-height);
  letter-spacing: var(--pr-letter-spacing-ui);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  transition:
    background var(--pr-motion-base) var(--pr-ease-out),
    border-color var(--pr-motion-base) var(--pr-ease-out),
    box-shadow var(--pr-motion-base) var(--pr-ease-out),
    color var(--pr-motion-base) var(--pr-ease-out),
    filter var(--pr-motion-base) var(--pr-ease-out),
    transform var(--pr-motion-fast) var(--pr-ease-out);
}

.tbtn:hover:not(:disabled) {
  background: var(--color-bg-secondary);
  border-color: color-mix(in srgb, var(--color-border) 65%, var(--pr-primary));
}

.tbtn:active:not(:disabled) {
  transform: translateY(1px);
}

.tbtn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.tbtn:focus-visible {
  outline: var(--pr-focus-ring);
  outline-offset: var(--pr-focus-offset);
}

.tbtn.primary {
  background: var(--color-green);
  color: var(--color-on-accent);
  border-color: var(--color-green);
  box-shadow: 0 2px 10px color-mix(in srgb, var(--color-green) 28%, transparent);
}
.tbtn.primary:hover:not(:disabled) {
  background: var(--color-green-dark);
  border-color: var(--color-green-dark);
  filter: brightness(1.03);
}

.tbtn.secondary {
  background: var(--color-bg-secondary);
  color: var(--color-text);
  border-color: var(--color-border);
}
.tbtn.secondary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-bg-secondary) 82%, var(--color-border));
  border-color: color-mix(in srgb, var(--color-border) 75%, var(--pr-primary));
}

.tbtn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--color-text-muted);
}
.tbtn.ghost:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-bg-secondary) 55%, var(--color-bg));
  border-color: transparent;
  color: var(--color-text);
}

.tbtn.danger {
  background: var(--color-danger-bg);
  color: var(--color-danger-strong);
  border-color: var(--color-danger-border);
}
.tbtn.danger:hover:not(:disabled) {
  background: var(--color-danger-hover-bg);
  border-color: var(--color-danger-border-strong);
}

/* ── Error screens ─────────────────────────────────────────────── */
.app-error {
  max-width: 640px;
  margin: 26px auto;
  padding: 18px 18px 16px;
  background: var(--color-bg);
  border: 1px solid var(--color-border-light);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
}

.app-error__title {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
}

.app-error__text {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--color-text-muted);
}

.app-error__actions {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ── Dropdown (unified) ─────────────────────────────────────────── */
.dd {
  position: relative;
  width: 100%;
}

.dd__btn {
  width: 100%;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition:
    border-color var(--pr-motion-fast) var(--pr-ease-out),
    background var(--pr-motion-fast) var(--pr-ease-out),
    box-shadow var(--pr-motion-fast) var(--pr-ease-out),
    transform var(--pr-motion-fast) var(--pr-ease-out);
}
.dd__btn:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-bg-secondary) 45%, var(--color-bg));
  border-color: color-mix(in srgb, var(--pr-primary) 18%, var(--color-border));
}
.dd__btn:active:not(:disabled) {
  transform: translateY(1px);
}
.dd__btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.dd__btn:focus-visible {
  outline: var(--pr-focus-ring);
  outline-offset: var(--pr-focus-offset);
  border-color: var(--pr-primary);
}

.dd__text {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dd__chev {
  font-size: 12px;
  color: var(--color-text-muted);
  transition: transform var(--pr-motion-fast) var(--pr-ease-out);
}
.dd.is-open .dd__chev {
  transform: rotate(180deg);
}

.dd__menu {
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-surface);
  box-shadow: 0 10px 28px rgba(15, 27, 51, 0.12);
  padding: 4px;
  z-index: 60;
  overflow: auto;
}

.dd__item {
  padding: 8px 10px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
  user-select: none;
}
.dd__item:hover {
  background: color-mix(in srgb, var(--color-bg-secondary) 55%, var(--color-bg));
}
.dd__item.is-selected {
  background: color-mix(in srgb, var(--color-blue-light) 55%, var(--color-bg));
  color: var(--color-blue);
  font-weight: 650;
}
.dd__item.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── AI chat (ported from ftl_per) ─────────────────────────────── */
:root {
  --chat-panel-border: var(--color-border);
  --chat-panel-shadow: none;
  --chat-border: var(--color-border-light);
  --chat-header-bg: color-mix(in srgb, var(--color-bg-secondary) 55%, var(--color-bg));
  --chat-chip-bg: var(--color-bg);
  --chat-chip-text: var(--color-text);
  --control-bg: var(--color-bg);
  --control-bg-hover: var(--color-bg-secondary);
  --control-bg-active: color-mix(in srgb, var(--color-bg-secondary) 70%, var(--color-bg));
  --control-bg-disabled: color-mix(in srgb, var(--color-border-light) 55%, var(--color-bg));
  --control-border: var(--color-border);
  --control-border-hover: color-mix(in srgb, var(--color-border) 75%, var(--pr-primary));
  --control-border-focus: var(--pr-primary);
  --control-text: var(--color-text);
  --control-text-disabled: var(--color-text-sub);
  --control-focus-ring: 0 0 0 3px color-mix(in srgb, var(--pr-primary) 18%, transparent);

  /* single source of truth for chat sizing */
  --chat-top-offset: 72px; /* header height + small gap */
  --chat-bottom-offset: 16px;
  /* Wider desktop chat so messages/actions fit comfortably */
  --chat-side-panel-width: clamp(380px, 34vw, 560px);
  /* Height is bounded by viewport; target uses a sensible clamp to avoid huge emptiness */
  --chat-panel-max-h: calc(100vh - var(--chat-top-offset) - var(--chat-bottom-offset));
  /* Desktop: fill all available vertical space */
  --chat-panel-h: var(--chat-panel-max-h);
}

/* Aside / AI panel (desktop parity with ftl_per) */
.aside,
.files-ai-panel {
  width: var(--chat-side-panel-width);
  flex-shrink: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--color-bg);
  border: 1px solid var(--chat-panel-border);
  border-radius: 0;
  box-shadow: var(--chat-panel-shadow);
}
.chat-panel {
  position: relative;
  align-self: stretch;
  height: auto;
  width: var(--chat-side-panel-width);
  min-width: 0;
  margin-left: 0;
  border-radius: 0;
  z-index: 3;
  transform-origin: right center;
  opacity: 1;
  transform: translateX(0);
  box-shadow: none;
  transition: width .26s var(--pr-ease-out), margin-left .26s var(--pr-ease-out), opacity .2s ease, transform .26s var(--pr-ease-out);
}
.chat-panel.chat-panel-closed {
  pointer-events: none;
  width: 0;
  margin-left: 0;
  opacity: 0;
  transform: translateX(18px);
  border-color: transparent;
  box-shadow: none;
}
.chat-panel.chat-panel-open {
  pointer-events: auto;
}

/* Smoother panel entrance */
@media (prefers-reduced-motion: no-preference) {
  .chat-panel.chat-panel-open {
    animation: chat-panel-in 240ms var(--pr-ease-out) both;
  }
}

@keyframes chat-panel-in {
  from { opacity: 0; transform: translateX(14px); }
  to { opacity: 1; transform: translateX(0); }
}

.chat-fab {
  display: none;
  width: 56px;
  height: 56px;
  min-height: 56px;
  border: 1px solid #bcd0ee;
  border-radius: 999px;
  background: #fdfefe;
  color: #1b4a9f;
  padding: 0;
  align-items: center;
  justify-content: center;
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 36;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(18, 52, 120, .14);
  transform: translateY(12px) scale(.96);
  opacity: 0;
  transition: opacity .22s ease, transform .24s cubic-bezier(.2, .8, .2, 1), box-shadow .2s ease, border-color .2s ease, background-color .2s ease;
}
.chat-fab.visible {
  display: inline-flex;
  transform: translateY(0) scale(1);
  opacity: 1;
}
.chat-fab:hover {
  background: var(--control-bg-hover);
  border-color: var(--control-border-hover);
  box-shadow: 0 10px 24px rgba(18, 52, 120, .18);
  transform: translateY(0) scale(1);
}
.chat-fab:focus-visible {
  outline: none;
  border-color: var(--control-border-focus);
  box-shadow: var(--control-focus-ring), 0 10px 24px rgba(18, 52, 120, .16);
}
.chat-fab:active {
  background: var(--control-bg-active);
  border-color: var(--control-border-focus);
  box-shadow: 0 6px 14px rgba(18, 52, 120, .16);
  transform: translateY(1px) scale(.98);
}
.chat-fab.visible.has-unread {
  animation: chat-fab-attention 4.8s ease-in-out 1.2s infinite;
}
.chat-collapsed-icon {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid #c5d7f6;
  background: #f2f7ff;
  color: #184493;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.chat-fab-icon {
  width: 16px;
  height: 16px;
  display: block;
}
.chat-collapsed-badge {
  margin-left: auto;
  min-width: 20px;
  min-height: 20px;
  border-radius: 999px;
  padding: 0 5px;
  border: 1px solid #c7dafd;
  background: #ffffff;
  color: #16396f;
  font-size: 10px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(21, 58, 122, .14);
}
.chat-fab .chat-collapsed-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  margin-left: 0;
  min-width: 20px;
  min-height: 20px;
}

.ai-dot {
  animation: pulse 2s infinite;
}

@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1) } 50% { opacity: .4; transform: scale(.85) } }

@keyframes chat-fab-attention {
  0%, 74%, 100% { transform: translateY(0) scale(1); }
  79% { transform: translateY(-1px) scale(1.03); }
  84% { transform: translateY(0) scale(1); }
  89% { transform: translateY(-1px) scale(1.03); }
  94% { transform: translateY(0) scale(1); }
}

.chat-mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 27, 51, 0.35);
  border: 0;
  z-index: 35;
}

@media (max-width: 640px) {
  .app-content { flex-direction: column; }
  .app-content-aside { width: 100%; }
  .chat-panel {
    position: fixed;
    right: 12px;
    left: 12px;
    bottom: 12px;
    width: auto;
    height: min(520px, 72vh);
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(18, 52, 122, .18);
    z-index: 40;
  }
  .chat-panel.chat-panel-closed {
    transform: translateY(18px);
    width: auto;
  }
  .chat-mobile-overlay { display: block; }
}

.aside-header.chat-panel-header {
  padding: 8px 10px;
  min-height: 50px;
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  border-bottom: 1px solid var(--chat-border);
  background: var(--chat-header-bg);
}

.aside-header.chat-panel-header {
  backdrop-filter: blur(6px);
}
.chat-panel-agent {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  align-items: center;
  column-gap: 10px;
  row-gap: 2px;
  min-width: 0;
  flex: 1 1 auto;
}
.chat-panel-agent-title {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
}
.chat-panel-agent-status {
  grid-column: 2;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #166534;
}
.ai-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-success, #16a34a);
}
.chat-panel-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.chat-panel-toggle {
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm, 9px);
  background: var(--control-bg);
  color: var(--control-text);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.chat-panel-toggle:hover:not(:disabled) {
  background: var(--control-bg-hover);
  border-color: var(--control-border-hover);
}
.chat-panel-toggle:focus-visible {
  outline: none;
  border-color: var(--control-border-focus);
  box-shadow: var(--control-focus-ring);
}

.chat-panel-body-wrap {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
.aside-body.files-ai-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    radial-gradient(1200px 680px at 10% 0%, rgba(31, 111, 235, 0.06), transparent 60%),
    radial-gradient(900px 560px at 95% 15%, rgba(31, 111, 235, 0.05), transparent 55%),
    #ffffff;
}

/* Scrollbar polish (WebKit) */
.aside-body.files-ai-body::-webkit-scrollbar { width: 10px; }
.aside-body.files-ai-body::-webkit-scrollbar-track { background: transparent; }
.aside-body.files-ai-body::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--color-border) 70%, transparent);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}
.aside-body.files-ai-body::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--color-border) 55%, var(--pr-primary));
  border: 3px solid transparent;
  background-clip: content-box;
}
.ai-msg,
.files-ai-message,
.agent-card {
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.55;
  border: 1px solid var(--pr-border, #dbe4f3);
}

/* Message entrance animation */
@media (prefers-reduced-motion: no-preference) {
  .ai-msg {
    animation: chat-msg-in 180ms ease-out both;
  }
}

@keyframes chat-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.ai-msg.system,
.ai-msg.agent,
.ai-msg.user {
  background: rgba(255, 255, 255, 0.92);
  border-color: color-mix(in srgb, var(--pr-border) 75%, transparent);
  color: var(--pr-text, #0f1b33);
}

/* Rich AI formatting (professional, readable) */
.ai-rich {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.ai-heading {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #0f1b33;
}

.ai-divider {
  height: 1px;
  background: color-mix(in srgb, var(--color-border) 70%, transparent);
  margin: 2px 0;
}

.ai-block {
  display: block;
}

.ai-block.ai-p {
  line-height: 1.55;
}

.ai-block.ai-li {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.ai-li-bullet {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-weight: 900;
  background: color-mix(in srgb, var(--pr-primary) 7%, transparent);
  color: color-mix(in srgb, var(--pr-primary) 55%, #0f1b33);
}

.ai-map {
  border: 1px solid color-mix(in srgb, var(--pr-border) 70%, transparent);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.84);
  overflow: hidden;
}

.ai-map-table {
  width: 100%;
  border-collapse: collapse;
}

.ai-map-row td {
  padding: 7px 10px;
  vertical-align: top;
  border-top: 1px solid color-mix(in srgb, var(--pr-border) 65%, transparent);
}

.ai-map-row:first-child td {
  border-top: 0;
}

.ai-map-status {
  width: 34px;
  text-align: center;
  font-weight: 900;
}

.ai-map-field {
  font-weight: 750;
  color: #0f1b33;
}

.ai-map-arrow {
  width: 18px;
  text-align: center;
  opacity: 0.6;
}

.ai-map-col {
  color: #173a75;
  word-break: break-word;
}

.ai-map-row-❓ .ai-map-status,
.ai-map-row-❓ .ai-map-col {
  color: #854d0e;
}

.ai-map-row-❌ .ai-map-status,
.ai-map-row-❌ .ai-map-col {
  color: #991b1b;
}
.chat-bubble {
  border-radius: 12px;
  width: fit-content;
  max-width: min(92%, 560px);
  align-self: flex-start;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  box-shadow: 0 6px 18px rgba(15, 27, 51, 0.06);
}
.ai-msg.user {
  margin-left: 28px;
  align-self: flex-end;
  background: linear-gradient(180deg, rgba(231, 240, 255, 0.95), rgba(237, 243, 255, 0.9));
  border-color: color-mix(in srgb, #c8d8f5 78%, transparent);
  color: #173a75;
}

.ai-msg.agent {
  background: rgba(255, 255, 255, 0.94);
}

.ai-msg.system {
  background: color-mix(in srgb, var(--pr-primary-weak) 42%, white);
  border-color: color-mix(in srgb, var(--pr-primary-border) 55%, var(--pr-border));
}

/* Typing indicator */
.ai-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 0 0;
}
.ai-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--pr-text) 30%, transparent);
  opacity: 0.35;
}
@media (prefers-reduced-motion: no-preference) {
  .ai-typing-dot {
    animation: ai-typing-bounce 900ms ease-in-out infinite;
  }
  .ai-typing-dot:nth-child(2) { animation-delay: 120ms; }
  .ai-typing-dot:nth-child(3) { animation-delay: 240ms; }
}

@keyframes ai-typing-bounce {
  0%, 100% { transform: translateY(0); opacity: 0.35; }
  45% { transform: translateY(-3px); opacity: 0.75; }
}

.ai-inline-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  margin: 0 3px 3px 0;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--pr-primary) 35%, var(--color-border));
  background: color-mix(in srgb, var(--pr-primary) 10%, var(--color-bg));
  color: color-mix(in srgb, var(--pr-primary) 70%, var(--pr-text));
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  vertical-align: baseline;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-inline-action:hover {
  border-color: color-mix(in srgb, var(--pr-primary) 55%, var(--color-border));
  background: color-mix(in srgb, var(--pr-primary) 14%, var(--color-bg));
}
.ai-inline-action:focus-visible {
  outline: var(--pr-focus-ring);
  outline-offset: 2px;
}

.chat-day-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2px;
}
.chat-day-separator span {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-text-sub);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  border-radius: 999px;
  padding: 2px 8px;
}
.chat-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chat-hint-chip {
  border: 1px solid var(--control-border);
  border-radius: 999px;
  background: var(--chat-chip-bg);
  color: var(--chat-chip-text);
  text-align: left;
  min-height: 30px;
  padding: 5px 10px;
  font-size: 11px;
  line-height: 1.35;
  font-weight: 600;
  cursor: pointer;
}
.chat-hint-chip:hover:not(:disabled) {
  background: var(--control-bg-hover);
  border-color: var(--control-border-hover);
}
.chat-hint-chip.is-leaving {
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px) scale(0.98);
  transition: opacity 140ms ease, transform 160ms var(--pr-ease-out);
}
.chat-hint-chip:focus-visible {
  outline: none;
  border-color: var(--control-border-focus);
  box-shadow: var(--control-focus-ring);
}

.agent-label {
  font-size: 10px;
  font-weight: 700;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: flex;
  align-items: center;
  gap: 4px;
}

.files-ai-input {
  margin-top: auto;
  padding: 10px 12px;
  border-top: 1px solid #dbe6f7;
  display: flex;
  gap: 8px;
  background: #ffffff;
  flex-shrink: 0;
}
.files-ai-input input {
  flex: 1;
  min-height: 34px;
  font-size: 12px;
  padding: 7px 10px;
  border: 1px solid var(--control-border);
  border-radius: 9px;
  background: var(--control-bg);
  color: var(--control-text);
  outline: none;
}
.files-ai-input input::placeholder { color: var(--pr-text-sub, #6f7f99); }
.files-ai-input input:hover:not(:disabled) {
  background: var(--control-bg-hover);
  border-color: var(--control-border-hover);
}
.files-ai-input input:focus-visible {
  border-color: var(--control-border-focus);
  box-shadow: var(--control-focus-ring);
}
.files-ai-input input:disabled {
  background: var(--control-bg-disabled);
  border-color: #cfdbef;
  color: var(--control-text-disabled);
}
.files-ai-input button {
  min-width: 36px;
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid var(--pr-primary);
  background: var(--pr-primary);
  color: #fff;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.files-ai-input button .ai-send-icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transform: translateY(-0.5px);
}
.files-ai-input button:disabled .ai-send-icon {
  opacity: 0.8;
}
.files-ai-input button:hover:not(:disabled) { background: var(--pr-primary-hover); border-color: var(--pr-primary-hover); }
.files-ai-input button:focus-visible { outline: none; box-shadow: var(--control-focus-ring); }
.files-ai-input button:active:not(:disabled) { background: #1645bb; border-color: #1645bb; }
.files-ai-input button:disabled { background: #9db7ef; border-color: #9db7ef; cursor: not-allowed; }
.abtn {
  font-size: 11px;
  font-weight: 600;
  padding: 6px 10px;
  border: 1px solid var(--control-border);
  border-radius: 10px;
  cursor: pointer;
  background: var(--control-bg);
  color: var(--control-text);
}
.abtn.go {
  background: var(--pr-primary);
  color: var(--color-on-accent, #fff);
  border-color: var(--pr-primary);
}
.abtn.go:hover:not(:disabled) {
  filter: brightness(0.97);
}
.chat-footer-meta {
  border-top: 1px solid var(--chat-border);
  padding: 7px 12px;
  font-size: 10px;
  color: var(--pr-text-sub, #6f7f99);
  letter-spacing: .03em;
  text-transform: uppercase;
  background: #ffffff;
}

/* Native selects are hidden via JS (inline style) after successful enhancement,
   so a failed enhancement never "removes" UI. */

/* ── App layout (full height) ─────────────────────────────────── */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-main {
  flex: 1;
  min-height: 0; /* allow nested scroll areas */
}

/* ── Header ──────────────────────────────────────────────────── */
.header {
  min-height: 56px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}

/* Двухрядная шапка (как logistics_platform_v3: бренд / пользователь + полоса вкладок) */
.header.header--cabinet {
  min-height: 0;
  flex-direction: column;
  align-items: stretch;
  padding: 0;
  gap: 0;
  border-bottom: none;
}

.header--cabinet .header__row--brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  min-height: 50px;
  flex-shrink: 0;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border-light);
}

.header--cabinet .header__brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.header--cabinet .header__product-tagline {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-muted);
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(42ch, 36vw);
}

.header--cabinet .header__row--nav {
  flex-shrink: 0;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 1px 3px color-mix(in srgb, var(--color-text) 7%, transparent);
  padding: 0 8px 0 16px;
}

.header--cabinet .header__tabs {
  margin-left: 0;
  flex: 1;
  min-width: 0;
  flex-wrap: wrap;
  gap: 2px;
  align-items: stretch;
}

.header--cabinet .header__tabs .tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 12px 14px;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  background: transparent;
}

.header--cabinet .header__tabs .tab::before,
.header--cabinet .header__tabs .tab::after {
  content: none !important;
}

.header--cabinet .header__tabs .tab:hover {
  color: var(--color-text);
  background: transparent;
}

.header--cabinet .header__tabs .tab.active {
  color: var(--color-blue);
  border-bottom-color: var(--color-blue);
  background: transparent;
}

.header--cabinet .header__tabs .tab:focus-visible {
  border-radius: var(--radius-sm, 6px);
}

.header--cabinet .header__tabs .tab .tab__label {
  line-height: 1.2;
}

.header-tab-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 100px;
  background: color-mix(in srgb, var(--pr-primary) 14%, var(--color-bg-secondary));
  color: var(--color-blue);
  line-height: 1.35;
  flex-shrink: 0;
}

.header--cabinet .header__tabs .tab.active .header-tab-badge {
  background: var(--color-blue);
  color: var(--color-on-accent);
}

@media (max-width: 720px) {
  .header--cabinet .header__product-tagline {
    display: none;
  }

  .header--cabinet .header__row--brand {
    padding: 0 14px;
    gap: 10px;
  }

  .header--cabinet .header__row--nav {
    padding: 0 6px 0 10px;
  }

  .header--cabinet .header__tabs .tab {
    padding: 10px 10px;
    font-size: 12px;
  }
}

.header--cabinet .header__user {
  flex-shrink: 0;
}

.header--cabinet #userEmail {
  max-width: min(280px, 38vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  text-decoration: none;
}

.logo-mark {
  width: 22px;
  height: 22px;
  background: var(--color-green);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-mark svg { width: 13px; height: 13px; fill: #fff; }

.header__spacer { flex: 1; }

.header__tabs {
  display: inline-flex;
  gap: 0;
  align-items: center;
  flex-wrap: nowrap;
  background: transparent;
  border: 0;
  padding: 0;
  margin-left: 6px;
}

.header__tabs .tab {
  border: 0;
  background: transparent;
  color: var(--color-text);
  font-size: 13px;
  font-weight: 400;
  padding: 0 10px 12px 10px;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  cursor: pointer;
  line-height: 1;
  position: relative;
  transition: color .15s ease;
}

.header__tabs .tab::before {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 4px;
  height: 2px;
  background: color-mix(in srgb, var(--color-text) 28%, transparent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .18s ease;
}

.header__tabs .tab::after {
  content: "|";
  position: absolute;
  right: -1px;
  top: 0;
  color: color-mix(in srgb, var(--color-text-muted) 55%, transparent);
}

.header__tabs .tab:last-child::after {
  content: "";
}

.header__tabs .tab:hover {
  color: var(--color-text);
  background: transparent;
}

.header__tabs .tab:focus-visible {
  outline: var(--pr-focus-ring);
  outline-offset: 3px;
  border-radius: var(--radius-sm, 6px);
  z-index: 1;
}

.header__tabs .tab:focus-visible::before {
  transform: scaleX(1);
  background: color-mix(in srgb, var(--pr-primary) 55%, var(--color-text) 45%);
}

.header__tabs .tab.active {
  border-bottom-color: transparent;
  background: transparent;
  color: var(--color-text);
}

.header__tabs .tab:hover::before,
.header__tabs .tab.active::before {
  transform: scaleX(1);
}

.header__user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--color-text-muted);
}

.header__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-green-light);
  color: var(--color-green-dark);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-logout {
  font-size: var(--pr-btn-font-size);
  font-weight: var(--pr-btn-font-weight);
  line-height: var(--pr-btn-line-height);
  letter-spacing: var(--pr-letter-spacing-ui);
  min-height: var(--pr-btn-min-height-sm);
  padding: var(--pr-btn-padding-y-sm) var(--pr-btn-padding-x-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text-muted);
  cursor: pointer;
}
.btn-logout:hover { background: var(--color-bg-secondary); }

.btn-logout:focus-visible {
  outline: var(--pr-focus-ring);
  outline-offset: var(--pr-focus-offset);
}

/* Узкий экран: вкладки — вторая строка с горизонтальным скроллом, без обрезания */
@media (max-width: 960px) {
  .header {
    flex-wrap: wrap;
    row-gap: 6px;
    padding-top: 10px;
    padding-bottom: 10px;
    align-items: center;
  }

  .logo {
    order: 1;
    min-width: 0;
  }

  .header__spacer {
    order: 2;
    flex: 1 1 auto;
    min-width: 12px;
  }

  .header__user {
    order: 3;
    flex: 0 0 auto;
    min-width: 0;
  }

  .header__tabs {
    order: 4;
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    margin-left: 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 2px;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }

  .header__tabs .tab {
    flex: 0 0 auto;
  }

  .logo .logo-mark {
    flex-shrink: 0;
  }
}

@media (max-width: 520px) {
  .header {
    padding-left: 12px;
    padding-right: 12px;
    gap: 10px;
  }

  .header__user #userEmail {
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* ── Page layout ─────────────────────────────────────────────── */
.page {
  width: 100%;
  margin: 0;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-height: 0;
}

.app-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
  gap: 0;
  align-items: stretch;
}

.app-content-main {
  flex: 1 1 auto;
  min-width: 0;
}

.app-content-aside {
  flex: 0 0 auto;
  min-width: 0;
  display: flex;
  align-items: stretch;
  align-self: flex-end;
  position: sticky;
  top: auto;
  bottom: var(--chat-bottom-offset);
  max-height: var(--chat-panel-max-h);
  width: 0;
  flex-basis: 0;
  overflow: hidden;
  transition: width .26s var(--pr-ease-out), flex-basis .26s var(--pr-ease-out);
}

.app-content-aside .files-ai-panel.chat-panel {
  height: var(--chat-panel-h);
  width: 100%;
}

/* ── Adaptive tuning for chat panel ───────────────────────────── */
@media (max-width: 1200px) {
  :root {
    --chat-side-panel-width: clamp(360px, 36vw, 520px);
    --chat-panel-h: var(--chat-panel-max-h);
  }
}

@media (max-width: 960px) {
  :root {
    --chat-side-panel-width: clamp(340px, 42vw, 480px);
    --chat-panel-h: var(--chat-panel-max-h);
  }
}

@media (max-height: 780px) {
  :root {
    --chat-panel-h: var(--chat-panel-max-h);
  }
}

.app-content-aside .chat-panel-body-wrap {
  flex: 1 1 auto;
  min-height: 0;
}

@media (max-width: 720px) {
  .page { padding: 16px; }
}

/* ── Tabs ────────────────────────────────────────────────────── */
.tabs {
  display: inline-flex;
  gap: 8px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 6px;
  margin-bottom: 16px;
}
.tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.tab:hover { background: var(--color-bg-secondary); color: var(--color-text); }
.tab.active {
  background: var(--color-green-light);
  color: var(--color-green-dark);
  border-color: var(--color-green-border);
}

.tab-panels { display: block; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.upload-grid {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 720px) {
  .upload-grid { grid-template-columns: 1fr; }
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--color-border-light);
}

.card-header h2 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}

.card-header p {
  font-size: 12px;
  color: var(--color-text-muted);
}

.card-body { padding: 18px; }

