:root {
  color-scheme: dark;
  --bg: #0f0f0f;
  --surface: #1f1f1f;
  --surface-2: #272727;
  --line: #3a3a3a;
  --text: #f1f1f1;
  --muted: #aaaaaa;
  --accent: #3ea6ff;
  --accent-hover: #65b8ff;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: none;
}
html[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f7f7f7;
  --surface-2: #ffffff;
  --line: #d9d9d9;
  --text: #0f0f0f;
  --muted: #606060;
  --accent: #065fd4;
  --accent-hover: #1a73e8;
}
@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #ffffff;
    --surface: #f7f7f7;
    --surface-2: #ffffff;
    --line: #d9d9d9;
    --text: #0f0f0f;
    --muted: #606060;
    --accent: #065fd4;
    --accent-hover: #1a73e8;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { min-height: 100%; }
body { margin: 0; font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background: var(--bg); color: var(--text); }
.app-shell { max-width: 1720px; margin: 0 auto; padding: 24px 20px 32px; }
.header { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 22px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 16px; min-width: 0; flex-wrap: wrap; }
/* Only ever wraps a real uploaded logo; the coloured letter badge is gone. */
.brand-logo { width: 52px; height: 52px; border-radius: 16px; overflow: hidden; flex: 0 0 auto; }
.brand-logo-img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; }
.brand h1 { margin: 0; font-size: 30px; line-height: 1.05; }
.brand p { margin: 6px 0 0; color: var(--muted); line-height: 1.35; }
.header-right { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.model-pill { text-decoration: none; padding: 10px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); font-size: 14px; max-width: 100%; overflow-wrap: anywhere; }
.icon-button { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text); cursor: pointer; font-size: 18px; flex: 0 0 auto; }
.main-content { display: flex; flex-direction: column; gap: 14px; min-width: 0; width: 100%; }
.main-grid { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(280px, 0.65fr); gap: 18px; align-items: start; }
.main-grid-single { grid-template-columns: 1fr; }
.translator, .side-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.side-card-inline { padding: 18px; }
.translator { padding: 20px; min-width: 0; width: 100%; }
.translator-stack { display: flex; flex-direction: column; gap: 0; min-width: 0; }
.translator-tabs { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.translator-tabs-header { margin: 0; flex: 0 1 auto; }
.translator-tabs-brand { margin-left: 8px; }
.translator-tabs-right { margin-right: 4px; }
.translator-tabs-header .tab-button { min-height: 40px; padding: 0 16px; }
.tab-button { min-height: 44px; padding: 0 18px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer; transition: background .15s ease, border-color .15s ease, opacity .15s ease; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.tab-button:hover { opacity: .92; }
.tab-button.active { background: var(--accent); border-color: transparent; color: #fff; font-weight: 700; }
.tab-icon { display: none; width: 20px; height: 20px; flex: 0 0 auto; }
.translator-block { display: block; }
.is-hidden { display: none; }
.translator-top { display: grid; grid-template-columns: 1fr 70px 1fr; gap: 14px; align-items: end; margin-bottom: 16px; }
.image-translator-top { margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.field label, .muted, .side-card p { color: var(--muted); }
.field label { font-size: 14px; font-weight: 600; }
/* Browser autofill paints inputs its own colour; keep the theme's instead. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--surface-2) inset;
  caret-color: var(--text);
  transition: background-color 9999s;
}
a.model-pill:hover { color: var(--text); }

/* Single source of truth for control chrome. Anything that should look like a
   form control joins these two selector lists instead of restating the values. */
select, textarea, .button, .swap-button, .select-trigger, .select-search,
input[type="text"], input[type="password"], input[type="number"], input[type="file"] {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
}
select, .button, .swap-button, .select-trigger,
input[type="text"], input[type="password"], input[type="number"] {
  min-height: 48px;
  padding: 0 14px;
}
select { width: 100%; min-width: 0; }
.native-select-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  border: 0 !important;
  white-space: nowrap !important;
}
.select-widget {
  position: relative;
  width: 100%;
}
.select-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  cursor: pointer;
}
.select-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.select-caret {
  color: var(--muted);
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
}
.select-widget.is-open .select-trigger,
.select-trigger:focus {
  outline: none;
  border-color: var(--line);
  background: color-mix(in srgb, var(--surface-2) 88%, var(--text) 12%);
}
.select-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 40;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.28);
}
.select-search {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  /* Sits flush inside the panel, so it drops the shared border and radius. */
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
}
.select-search::placeholder {
  color: var(--muted);
}
.select-search:focus {
  outline: none;
  border-bottom-color: var(--line);
}
.select-options {
  max-height: 300px;
  overflow: auto;
  padding: 6px;
}
.select-option {
  width: 100%;
  min-height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  padding: 7px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}
