:root {
  --ai-red: #EC1510;
  --ai-red-dark: #C01210;
  --ai-ink: #1A1A1A;
  --ai-muted: #777;
  --ai-soft: #FFF6F5;
  --ai-line: #F1D8D6;
  --ai-green: #1F8A4C;
  --ai-amber: #B07A1F;
}

.ai-studio {
  direction: rtl;
  font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
}

.ai-studio * {
  box-sizing: border-box;
}

.ai-shell {
  max-width: 980px;
  margin: 0 auto 18px;
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  color: var(--ai-ink);
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.12);
}

.ai-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.ai-title h2 {
  margin: 0 0 6px;
  font-size: 22px;
  line-height: 1.35;
}

.ai-title p {
  margin: 0;
  color: var(--ai-muted);
  font-size: 13px;
  line-height: 1.7;
}

.ai-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--ai-line);
  border-radius: 999px;
  background: var(--ai-soft);
  color: var(--ai-red);
  font-size: 12px;
  white-space: nowrap;
}

.ai-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ai-green);
}

.ai-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
}

.ai-presets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.ai-preset {
  border: 1px solid var(--ai-line);
  border-radius: 999px;
  padding: 8px 13px;
  background: #fff;
  color: var(--ai-ink);
  cursor: pointer;
  font: inherit;
  font-size: 12.5px;
}

.ai-preset:hover,
.ai-preset.active {
  background: var(--ai-soft);
  border-color: var(--ai-red);
  color: var(--ai-red);
}

.ai-panel {
  border: 1px solid var(--ai-line);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
}

.ai-panel-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--ai-line);
  background: var(--ai-soft);
  font-weight: 700;
  font-size: 14px;
}

.ai-upload {
  display: flex;
  min-height: 156px;
  margin: 14px;
  border: 1px dashed var(--ai-red);
  border-radius: 12px;
  background: var(--ai-soft);
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  padding: 18px;
}

.ai-upload strong {
  display: block;
  color: var(--ai-red);
  margin-bottom: 6px;
  font-size: 15px;
}

.ai-upload span {
  display: block;
  color: var(--ai-muted);
  font-size: 12.5px;
  line-height: 1.6;
}

.ai-upload input {
  display: none;
}

.ai-upload.is-dragging {
  background: #FFEDEB;
  box-shadow: 0 0 0 3px rgba(236, 21, 16, .12);
}

.ai-tools {
  display: grid;
  gap: 8px;
  padding: 0 14px 14px;
}

.ai-tool {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 10px 11px;
  border: 1px solid #e7e7e7;
  border-radius: 10px;
  background: #fff;
  color: var(--ai-ink);
  cursor: pointer;
  font: inherit;
  text-align: right;
}

.ai-tool:hover,
.ai-tool.active {
  border-color: var(--ai-red);
  background: var(--ai-soft);
  color: var(--ai-red);
}

.ai-tool svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.ai-control {
  padding: 0 14px 14px;
}

.ai-control label {
  display: block;
  font-size: 12px;
  color: var(--ai-muted);
  margin-bottom: 7px;
}

.ai-control input[type="range"] {
  width: 100%;
  accent-color: var(--ai-red);
}

.ai-preview {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  min-height: 560px;
}

.ai-tabs {
  display: flex;
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--ai-line);
  flex-wrap: wrap;
}

.ai-tab {
  border: 1px solid #e1e1e1;
  border-radius: 999px;
  padding: 7px 13px;
  background: #fff;
  cursor: pointer;
  font-size: 12.5px;
}

.ai-tab.active {
  color: #fff;
  background: var(--ai-red);
  border-color: var(--ai-red);
}

.ai-canvas-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 388px;
  background:
    linear-gradient(45deg, #f7f7f7 25%, transparent 25%),
    linear-gradient(-45deg, #f7f7f7 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f7f7f7 75%),
    linear-gradient(-45deg, transparent 75%, #f7f7f7 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
  overflow: hidden;
}

.ai-canvas-wrap canvas {
  max-width: 100%;
  max-height: 420px;
  width: auto;
  height: auto;
  display: none;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.16);
}

.ai-empty {
  text-align: center;
  color: var(--ai-muted);
  padding: 24px;
  line-height: 1.7;
}

.ai-compare-control {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--ai-line);
}

