:root {
  --bg: #f3f1ec;
  --surface: #fbfaf7;
  --surface-strong: #ffffff;
  --ink: #202422;
  --muted: #6f7570;
  --line: #d8d9d3;
  --line-strong: #bfc3bd;
  --accent: #176b68;
  --accent-hover: #105b58;
  --accent-soft: #dcecea;
  --danger: #a33f37;
  --viewer: #1f2424;
  --viewer-line: #343a39;
  --radius: 7px;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { height: 100vh; overflow: hidden; background: var(--bg); }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid #2b8d88;
  outline-offset: 2px;
}
button:disabled { opacity: .48; cursor: default; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-bar {
  height: 52px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 250, 247, .97);
}
.identity { min-width: 0; display: flex; align-items: baseline; gap: 9px; }
.identity strong { font-size: 15px; letter-spacing: .01em; white-space: nowrap; }
.identity span { max-width: 220px; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-control, .model-control { min-width: 0; display: flex; align-items: center; gap: 6px; }
.project-control { margin-left: 4px; }
.project-control select { width: min(210px, 22vw); }
.model-control { margin-left: auto; }
.model-control select { max-width: 230px; }
.lm-status { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.model-dot { width: 8px; height: 8px; border-radius: 50%; background: #9a9e9a; flex: 0 0 auto; }
.model-dot.online { background: #26856f; }
.model-dot.warning { background: #bd7b20; }
.model-dot.offline { background: var(--danger); }
.app-version { color: var(--muted); font-size: 11px; white-space: nowrap; }
.runtime-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-strong);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
}
.runtime-badge[data-mode="cloud"] { color: var(--accent); border-color: #9fc4bf; background: var(--accent-soft); }
.account-button { max-width: 170px; padding: 4px 8px; overflow: hidden; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--surface); text-overflow: ellipsis; white-space: nowrap; font-size: 11px; cursor: pointer; }
.admin-link {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border: 1px solid #9fc4bf;
  border-radius: 999px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
}
.admin-context {
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 12px;
  border-bottom: 1px solid #9fc4bf;
  color: #164d4b;
  background: var(--accent-soft);
  font-size: 12px;
}
.admin-context .text-action { color: #164d4b; }
.admin-context[hidden] { display: none; }
body.admin-context-active .workspace { height: calc(100vh - 88px); }
body.admin-context-active .runtime-notices { top: 88px; }
.runtime-notices {
  position: fixed;
  top: 52px;
  left: 50%;
  z-index: 11;
  width: min(780px, calc(100vw - 24px));
  transform: translateX(-50%);
  padding: 8px 12px;
  border: 1px solid #d5ad68;
  border-top: 0;
  border-radius: 0 0 7px 7px;
  color: #5f421d;
  background: #fff5df;
  box-shadow: 0 5px 18px rgba(38, 31, 19, .13);
  font-size: 12px;
  line-height: 1.4;
}
.runtime-notices[hidden] { display: none; }
.runtime-notices[data-severity="critical"] { color: #73352f; border-color: #d69991; background: #fbe9e6; }

.workspace {
  height: calc(100vh - 52px);
  display: grid;
  grid-template-columns: 252px minmax(430px, 1fr) minmax(350px, 420px);
  overflow: hidden;
}
.file-pane, .editor-pane { min-width: 0; min-height: 0; background: var(--surface); }
.file-pane { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.editor-pane { border-left: 1px solid var(--line); overflow: auto; }
.viewer-pane {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  background: var(--viewer);
  overflow: hidden;
  container-type: inline-size;
}

.icon-button, .quiet-button, .primary-button, .text-action, .workflow-button, .floating-button, .floating-value, .carousel-button, .roi-reset {
  border-radius: 5px;
  cursor: pointer;
}
.icon-button {
  min-width: 32px;
  min-height: 32px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  background: transparent;
}
.icon-button svg, .workflow-button svg, .floating-button svg, .carousel-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-button:hover, .quiet-button:hover { background: #ecece7; }
.quiet-button { min-height: 32px; padding: 5px 10px; border: 1px solid var(--line-strong); background: var(--surface-strong); }
.primary-button { min-height: 34px; padding: 6px 14px; border: 1px solid var(--accent); background: var(--accent); color: white; font-weight: 600; }
.primary-button:hover { background: var(--accent-hover); }

input, textarea, select {
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface-strong);
  color: var(--ink);
  padding: 7px 8px;
}
textarea { resize: vertical; line-height: 1.45; }

.file-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}
.file-tools #fileSearch { grid-column: 1 / -1; min-width: 0; }
.file-tools #statusFilter { min-width: 0; width: 100%; font-size: 12px; }
.select-visible { display: inline-flex; align-items: center; gap: 5px; padding: 0 3px; color: var(--muted); font-size: 11px; white-space: nowrap; cursor: pointer; }
.select-visible input { margin: 0; padding: 0; }
.selection-bar {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 9px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  flex-wrap: wrap;
}
.selection-bar > span { min-width: 0; margin-right: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-action { min-height: 25px; padding: 2px 5px; border: 0; background: transparent; color: var(--accent); font-size: 11px; white-space: nowrap; }
.text-action:hover { background: var(--accent-soft); }
.selection-bar .text-action:disabled { display: none; }
.file-count { padding: 6px 12px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); }
.file-list { min-height: 0; overflow: auto; padding: 4px 0 12px; }
.file-item {
  width: 100%;
  min-height: 66px;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) 10px;
  gap: 7px;
  align-items: center;
  padding: 7px 10px 7px 7px;
  border-left: 3px solid transparent;
  background: transparent;
}
.file-item:hover { background: #eeeee9; }
.file-item.active { background: var(--accent-soft); border-left-color: var(--accent); }
.file-select { margin: 0; padding: 0; justify-self: center; }
.file-open {
  min-width: 0;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.file-thumb { width: 48px; height: 48px; object-fit: cover; background: #deded8; border: 1px solid var(--line); }
.file-copy { min-width: 0; }
.file-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.file-status { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #a8aba7; }
.status-dot.ready { background: #3e8876; }
.status-dot.review, .status-dot.stale { background: #bd7b20; }
.status-dot.saved, .status-dot.reviewed { background: var(--accent); }
.status-dot.error { background: var(--danger); }

.image-stage { position: relative; min-height: 0; overflow: hidden; user-select: none; }
.image-viewport { position: absolute; inset: 0; overflow: auto; overscroll-behavior: contain; }
.image-plane { min-width: 100%; min-height: 100%; width: max-content; height: max-content; display: grid; place-items: center; padding: 18px; }
.empty-image { color: #939b99; font-size: 13px; }
.image-wrap { position: relative; line-height: 0; cursor: crosshair; touch-action: pan-x pan-y; }
.image-wrap img { display: block; width: 100%; height: 100%; max-width: none; max-height: none; object-fit: fill; }

.floating-image-controls {
  position: absolute;
  top: 10px;
  left: 50%;
  z-index: 8;
  max-width: calc(100% - 104px);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  transform: translateX(-50%);
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 7px;
  background: rgba(22, 27, 26, .84);
  color: #edf2f0;
  box-shadow: 0 5px 16px rgba(0, 0, 0, .2);
  backdrop-filter: blur(7px);
}
.floating-button, .floating-value {
  height: 30px;
  min-height: 30px;
  border: 0;
  background: transparent;
  color: inherit;
}
.floating-button { min-width: 30px; display: inline-grid; place-items: center; padding: 3px 7px; font-size: 18px; }
.floating-value { min-width: 48px; padding: 3px 6px; font-size: 11px; }
.floating-button:hover, .floating-value:hover, .floating-button[aria-pressed="true"] { background: rgba(255, 255, 255, .13); }
.floating-separator { width: 1px; height: 20px; margin: 0 2px; background: rgba(255, 255, 255, .18); }
.ai-area-toggle svg { width: 18px; height: 18px; }

.carousel-button {
  position: absolute;
  top: 50%;
  z-index: 7;
  width: 42px;
  height: 58px;
  display: grid;
  place-items: center;
  padding: 0;
  transform: translateY(-50%);
  border: 0;
  background: rgba(15, 20, 19, .28);
  color: rgba(255, 255, 255, .82);
  opacity: 0;
  pointer-events: none;
  transition: opacity .14s ease, background .14s ease;
}
.image-stage:hover .carousel-button:not(:disabled), .carousel-button:focus-visible { opacity: 1; pointer-events: auto; }
.carousel-button:disabled { display: none; }
.carousel-button:hover, .carousel-button:focus-visible { background: rgba(15, 20, 19, .72); color: white; }
.carousel-button.previous { left: 8px; }
.carousel-button.next { right: 8px; }
.carousel-button svg { width: 26px; height: 26px; }

.roi {
  position: absolute;
  border: 2px solid #72d0c6;
  box-shadow: 0 0 0 9999px rgba(8, 12, 12, .58);
  cursor: move;
  touch-action: pan-x pan-y;
}
.roi::after { content: "Область ИИ"; position: absolute; top: 5px; left: 7px; color: white; background: rgba(13, 88, 84, .82); padding: 3px 5px; border-radius: 3px; font: 11px/1.2 "Segoe UI", sans-serif; }
.roi-reset {
  position: absolute;
  top: 5px;
  right: 5px;
  z-index: 3;
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  padding: 0 0 2px;
  border: 1px solid rgba(255, 255, 255, .55);
  background: rgba(18, 31, 30, .82);
  color: white;
  font-size: 18px;
  line-height: 1;
}
.roi-reset:hover { background: rgba(163, 63, 55, .92); }
.roi-handle { position: absolute; width: 14px; height: 14px; border: 2px solid white; border-radius: 50%; background: var(--accent); }
.roi-handle.nw { left: -8px; top: -8px; cursor: nwse-resize; }
.roi-handle.ne { right: -8px; top: -8px; cursor: nesw-resize; }
.roi-handle.sw { left: -8px; bottom: -8px; cursor: nesw-resize; }
.roi-handle.se { right: -8px; bottom: -8px; cursor: nwse-resize; }
.image-footer { min-height: 34px; display: flex; align-items: center; padding: 5px 12px; border-top: 1px solid var(--viewer-line); color: #aeb5b3; font-size: 12px; }
.image-footer span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.editor-sticky { position: sticky; top: 0; z-index: 3; background: rgba(251, 250, 247, .97); border-bottom: 1px solid var(--line); }
.editor-actions { display: flex; align-items: center; gap: 7px; padding: 9px 12px; }
.workflow-button {
  position: relative;
  width: 38px;
  height: 38px;
  min-height: 38px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line-strong);
  background: var(--surface-strong);
}
.workflow-button:hover { background: #ecece7; }
.workflow-button.primary { color: white; border-color: var(--accent); background: var(--accent); }
.workflow-button.primary:hover { background: var(--accent-hover); }
.workflow-button.attention { color: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.workflow-button.dirty::after { content: ""; position: absolute; right: 4px; top: 4px; width: 7px; height: 7px; border: 1px solid white; border-radius: 50%; background: #d18424; }
.analysis-meta { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; padding: 0 12px 9px; color: var(--muted); font-size: 11px; }
.confidence { display: inline-flex; align-items: center; gap: 5px; color: var(--ink); }
.confidence strong { min-width: 30px; font-size: 12px; }
.confidence progress { width: 52px; height: 5px; accent-color: var(--accent); }
.confidence.medium progress { accent-color: #b87a24; }
.confidence.low progress { accent-color: var(--danger); }
.request-meta { color: var(--ink); }
.request-comparison { flex-basis: 100%; }
.description-state { color: #a66417; }
.reviewed-toggle { margin-left: auto; color: var(--muted); font-size: 11px; white-space: nowrap; }
.request-progress { display: flex; align-items: center; gap: 7px; min-height: 31px; padding: 6px 12px; border-top: 1px solid var(--line); color: var(--ink); font-size: 12px; }
.request-progress[hidden] { display: none; }
.request-progress time { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); }
.request-progress .cancel-job { margin-left: auto; color: var(--danger); }
.request-progress .cancel-job + time { margin-left: 0; }
.progress-spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.request-options { margin: 0 12px; padding: 9px 0 0; border-bottom: 1px solid var(--line); }
.request-options summary { width: fit-content; color: var(--muted); font-size: 11px; cursor: pointer; }
.instruction-row { display: flex; gap: 6px; padding: 8px 0 10px; }
.instruction-row input { min-width: 0; flex: 1; }
.inline-message { margin: 9px 12px 0; padding: 8px 10px; color: #73352f; background: #f7e7e4; border-left: 3px solid var(--danger); font-size: 12px; line-height: 1.4; }
.result-form { display: flex; flex-direction: column; gap: 13px; padding: 12px 12px 32px; }
.result-form > label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 12px; }
.result-form input, .result-form textarea, .result-form select { color: var(--ink); font-size: 13px; }

dialog { width: min(480px, calc(100vw - 24px)); max-height: calc(100svh - 24px); padding: 0; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--surface); overflow: auto; }
dialog::backdrop { background: rgba(20, 24, 23, .42); }
.project-dialog { width: min(600px, calc(100vw - 24px)); }
.dialog-shell { position: relative; margin: 0; padding: 22px; }
.dialog-shell h2 { margin: 0 38px 18px 0; font-size: 17px; }
.dialog-shell h3 { margin: 19px 0 7px; font-size: 13px; }
.dialog-close { position: absolute; top: 10px; right: 10px; }
.dialog-field { display: flex; flex-direction: column; gap: 6px; margin-top: 13px; color: var(--muted); font-size: 12px; }
.dialog-field input, .dialog-field textarea, .dialog-field select { color: var(--ink); }
.field-note { margin: 6px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.dialog-actions { display: flex; justify-content: flex-end; margin: 20px 0 0; padding: 14px 0 0; border-top: 1px solid var(--line); }
.wide-action { width: 100%; margin-top: 17px; }
.project-transfer { display: flex; gap: 7px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.project-transfer > button { flex: 1; }
.cloud-upload { margin-top: 18px; padding-top: 3px; border-top: 1px solid var(--line); }
.auth-dialog { width: min(430px, calc(100vw - 24px)); }
.invitation-form { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.invitation-form summary { color: var(--muted); cursor: pointer; }
.help-dialog { font-size: 13px; line-height: 1.5; }
.help-dialog p { margin: 10px 0; color: #454b47; }
.help-dialog ul, .help-steps { margin: 7px 0 0; padding-left: 22px; }
.help-dialog li { margin: 7px 0; }
.help-steps li::marker { color: var(--accent); font-weight: 700; }
.shortcut-list { margin: 6px 0 14px; }
.shortcut-list > div { display: grid; grid-template-columns: 118px 1fr; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.shortcut-list dt, .shortcut-list dd { margin: 0; }
.shortcut-list dd { color: var(--muted); }
.muted { color: var(--muted) !important; }
kbd { padding: 1px 5px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; background: white; }
.toast { position: fixed; left: 50%; bottom: 20px; z-index: 20; transform: translate(-50%, 16px); opacity: 0; pointer-events: none; padding: 9px 13px; border-radius: 6px; color: white; background: #2c3532; font-size: 13px; transition: .16s ease; }
.toast.visible { transform: translate(-50%, 0); opacity: 1; }
.scrim { display: none; }
.mobile-only { display: none; }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 220px minmax(390px, 1fr) minmax(320px, 370px); }
  .identity span { max-width: 140px; }
  .project-control select { width: 160px; }
  .model-control select { max-width: 180px; }
  .selection-bar { flex-wrap: wrap; }
  .selection-bar > span { flex-basis: 100%; }
}

@media (max-width: 900px) {
  body { height: auto; min-height: 100vh; overflow: auto; }
  .app-bar { position: sticky; top: 0; z-index: 12; }
  .mobile-only { display: inline-grid; place-items: center; }
  .identity span { display: none; }
  .project-control { margin-left: 0; }
  .project-control select { width: 140px; }
  .model-control select { max-width: 145px; }
  .lm-status span:last-child { display: none; }
  .workspace { height: auto; display: block; overflow: visible; }
  .file-pane { position: fixed; inset: 52px auto 0 0; z-index: 15; width: min(310px, 86vw); transform: translateX(-102%); transition: transform .18s ease; box-shadow: 12px 0 30px rgba(0, 0, 0, .16); }
  body.files-open .file-pane { transform: translateX(0); }
  .scrim { position: fixed; inset: 52px 0 0; z-index: 14; background: rgba(20, 24, 23, .35); }
  body.files-open .scrim { display: block; }
  .viewer-pane { height: 62svh; min-height: 470px; }
  .editor-pane { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .editor-sticky { top: 52px; }
}

@media (max-width: 680px) {
  .app-bar { padding: 0 8px; gap: 6px; }
  .identity { display: none; }
  .project-control { min-width: 0; flex: 1; }
  .project-control select { width: 100%; min-width: 92px; }
  .model-control { margin-left: 0; }
  .model-control select { width: 112px; padding-left: 5px; padding-right: 5px; font-size: 11px; }
  .app-version { display: none; }
  .floating-image-controls { top: 8px; max-width: calc(100% - 84px); overflow-x: auto; scrollbar-width: none; }
  .floating-image-controls::-webkit-scrollbar { display: none; }
  .carousel-button { width: 36px; height: 50px; }
  .carousel-button.previous { left: 4px; }
  .carousel-button.next { right: 4px; }
  .image-plane { padding: 10px; }
}

@media (max-width: 520px) {
  .project-control select { max-width: 128px; font-size: 12px; }
  .model-control select { width: 94px; }
  .lm-status { gap: 0; }
  .account-button { width: 32px; min-width: 32px; height: 32px; padding: 0; border-radius: 50%; font-size: 0; }
  .account-button::before { content: attr(data-short); font-size: 12px; font-weight: 700; }
  .viewer-pane { height: 66svh; min-height: 500px; }
  .editor-actions { gap: 5px; padding: 8px; }
  .analysis-meta { padding: 0 8px 8px; }
  .selection-bar { gap: 2px; }
  .text-action { padding-left: 4px; padding-right: 4px; }
  .dialog-shell { padding: 18px 16px; }
  .project-transfer { flex-direction: column; }
  .shortcut-list > div { grid-template-columns: 100px 1fr; }
}

@media (pointer: coarse) {
  .carousel-button:not(:disabled) { opacity: 1; pointer-events: auto; }
  .roi-handle { width: 22px; height: 22px; }
  .roi-handle.nw { left: -12px; top: -12px; }
  .roi-handle.ne { right: -12px; top: -12px; }
  .roi-handle.sw { left: -12px; bottom: -12px; }
  .roi-handle.se { right: -12px; bottom: -12px; }
  .roi-reset { width: 30px; height: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
  .progress-spinner { animation: none; }
}