.lang-option-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lang-option-code {
  flex: 0 0 auto;
  color: var(--muted);
}
.select-option:hover,
.select-option.is-active {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}
.select-option.is-selected {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  font-weight: 600;
}
.select-empty {
  padding: 10px 10px 12px;
  color: var(--muted);
  font-size: 14px;
}
textarea { width: 100%; min-height: 390px; padding: 16px; resize: vertical; line-height: 1.55; }
select:focus, textarea:focus { outline: none; border-color: var(--accent); }
select:focus { border-color: var(--line); }
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.panel { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 14px; font-weight: 600; padding: 2px 2px 0; }
.image-panel-head { margin-bottom: 8px; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.button, .swap-button { cursor: pointer; transition: background .15s ease, border-color .15s ease, opacity .15s ease; }
.button:hover, .swap-button:hover, .icon-button:hover { opacity: .92; }
.button-primary { background: var(--accent); border-color: transparent; color: #fff; font-weight: 700; min-width: 180px; }
.button-primary:hover { background: var(--accent-hover); }
.button-secondary, .swap-button { background: var(--surface-2); }
.sidebar { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.side-card { padding: 18px; }
.side-card h2 { margin: 0 0 10px; font-size: 18px; }
.endpoint { display: block; margin-top: 10px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); overflow-wrap: anywhere; word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; line-height: 1.45; }
button:disabled { opacity: .65; cursor: not-allowed; }
.image-options { margin: 4px 0 14px; }
.checkbox-row { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-size: 14px; user-select: none; cursor: pointer; }
.checkbox-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.image-upload-box { position: relative; margin: 14px 0 16px; border: 1px dashed var(--line); border-radius: var(--radius-sm); background: linear-gradient(180deg, rgba(255,255,255,.02), rgba(255,255,255,.01)); min-height: 148px; display: flex; align-items: center; justify-content: center; transition: border-color .15s ease, background .15s ease, transform .15s ease, box-shadow .15s ease; overflow: hidden; }
.image-upload-box input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.image-upload-content { pointer-events: none; text-align: center; padding: 20px; max-width: 520px; }
.image-upload-icon { font-size: 30px; line-height: 1; margin-bottom: 10px; }
.image-upload-title { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.image-upload-subtitle { font-size: 14px; color: var(--muted); line-height: 1.45; }
.image-upload-hint { margin-top: 12px; font-size: 13px; color: var(--muted); padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; display: inline-block; background: var(--surface-2); max-width: 100%; overflow-wrap: anywhere; }
.image-upload-box.drag-active { border-color: var(--accent); background: rgba(62,166,255,.08); box-shadow: 0 0 0 1px rgba(62,166,255,.25) inset; }
.image-upload-box.drag-active .image-upload-title { color: var(--accent); }
@media (max-width: 1024px) {
  .main-grid { grid-template-columns: 1fr; }
  .sidebar { order: 2; }
  .main-content { order: 1; }
}
@media (max-width: 760px) {
  .app-shell { padding: 16px 12px 24px; }
  .header { align-items: flex-start; margin-bottom: 16px; }
  .brand { gap: 12px; width: 100%; }
  .brand-logo { width: 44px; height: 44px; font-size: 18px; border-radius: 14px; }
  .brand h1 { font-size: 22px; }
  .brand p { font-size: 14px; }
  .header-right { width: 100%; justify-content: space-between; }
  .model-pill { font-size: 13px; padding: 9px 12px; }
  .translator, .side-card { border-radius: 16px; }
  .translator { padding: 14px; }
  .translator-top, .editor-grid { grid-template-columns: 1fr; }
  .translator-top { gap: 10px; }
  .swap-button { width: 100%; }
  .panel-head { font-size: 13px; }
  textarea { min-height: 220px; padding: 14px; font-size: 16px; }
  .actions { gap: 10px; }
  #textTranslatorBlock .text-translate-actions {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: stretch;
  }
  #textTranslatorBlock .text-translate-actions .button-primary,
  #textTranslatorBlock .text-translate-actions .translation-engine-toggle {
    width: auto;
    min-width: 0;
    flex: 1 1 0;
  }
  .translation-engine-toggle {
    grid-template-columns: 38px minmax(0, 1fr);
    min-height: 46px;
    padding: 0 10px;
    gap: 8px;
    font-size: 13px;
    max-width: none;
  }
  .translation-engine-track {
    width: 38px;
    height: 22px;
    flex-basis: 38px;
  }
  .translation-engine-thumb {
    width: 14px;
    height: 14px;
  }
  .translation-engine-toggle input:checked + .translation-engine-track .translation-engine-thumb {
    transform: translateX(16px);
  }
  .translation-engine-copy {
    font-size: 12px;
  }
  .button, .swap-button, .icon-button, select { min-height: 46px; }
  .select-trigger { min-height: 46px; }
  .endpoint { font-size: 13px; padding: 12px; }
  .image-upload-box { min-height: 132px; }
  .image-upload-title { font-size: 15px; }
  .image-upload-subtitle { font-size: 13px; }
  .image-upload-hint { font-size: 12px; }
}
@media (max-width: 480px) {
  .app-shell { padding: 12px 10px 20px; }
  .brand h1 { font-size: 20px; }
  .brand p { font-size: 13px; }
  .model-pill { max-width: calc(100vw - 90px); font-size: 12px; }
  textarea { min-height: 180px; }
  .panel-head { flex-wrap: wrap; align-items: flex-start; }
  .icon-button { width: 42px; height: 42px; }
}



/* compact image translator */
.image-translator .image-panel-head {
  margin-bottom: 10px;
}
.image-compact-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(340px, 0.95fr);
  gap: 16px;
}
.image-preview-panel {
  overflow: hidden;
}
.image-preview-stage {
  position: relative;
  min-height: 500px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  overflow: hidden;
}
.image-preview-stage input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 3;
}
.image-preview-stage.drag-active {
  border-color: var(--accent);
  background: rgba(62,166,255,0.06);
}
.image-canvas-wrap {
  position: relative;
  min-height: 500px;
  display: grid;
  place-items: center;
  background: #131313;
  overflow: auto;
  padding: 16px;
}
body.light-theme .image-canvas-wrap {
  background: #ffffff;
}
#translatedImageCanvas {
  max-width: 100%;
  height: auto;
  display: none;
  border-radius: 10px;
}
#translatedImageCanvas.is-ready { display: block; }
.image-canvas-placeholder {
  text-align: center;
  color: var(--muted);
  max-width: 340px;
  line-height: 1.55;
  padding: 28px;
}
.image-canvas-placeholder.is-hidden { display: none; }
.image-upload-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  margin-top: 14px;
}
.ocr-panel textarea {
  min-height: 500px;
}
@media (max-width: 1100px) {
  .image-compact-grid {
    grid-template-columns: 1fr;
  }
  .ocr-panel textarea,
  .image-preview-stage,
  .image-canvas-wrap {
    min-height: 320px;
  }
}


#xunityBlock .side-card-inline { max-width: 100%; }
#xunityBlock .endpoint { font-size: 15px; }