.ai-compare-control label {
  color: var(--ai-muted);
  font-size: 12px;
  white-space: nowrap;
}

.ai-compare-control input {
  width: 100%;
  accent-color: var(--ai-red);
}

.ai-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-top: 1px solid var(--ai-line);
  flex-wrap: wrap;
}

.ai-action-set {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ai-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 10px 15px;
  border: 1px solid var(--ai-red);
  border-radius: 10px;
  background: var(--ai-red);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  font-size: 13.5px;
}

.ai-btn:hover {
  background: var(--ai-red-dark);
}

.ai-btn.secondary {
  color: var(--ai-red);
  background: #fff;
}

.ai-btn.secondary:hover {
  background: var(--ai-soft);
}

.ai-btn:disabled {
  border-color: #ccc;
  background: #ccc;
  color: #fff;
  cursor: not-allowed;
}

.ai-queue {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 16px;
}

.ai-metric {
  background: var(--ai-soft);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}

.ai-metric strong {
  display: block;
  font-size: 20px;
  margin-bottom: 3px;
}

.ai-metric span {
  color: var(--ai-muted);
  font-size: 12px;
}

.ai-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.ai-thumb {
  border: 1px solid var(--ai-line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  cursor: pointer;
}

.ai-thumb.active {
  border-color: var(--ai-red);
  box-shadow: 0 0 0 2px rgba(236, 21, 16, 0.12);
}

.ai-thumb img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
}

.ai-thumb span {
  display: block;
  padding: 7px;
  color: var(--ai-muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-thumb b {
  display: block;
  margin: 0 7px 7px;
  padding: 3px 7px;
  border-radius: 999px;
  background: #EAF7EF;
  color: var(--ai-green);
  font-size: 10.5px;
  font-weight: 700;
}

.ai-info {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--ai-line);
  border-radius: 10px;
  background: #fff;
  color: var(--ai-muted);
  font-size: 12px;
  line-height: 1.6;
}

.ai-ocr-panel {
  margin-top: 12px;
  border: 1px solid var(--ai-line);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
}

.ai-ocr-panel[hidden] {
  display: none;
}

.ai-ocr-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: var(--ai-soft);
  border-bottom: 1px solid var(--ai-line);
}

.ai-ocr-head strong {
  color: var(--ai-ink);
  font-size: 14px;
}

.ai-ocr-head span {
  color: var(--ai-red);
  font-size: 12px;
  white-space: nowrap;
}

.ai-ocr-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 12px;
}

.ai-ocr-field {
  border: 1px solid #eee;
  border-radius: 10px;
  padding: 10px;
  background: #fff;
  min-width: 0;
}

.ai-ocr-field span {
  display: block;
  color: var(--ai-muted);
  font-size: 11.5px;
  margin-bottom: 5px;
}

.ai-ocr-field strong {
  display: block;
  color: var(--ai-ink);
  font-size: 13px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.ai-ocr-panel textarea {
  display: block;
  width: calc(100% - 24px);
  min-height: 150px;
  margin: 0 12px 12px;
  padding: 12px;
  border: 1px solid #eee;
  border-radius: 10px;
  resize: vertical;
  color: var(--ai-ink);
  background: #FAFAFA;
  font: 13px/1.7 'Segoe UI', Tahoma, Arial, sans-serif;
}

.ai-progress {
  width: 100%;
  height: 7px;
  border-radius: 99px;
  background: var(--ai-line);
  overflow: hidden;
  margin-top: 10px;
  display: none;
}

.ai-progress div {
  height: 100%;
  width: 0%;
  background: var(--ai-red);
  transition: width .2s ease;
}

@media (max-width: 840px) {
  .ai-layout {
    grid-template-columns: 1fr;
  }

  .ai-head {
    display: block;
  }

  .ai-status {
    margin-top: 12px;
  }

  .ai-queue {
    grid-template-columns: repeat(2, 1fr);
  }

  .ai-ocr-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .ai-shell {
    padding: 16px;
    border-radius: 12px;
  }

  .ai-actions {
    align-items: stretch;
  }

  .ai-action-set,
  .ai-btn {
    width: 100%;
  }
}