.image-preview-head { display:none; }
.image-view-switch {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 4;
}
.image-status-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 4;
}
.image-file-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  bottom: auto;
  z-index: 4;
  width: max-content;
  max-width: min(54%, 400px);
}
.image-overlay-badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(15,15,15,.78);
  border: 1px solid rgba(255,255,255,.12);
  color: #fff;
  font-size: 12px;
  backdrop-filter: blur(4px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
body.light-theme .image-overlay-badge {
  background: rgba(255,255,255,.92);
  border-color: rgba(0,0,0,.12);
  color: #111;
}
.ocr-switcher-head { justify-content: flex-start; }
.ocr-switcher-head { justify-content: flex-start; }
.segment-switch {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
}
.segment-button {
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
.segment-button.active {
  background: var(--surface);
  color: var(--text);
}
@media (max-width: 760px) {
  .image-view-switch {
    top: 10px;
    left: 10px;
  }
  .image-status-badge {
    top: 10px;
    right: 10px;
  }
  .image-file-badge {
    top: 10px;
    right: 10px;
    bottom: auto;
    max-width: calc(100% - 20px);
  }
  .image-overlay-badge {
    font-size: 11px;
    min-height: 28px;
    padding: 0 10px;
  }
  .ocr-switcher-head .segment-switch {
    width: 100%;
  }
  .ocr-switcher-head .segment-button {
    flex: 1 1 0;
  }
}


.image-compact-grid {
  align-items: stretch;
}
.image-compact-grid > .panel {
  height: 100%;
}
.image-preview-panel,
.ocr-panel {
  min-height: 0;
}
.ocr-panel {
  display: flex;
}
.ocr-panel textarea {
  flex: 1 1 auto;
  height: 100%;
  resize: none;
}
.ocr-panel.is-mobile-collapsed {
  min-height: 0 !important;
}
.ocr-panel.is-mobile-collapsed .ocr-output-text {
  display: none !important;
}
.image-preview-stage {
  height: 100%;
}
.image-preview-stage.is-processing {
  pointer-events: none;
}
.image-preview-stage.is-processing::after {
  content: "Подождите, текущее изображение ещё обрабатывается";
  position: absolute;
  inset: auto 16px 16px 16px;
  z-index: 5;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(15,15,15,.82);
  border: 1px solid rgba(255,255,255,.12);
  color: #fff;
  font-size: 13px;
  text-align: center;
  backdrop-filter: blur(4px);
}
.image-preview-stage.is-processing input[type="file"] {
  cursor: not-allowed;
}
@media (max-width: 1100px) {
  .ocr-panel {
    min-height: 320px !important;
  }
}


.image-preview-stage input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.image-canvas-wrap {
  align-items: flex-start;
  justify-items: center;
}
#translatedImageCanvas,
#originalImagePreview {
  max-width: none;
  height: auto;
  display: none;
  border-radius: 10px;
}
#translatedImageCanvas.is-ready,
#originalImagePreview.is-ready {
  display: block;
}
#translatedImageCanvas.is-visible,
#originalImagePreview.is-visible {
  display: block;
}
#translatedImageCanvas:not(.is-visible),
#originalImagePreview:not(.is-visible) {
  display: none;
}
#originalImagePreview {
  object-fit: contain;
}
.image-view-switch.is-hidden { display: none; }
.image-view-switch {
  margin-right: auto;
}
.image-overlay-meta {
  left: 14px;
  right: 14px;
  justify-content: flex-end;
}
.image-preview-stage.is-processing::after {
  content: "Подождите, идёт обработка изображения";
  position: absolute;
  inset: auto 16px 16px 16px;
  z-index: 4;
  padding: 12px 14px;
  text-align: center;
  border-radius: 12px;
  color: #fff;
  background: rgba(15,15,15,.82);
  border: 1px solid rgba(255,255,255,.12);
}
@media (max-width: 760px) {
  .image-preview-stage,
  .image-canvas-wrap,
  .ocr-panel textarea {
    min-height: 420px;
  }
  .image-overlay-meta {
    gap: 6px;
  }
  .image-view-switch { margin-right: 0; }
}




/* precise overlay positions */
.image-preview-stage {
  background: #131313;
  display: flex;
  position: relative;
}
.image-canvas-wrap {
  width: 100%;
  height: 100%;
  min-height: inherit;
  align-items: center;
  justify-items: center;
  background: #131313;
}
.image-canvas-placeholder {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
}
.image-canvas-placeholder.is-hidden {
  display: none !important;
}
#originalImagePreview,
#translatedImageCanvas {
  max-width: 100%;
}
#originalImagePreview {
  max-height: min(72vh, 920px);
}
#translatedImageCanvas {
  max-height: min(72vh, 920px);
}
.image-overlay-meta {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}
.image-overlay-meta > * {
  pointer-events: auto;
}
.image-view-switch {
  position: absolute;
  top: 14px;
  left: 14px;
  margin: 0;
}
#imageFileName {
  position: absolute;
  top: 14px;
  right: 20px;
  bottom: auto;
  width: max-content;
  max-width: min(46%, 320px);
  text-align: right;
}
.image-preview-stage.is-processing::after {
  inset: auto 16px 16px 16px;
  z-index: 5;
}
@media (max-width: 760px) {
  #originalImagePreview,
  #translatedImageCanvas {
    max-height: 58vh;
  }
  .image-view-switch {
    top: 10px;
    left: 10px;
  }
  #imageFileName {
    top: 10px;
    right: 14px;
    bottom: auto;
    max-width: calc(100% - 28px);
  }
}


/* refined controls and theme assets */
.panel-head-tools {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  position: relative;
}
.icon-button-image img,
.icon-button-inline img {
  width: 20px;
  height: 20px;
  object-fit: contain;
  display: block;
}
.icon-button-inline {
  width: 36px;
  height: 36px;
}
.icon-button[data-tooltip]:hover::after,
.icon-button[data-tooltip]:focus-visible::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(-50%);
  background: #fff;
  color: #171717;
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 14px;
  line-height: 1;
  box-shadow: 0 10px 24px rgba(0,0,0,.2);
  white-space: nowrap;
  z-index: 30;
}
.icon-button[data-tooltip]:hover::before,
.icon-button[data-tooltip]:focus-visible::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(100% + 2px);
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: #fff;
  z-index: 30;
}
.image-actions {
  align-items: center;
}
.image-reset-btn {
  border-radius: 14px;
}
#textTranslatorBlock .actions {
  align-items: center;
}
#textTranslatorBlock .button-primary,
#imageTranslatorBlock .button-primary {
  min-width: 190px;
}
.text-translate-actions {
  align-items: center;
  flex-wrap: wrap;
}
.translation-engine-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  flex: 1 1 520px;
  min-width: 0;
  max-width: 100%;
}
.translation-engine-toggle {
  display: inline-grid;
  grid-template-columns: 44px minmax(108px, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 48px;
  min-width: 178px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.translation-engine-copy {
  min-width: 0;
  max-width: 100%;
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.translation-engine-copy strong {
  color: var(--text);
  font-size: 14px;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.xunity-engine-panel {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
@media (max-width: 560px) {
  .xunity-engine-panel {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  .xunity-engine-panel .translation-engine-toggle {
    width: 100%;
    min-width: 0;
  }
}
.translation-engine-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}
.translation-engine-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.translation-engine-track {
  position: relative;
  width: 44px;
  height: 24px;
  flex: 0 0 44px;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.16);
  transition: background .15s ease, border-color .15s ease;
}
.translation-engine-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  transition: transform .15s ease;
}
.translation-engine-toggle input:checked + .translation-engine-track {
  background: var(--accent);
  border-color: var(--accent);
}
.translation-engine-toggle input:checked + .translation-engine-track .translation-engine-thumb {
  transform: translateX(20px);
}
.translation-engine-toggle:focus-within {
  border-color: var(--line);
  outline: none;
}
html[data-theme="light"] .translation-engine-track,
body.light-theme .translation-engine-track {
  background: rgba(0,0,0,.08);
  border-color: rgba(0,0,0,.12);
}

/* image overlay placement */
.image-preview-stage {
  background: var(--surface-2) !important;
}
.image-canvas-wrap {
  background: var(--surface-2) !important;
}
html[data-theme="light"] .image-preview-stage,
html[data-theme="light"] .image-canvas-wrap,
body.light-theme .image-preview-stage,
body.light-theme .image-canvas-wrap {
  background: #ffffff !important;
}
html[data-theme="light"] .image-canvas-placeholder,
body.light-theme .image-canvas-placeholder {
  color: #1a1a1a !important;
}
html[data-theme="light"] .image-upload-title,
body.light-theme .image-upload-title {
  color: #111 !important;
}
html[data-theme="light"] .image-upload-subtitle,
body.light-theme .image-upload-subtitle {
  color: rgba(17,17,17,.72) !important;
}
html[data-theme="light"] .image-upload-inline,
body.light-theme .image-upload-inline {
  color: #111 !important;
  background: #fff !important;
  border-color: rgba(0,0,0,.12) !important;
  box-shadow: 0 8px 20px rgba(0,0,0,.06) !important;
}
.image-preview-stage .image-view-switch {
  top: 10px !important;
  left: 10px !important;
  opacity: .86 !important;
  transition: opacity .18s ease;
}
.image-preview-stage .image-view-switch:hover,
.image-preview-stage .image-view-switch:focus-within {
  opacity: 1 !important;
}
.image-preview-stage #imageFileName {
  top: 10px !important;
  right: 10px !important;
  bottom: auto !important;
  width: max-content !important;
  transform: none !important;
  max-width: min(54%, 400px) !important;
  text-align: right;
}
.image-preview-stage.is-processing::after {
  content: "Подождите, идёт обработка изображения";
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  padding: 12px 14px;
  text-align: center;
  border-radius: 12px;
  color: #fff;
  background: rgba(15,15,15,.82);
  border: 1px solid rgba(255,255,255,.12);
  z-index: 5;
}
html[data-theme="light"] .image-preview-stage.is-processing::after,
body.light-theme .image-preview-stage.is-processing::after {
  color: #111;
  background: rgba(255,255,255,.95);
  border-color: rgba(0,0,0,.12);
}

@media (max-width: 760px) {
  .icon-button[data-tooltip]:hover::after,
  .icon-button[data-tooltip]:focus-visible::after,
  .icon-button[data-tooltip]:hover::before,
  .icon-button[data-tooltip]:focus-visible::before {
    display: none;
  }
  .image-preview-stage .image-view-switch {
    top: 8px !important;
    left: 8px !important;
  }
  .image-preview-stage #imageFileName {
    top: 8px !important;
    right: 8px !important;
    bottom: auto !important;
    max-width: calc(100% - 16px) !important;
  }
}

/* image action clear button should look like normal button */
.image-actions {
  gap: 12px;
}
.image-reset-btn {
  width: auto;
  min-width: 190px;
  height: auto;
  min-height: 46px;
  border-radius: 14px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.image-reset-btn img {
  width: 18px;
  height: 18px;
  object-fit: contain;
}
html[data-theme="dark"] .image-reset-btn img,
body:not(.light-theme) .image-reset-btn img {
  filter: brightness(0) invert(1);
}
html[data-theme="light"] .image-reset-btn img,
body.light-theme .image-reset-btn img {
  filter: none;
}

/* image translation progress */
.image-preview-stage.is-processing::after {
  display: none !important;
}
.image-progress {
  display: none;
  position: absolute;
  right: 14px;
  bottom: 16px;
  z-index: 5;
  width: min(250px, calc(100% - 28px));
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px;
  color: #fff;
  background: rgba(15,15,15,.86);
  backdrop-filter: blur(6px);
}
.image-progress[data-state="processing"] {
  display: flex;
  align-items: center;
  gap: 10px;
}
.image-language-warning {
  position: absolute;
  right: 14px;
  bottom: 82px;
  z-index: 6;
  max-width: min(380px, calc(100% - 28px));
  padding: 10px 12px;
  border: 1px solid rgba(255, 178, 69, .55);
  border-radius: 10px;
  background: rgba(90, 53, 10, .9);
  color: #ffd999;
  font-size: 13px;
  line-height: 1.35;
  box-shadow: 0 10px 28px rgba(0,0,0,.22);
  backdrop-filter: blur(6px);
}
.image-language-warning[hidden] {
  display: none;
}
.image-progress-spinner {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,.24);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: image-progress-spin .8s linear infinite;
}
.image-progress-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.image-progress #imageProgressLabel {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #fff;
  font-size: 13px;
}
#imageProgressValue {
  color: rgba(255,255,255,.64);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
@keyframes image-progress-spin {
  to { transform: rotate(360deg); }
}
html[data-theme="light"] .image-progress,
body.light-theme .image-progress {
  color: #111;
  background: rgba(255,255,255,.95);
  border-color: rgba(0,0,0,.12);
}
html[data-theme="light"] .image-language-warning,
body.light-theme .image-language-warning {
  background: rgba(255, 247, 231, .96);
  color: #7a3c00;
  border-color: rgba(199, 115, 0, .34);
}
html[data-theme="light"] .image-progress #imageProgressLabel,
body.light-theme .image-progress #imageProgressLabel {
  color: #111;
}
html[data-theme="light"] #imageProgressValue,
body.light-theme #imageProgressValue {
  color: rgba(17,17,17,.58);
}
html[data-theme="light"] .image-progress-spinner,
body.light-theme .image-progress-spinner {
  border-color: rgba(0,0,0,.16);
  border-top-color: var(--accent);
}
@media (max-width: 760px) {
  .image-progress { right: 8px; bottom: 8px; }
  .image-language-warning {
    right: 8px;
    bottom: 56px;
    max-width: calc(100% - 16px);
    padding: 8px 10px;
    font-size: 12px;
  }
}

.global-image-drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  place-items: center;
  pointer-events: none;
  color: #fff;
  background: rgba(10, 10, 12, .84);
  border: 2px dashed rgba(255, 255, 255, .34);
  backdrop-filter: blur(8px);
}
.global-image-drop-overlay.is-active {
  display: grid;
}
.global-image-drop-content {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 28px;
  text-align: center;
}
.global-image-drop-content .icon-svg {
  width: 52px;
  height: 52px;
  color: var(--accent);
}
.global-image-drop-content strong {
  font-size: clamp(22px, 3vw, 34px);
}

/* crisp vector icons */
.icon-svg {
  width: 18px;
  height: 18px;
  display: block;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#themeToggleIcon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}
#themeToggleIcon .icon-svg {
  width: 20px;
  height: 20px;
}
#themeToggleIcon .theme-system-fill {
  fill: currentColor;
  stroke: none;
}
.icon-button-image,
.text-panel-action,
.image-reset-btn {
  color: var(--text);
}
html[data-theme="light"] .icon-button-image,
html[data-theme="light"] .text-panel-action,
html[data-theme="light"] .image-reset-btn {
  color: #181818;
}

/* tooltips only for copy/delete, not theme toggle */
#themeToggle::before,
#themeToggle::after {
  display: none !important;
}

/* final theme + text controls + image sizing fixes */
#themeToggle {
  background: var(--surface-2);
  border-color: var(--line);
}
#themeToggleIcon {
  width: 20px;
  height: 20px;
  object-fit: contain;
  display: block;
}
html[data-theme="dark"] #themeToggleIcon,
body.theme-dark-active #themeToggleIcon,
html:not([data-theme="light"]) body:not(.light-theme) #themeToggleIcon {
  filter: brightness(0) invert(1) contrast(1.1);
}
html[data-theme="light"] #themeToggleIcon,
body.light-theme #themeToggleIcon {
  filter: none;
}

.text-panel-body {
  position: relative;
}
.text-panel-body textarea {
  padding-right: 58px;
}
.text-panel-action {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.18);
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.text-panel-action img {
  width: 18px;
  height: 18px;
  display: block;
  object-fit: contain;
}
html[data-theme="dark"] .text-panel-action img,
body.theme-dark-active .text-panel-action img,
html:not([data-theme="light"]) body:not(.light-theme) .text-panel-action img {
  filter: brightness(0) invert(1) contrast(1.1);
}
html[data-theme="light"] .text-panel-action,
body.light-theme .text-panel-action {
  background: rgba(0,0,0,.05);
  border-color: rgba(0,0,0,.14);
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
html[data-theme="light"] .text-panel-action img,
body.light-theme .text-panel-action img {
  filter: none;
}

.image-canvas-wrap {
  align-items: center !important;
  justify-items: center !important;
}
#originalImagePreview,
#translatedImageCanvas {
  max-width: min(100%, 860px);
  max-height: min(62vh, 620px);
}
.header-admin-link {
  text-decoration: none;
}

.icon-button-image img,
.text-panel-action img,
.image-reset-btn img {
  width: 18px;
  height: 18px;
  display: block;
  object-fit: contain;
}

.xunity-section {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: var(--surface-2);
  margin-top: 12px;
}

.xunity-section h2 {
  margin: 0 0 8px;
  font-size: 17px;
}

/* Translated image hover highlights */
.image-region-overlay {
  position: absolute;
  z-index: 4;
  display: none;
  overflow: hidden;
  pointer-events: none;
}
.image-region-overlay.is-ready {
  display: block;
}
  .image-region-hit {
    position: absolute;
    min-width: 8px;
    min-height: 8px;
    padding: 0;
    overflow: hidden;
    pointer-events: none;
    border: 0;
    border-radius: 6px;
    background: transparent;
  box-shadow: none;
  pointer-events: auto;
  cursor: default;
  opacity: 0;
  transition: opacity .12s ease, background-color .12s ease, box-shadow .12s ease;
}
.image-region-hit:hover,
.image-region-hit:focus-visible,
.image-region-hit.is-highlighted {
  border: 0;
  background: rgba(255, 216, 77, .16);
  box-shadow: inset 0 0 0 2px rgba(255, 216, 77, .82);
  opacity: 1;
  outline: none;
}
.ocr-panel {
  min-width: 0;
  position: relative;
}
.ocr-output-text {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 500px;
  resize: none;
  white-space: pre-wrap;
}
/*
 * Hovering a region on the image selects its text here, and that selection is
 * tinted yellow to tie the two together. Selecting by hand must stay the
 * browser default, so the rule is scoped to the hover state only.
 */
.ocr-output-text.is-region-hover::selection {
  background: rgba(255, 216, 77, .34);
  color: inherit;
}
.ocr-output-text.is-region-hover::-moz-selection {
  background: rgba(255, 216, 77, .34);
  color: inherit;
}
.ocr-output-text[hidden] {
  display: none;
}
@media (max-width: 760px) {
  .image-region-hit {
    min-width: 10px;
    min-height: 10px;
  }
}

.xunity-section p {
  margin: 0 0 10px;
}

.download-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.download-list-spaced {
  margin-top: 12px;
}

.download-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.download-item > * {
  min-width: 0;
}

.download-item code {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.download-item a {
  color: var(--accent);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.download-details summary {
  cursor: pointer;
  font-weight: 600;
  margin-bottom: 10px;
}

.download-picker {
  display: grid;
  gap: 10px;
  margin: 10px 0 6px;
}

.download-cta {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
}

body.admin-page .app-shell {
  max-width: 1100px;
}

body.admin-login-page .app-shell {
  width: 100%;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.admin-login-header {
  justify-content: flex-end;
  margin-bottom: 0;
}

.admin-login-header .header-right {
  justify-content: flex-end;
}

.admin-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.admin-grid {
  display: grid;
  gap: 14px;
}

.admin-section {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: var(--surface-2);
}

.admin-section h2 {
  margin: 0 0 10px;
  font-size: 18px;
}

.admin-fields {
  display: grid;
  gap: 10px;
}

.admin-section-intro {
  max-width: 980px;
  margin: -2px 0 14px;
  line-height: 1.55;
}

.admin-settings-group {
  min-width: 0;
  border-top: 1px solid var(--line);
}

.admin-settings-group > summary {
  padding: 14px 2px;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.admin-settings-group > summary:hover {
  color: var(--accent);
}

.admin-settings-body {
  display: grid;
  min-width: 0;
  gap: 12px;
  padding: 0 2px 16px;
}

.admin-settings-body .admin-row {
  align-items: start;
}

.admin-settings-body .admin-row > label {
  padding-top: 10px;
  font-weight: 600;
}

.admin-settings-body .admin-help {
  margin: 6px 0 0;
  max-width: 980px;
  line-height: 1.45;
}

.admin-language-guide,
.admin-profile-guide {
  margin-top: 14px;
}

.admin-table-scroll {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
}

.admin-language-table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-language-table th,
.admin-language-table td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  line-height: 1.45;
}

.admin-language-table th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
}

.admin-language-table td:last-child {
  min-width: 280px;
  color: var(--muted);
}

.admin-profile-list {
  gap: 8px;
}

.admin-profile-list p {
  margin: 0;
  line-height: 1.5;
}

.admin-row {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 12px;
  align-items: center;
}

.admin-row-no-label {
  grid-template-columns: 1fr;
}

.admin-inline {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.admin-status-ok {
  color: #40c463;
}

.admin-status-err {
  color: #ff7b7b;
}

/* Admin panel */
.admin-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  gap: 16px;
}
.admin-panel + .admin-panel {
  margin-top: 14px;
}
.admin-panel .panel-head {
  font-size: 16px;
  padding: 0;
}
.admin-panel .panel-head .ph {
  margin-right: 8px;
  vertical-align: -2px;
}

.admin-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px 18px;
  align-items: end;
  margin: 0;
}
.admin-form > label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
.admin-form > label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  color: var(--text);
}
.admin-form > button {
  grid-column: 1 / -1;
  justify-self: start;
}

.admin-form input[type="text"],
.admin-form input[type="password"],
.admin-form input[type="number"],
.admin-form input[type="file"] {
  width: 100%;
  min-width: 0;
}
.admin-form input[type="file"] {
  padding: 12px;
  cursor: pointer;
}
.admin-form input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  accent-color: var(--accent);
  cursor: pointer;
}
.admin-form input:focus-visible,
.admin-form select:focus-visible,
.admin-panel button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* The login form is three short fields; a full-width grid reads as broken. */
.admin-panel-auth {
  width: 100%;
  max-width: 420px;
  margin: 48px auto 0;
}
.admin-panel-auth .admin-form {
  grid-template-columns: 1fr;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.inline-form {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}
.admin-panel .download-item .inline-form {
  margin-left: auto;
}

.admin-notifications {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1200;
  width: min(420px, calc(100vw - 24px));
  display: grid;
  gap: 10px;
}

.admin-notification {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .28);
}

.admin-notification-error {
  border-left-color: #ef5350;
}

.admin-notification-success {
  border-left-color: #40c463;
}

.admin-notification-text {
  margin: 2px 0 0;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.admin-notification-actions {
  display: flex;
  gap: 4px;
}

.admin-notification-button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.admin-notification-button:hover {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.admin-notification-button.is-copied {
  color: #40c463;
}

.admin-notification-button .icon-svg {
  width: 17px;
  height: 17px;
}

.admin-help {
  font-size: 13px;
  color: var(--muted);
}

.admin-login-shell {
  align-self: center;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 0;
}

.admin-login-card {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.admin-login-card h2 {
  margin: 0 0 8px;
}

.admin-login-fields {
  display: grid;
  gap: 12px;
  margin-top: 10px;
}

.admin-login-row {
  display: grid;
  gap: 6px;
}

.admin-login-row label {
  color: var(--muted);
  font-size: 13px;
}

body.admin-page input[type="text"],
body.admin-page input[type="password"],
body.admin-page input[type="number"],
body.admin-page input[type="file"],
body.admin-page textarea,
body.admin-page select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
  font: inherit;
}

body.admin-page input[type="file"] {
  padding: 8px 12px;
  min-height: 56px;
  line-height: 1.2;
}

body.admin-page input[type="file"]::file-selector-button {
  margin-right: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
}

body.admin-page input[type="file"]::-webkit-file-upload-button {
  margin-right: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
}

body.admin-page input[type="file"]::file-selector-button:hover,
body.admin-page input[type="file"]::-webkit-file-upload-button:hover {
  opacity: 0.92;
}

body.admin-page .admin-file-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

body.admin-page .admin-file-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  justify-content: flex-start;
}

body.admin-page .admin-file-control input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

body.admin-page .admin-file-pick {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  line-height: 1;
  text-align: center;
}

body.admin-page .admin-file-name {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  padding: 0 12px;
  max-width: min(100%, 520px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.admin-page .admin-brand-upload {
  display: grid;
  gap: 10px;
  min-width: 0;
}

body.admin-page .admin-brand-preview {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  min-width: 0;
  overflow-wrap: anywhere;
}

body.admin-page .admin-brand-preview img {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.04);
  object-fit: cover;
  flex: 0 0 auto;
}

body.admin-page .admin-brand-remove {
  justify-content: flex-start;
}

body.admin-page #download_upload_btn[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

body.admin-page textarea {
  min-height: 96px;
  padding: 12px 14px;
}

body.admin-page input[type="text"]:focus,
body.admin-page input[type="password"]:focus,
body.admin-page input[type="number"]:focus,
body.admin-page input[type="file"]:focus,
body.admin-page textarea:focus,
body.admin-page select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

/* mobile image translation polish */
.image-preview-stage {
  min-height: clamp(360px, 48vw, 620px);
}

.image-canvas-wrap {
  padding: 8px !important;
  overflow: auto;
  align-content: center;
}

#originalImagePreview,
#translatedImageCanvas {
  max-width: 100% !important;
  max-height: min(70vh, 720px) !important;
  object-fit: contain;
}

.image-progress {
  width: auto;
  min-width: 218px;
  max-width: calc(100% - 20px);
  right: 10px;
  bottom: 10px;
  padding: 10px 10px 10px 12px;
}

.image-progress[data-state="processing"] {
  flex-direction: row-reverse;
  justify-content: space-between;
  gap: 12px;
}

.image-progress-copy {
  text-align: left;
}

@media (max-width: 760px) {
  body:not(.admin-page):not(.admin-login-page) {
    padding-bottom: 66px;
  }

  .app-shell {
    padding-bottom: 18px;
  }

  .translator-tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 80;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 2px;
    margin: 0;
    padding: 6px 10px calc(7px + env(safe-area-inset-bottom, 0px));
    border: 0;
    border-top: 1px solid rgba(255,255,255,.08);
    border-radius: 14px 14px 0 0;
    background: rgba(3,3,4,.94);
    box-shadow: 0 -16px 36px rgba(0,0,0,.45);
    backdrop-filter: blur(14px);
  }

  .translator-tabs .tab-button {
    width: 100%;
    min-height: 46px;
    padding: 2px 4px 1px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: rgba(255,255,255,.55);
    font-size: 11px;
    line-height: 1.1;
    white-space: normal;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .translator-tabs .tab-icon {
    display: block;
    width: 21px;
    height: 21px;
    stroke-width: 2.3;
  }

  .translator-tabs .tab-button.active {
    background: transparent;
    color: var(--accent);
    font-weight: 700;
  }

  .translator-tabs .tab-button.active .tab-icon {
    filter: drop-shadow(0 0 10px rgba(62,166,255,.28));
  }

  html[data-theme="light"] .translator-tabs,
  body.light-theme .translator-tabs {
    background: rgba(255,255,255,.95);
    border-top-color: rgba(0,0,0,.08);
    box-shadow: 0 -16px 36px rgba(0,0,0,.16);
  }

  html[data-theme="light"] .translator-tabs .tab-button,
  body.light-theme .translator-tabs .tab-button {
    color: rgba(17,17,17,.48);
  }

  html[data-theme="light"] .translator-tabs .tab-button.active,
  body.light-theme .translator-tabs .tab-button.active {
    color: var(--accent);
  }

  .image-translator-top {
    grid-template-columns: minmax(0, 1fr) 46px minmax(0, 1fr) !important;
    gap: 8px;
    align-items: stretch;
  }

  #textTranslatorBlock .translator-top {
    grid-template-columns: minmax(0, 1fr) 46px minmax(0, 1fr) !important;
    gap: 8px;
    align-items: stretch;
  }

  .image-translator-top .field {
    min-width: 0;
  }

  #textTranslatorBlock .translator-top .field {
    min-width: 0;
  }

  #imageSwapBtn {
    width: 46px !important;
    min-width: 46px;
    max-width: 46px;
    height: 46px;
    min-height: 46px;
    max-height: 46px;
    aspect-ratio: 1;
    display: inline-grid;
    place-items: center;
    padding: 0;
  }

  #swapBtn {
    width: 46px !important;
    min-width: 46px;
    max-width: 46px;
    height: 46px;
    min-height: 46px;
    max-height: 46px;
    aspect-ratio: 1;
    display: inline-grid;
    place-items: center;
    padding: 0;
  }

  .image-translator-top .select-trigger {
    min-height: 46px;
    padding: 0 10px;
    font-size: 14px;
  }

  #textTranslatorBlock .translator-top .select-trigger {
    min-height: 46px;
    padding: 0 10px;
    font-size: 14px;
  }

  .image-preview-stage {
    min-height: min(72vh, 520px);
  }

  .image-canvas-wrap {
    min-height: min(72vh, 520px) !important;
    padding: 6px !important;
  }

  #originalImagePreview,
  #translatedImageCanvas {
    max-height: none !important;
  }

  .select-value .lang-option-code,
  .select-option .lang-option-code {
    display: none;
  }

  .select-option {
    min-height: 36px;
    padding: 7px 9px;
    white-space: nowrap;
  }

  .select-options {
    max-height: 260px;
    overflow-x: hidden;
  }

  .image-preview-panel {
    margin-left: -8px;
    margin-right: -8px;
  }

  .image-preview-stage {
    border-color: transparent;
    background: transparent;
  }

  .image-preview-stage:has(.image-canvas-placeholder:not(.is-hidden)) {
    min-height: 112px;
    border-color: transparent;
    background: transparent !important;
  }

  .image-preview-stage:has(.image-canvas-placeholder:not(.is-hidden)) .image-canvas-wrap {
    min-height: 110px !important;
    padding: 18px 0 !important;
    background: transparent !important;
  }

  .image-preview-stage:has(.image-canvas-placeholder:not(.is-hidden)) .image-canvas-placeholder {
    position: static;
    transform: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    width: min(100%, 252px);
    min-height: 50px;
    padding: 0 16px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    color: var(--text);
    line-height: 1;
  }

  .image-preview-stage:has(.image-canvas-placeholder:not(.is-hidden)) .image-canvas-placeholder::before {
    content: "+";
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-weight: 800;
    line-height: 1;
  }

  .image-preview-stage:has(.image-canvas-placeholder:not(.is-hidden)) .image-upload-title {
    margin: 0;
    font-size: 14px;
  }

  .image-preview-stage:has(.image-canvas-placeholder:not(.is-hidden)) .image-upload-subtitle {
    display: none;
  }

  .image-preview-stage:has(#originalImagePreview.is-visible),
  .image-preview-stage:has(#translatedImageCanvas.is-visible),
  .image-preview-stage:has(#originalImagePreview.is-ready),
  .image-preview-stage:has(#translatedImageCanvas.is-ready) {
    border-color: transparent;
    background: transparent;
  }

  .image-preview-stage:has(#originalImagePreview.is-visible),
  .image-preview-stage:has(#translatedImageCanvas.is-visible),
  .image-preview-stage:has(#originalImagePreview.is-ready),
  .image-preview-stage:has(#translatedImageCanvas.is-ready) {
    min-height: 0;
  }

  .image-preview-stage:has(#originalImagePreview.is-visible) .image-canvas-wrap,
  .image-preview-stage:has(#translatedImageCanvas.is-visible) .image-canvas-wrap,
  .image-preview-stage:has(#originalImagePreview.is-ready) .image-canvas-wrap,
  .image-preview-stage:has(#translatedImageCanvas.is-ready) .image-canvas-wrap {
    min-height: 0 !important;
  }

  .image-progress {
    width: auto;
    min-width: 86px;
    min-height: 38px;
    right: 8px;
    bottom: 8px;
    padding: 7px 9px 7px 10px;
    border-radius: 10px;
  }

  .image-progress[data-state="processing"] {
    display: inline-flex;
    flex-direction: row;
    justify-content: center;
    gap: 8px;
  }

  .image-progress-spinner {
    order: 2;
    width: 17px;
    height: 17px;
    border-width: 2px;
  }

  .image-progress-copy {
    display: block;
  }

  .image-progress #imageProgressLabel {
    display: none;
  }

  #imageProgressValue {
    display: block;
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
  }

  .image-view-switch.segment-switch {
    width: auto;
    max-width: calc(100% - 20px);
    padding: 3px;
    gap: 3px;
    border-radius: 10px;
  }

  .image-view-switch .segment-button {
    flex: 0 1 auto;
    min-height: 30px;
    padding: 0 10px;
    border-radius: 8px;
    font-size: 13px;
  }

  .image-file-badge,
  .image-preview-stage #imageFileName {
    min-height: 24px !important;
    max-width: min(46%, 170px) !important;
    padding: 0 8px !important;
    font-size: 10px !important;
    border-radius: 999px;
    opacity: .9;
  }

  .image-actions {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 8px;
    align-items: stretch;
  }

  #imageTranslatorBlock .image-actions .button {
    width: auto;
    min-width: 0;
    flex: 1 1 0;
    min-height: 46px;
    padding: 0 9px;
    font-size: 13px;
    white-space: nowrap;
  }

  #imageTranslatorBlock .image-actions .image-reset-btn {
    flex: 0 1 42%;
  }

  .ocr-switcher-head .segment-button {
    min-height: 40px;
    padding: 0 8px;
    font-size: 13px;
  }

  .translation-engine-toggle {
    max-width: none;
    font-size: 12px;
  }

  .translation-engine-label {
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (max-width: 480px) {
  .image-actions .button {
    font-size: 12px;
  }

  .image-actions .image-reset-btn {
    flex-basis: 38%;
  }
}

.admin-pass-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

/* mobile header and icon polish */
#themeToggle {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
}

#themeToggleIcon {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  filter: none !important;
}

#themeToggleIcon .icon-svg {
  width: 23px;
  height: 23px;
}

.text-panel-action {
  border-radius: 50%;
  width: 46px;
  height: 46px;
  min-height: 46px;
  padding: 0;
}

.text-panel-action .icon-svg {
  width: 24px;
  height: 24px;
  stroke-width: 2.15;
}

.text-resize-grip {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 0;
  height: 24px;
  display: none;
  cursor: ns-resize;
  touch-action: none;
  z-index: 9;
}

.text-resize-grip::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 8px;
  width: 54px;
  height: 4px;
  border-radius: 999px;
  transform: translateX(-50%);
  background: color-mix(in srgb, var(--muted) 45%, transparent);
}

body.is-text-resizing,
body.is-text-resizing * {
  cursor: ns-resize !important;
  user-select: none !important;
}

.text-panel-body textarea {
  padding-right: 16px;
}

.text-panel-action {
  opacity: .92;
  transition: opacity .15s ease, background-color .15s ease, box-shadow .15s ease;
}

.text-panel-body:focus-within .text-panel-action,
.text-panel-body:hover .text-panel-action {
  opacity: .34;
}

.text-panel-action:hover,
.text-panel-action:focus-visible {
  opacity: 1 !important;
}

@media (max-width: 760px) {
  .header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
  }

  .brand {
    grid-column: 1;
    grid-row: 1;
    width: auto;
    min-width: 0;
    gap: 0;
  }

  .brand-logo {
    display: none;
  }

  .brand h1 {
    font-size: 21px;
    line-height: 1.1;
  }

  .brand p {
    font-size: 13px;
    line-height: 1.25;
    margin-top: 4px;
  }

  .model-pill-runtime {
    display: none;
  }

  .header-right {
    grid-column: 2;
    grid-row: 1;
    width: auto;
    margin-left: auto;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 8px;
  }

  .header-admin-link {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .text-panel-body textarea {
    padding-right: 16px !important;
    padding-bottom: 34px;
    resize: none;
  }

  .text-resize-grip {
    display: block;
  }

  .text-panel-action .icon-svg {
    width: 24px;
    height: 24px;
  }
}

.admin-pass-toggle {
  min-width: 96px;
  min-height: 48px;
  border-radius: 14px;
  padding: 0 16px;
}

@media (max-width: 900px) {
  .admin-notifications {
    right: 12px;
    bottom: 12px;
  }
  .admin-login-header .header-right {
    width: auto;
    margin-left: auto;
  }
  .admin-row {
    grid-template-columns: 1fr;
  }
  body.admin-page .download-item {
    align-items: flex-start;
    flex-wrap: wrap;
  }
  body.admin-page .download-item > span:first-child {
    flex: 1 1 240px;
  }
  body.admin-page .admin-file-actions {
    align-items: stretch;
  }
  body.admin-page .admin-file-control,
  body.admin-page .admin-file-name,
  body.admin-page #download_upload_btn {
    width: 100%;
  }
  .admin-pass-wrap {
    grid-template-columns: 1fr;
  }
}
