/* Мини-приложение «Сжатие картинок» (/mini-app/image-optimizer) */

.io-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 1100px) {
  .io-layout { grid-template-columns: minmax(0, 1fr); }
}

.io-work { overflow: hidden; }
.io-settings { position: sticky; top: calc(var(--topbar-h) + 20px); }
@media (max-width: 1100px) { .io-settings { position: static; } }

.io-link { color: var(--brand); font-weight: 600; }
kbd {
  display: inline-block; padding: 0 5px; min-width: 20px; text-align: center;
  border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px;
  font: 600 11px/18px var(--font); color: var(--text-2); background: var(--surface);
}

/* ---------- загрузка ---------- */
.io-drop {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 420px; margin: 16px; padding: 32px 20px;
  border: 2px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--surface-2);
  text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.io-drop:hover, .io-drop.is-dragover { border-color: var(--brand); background: var(--brand-soft); }
.io-drop.is-uploading { pointer-events: none; }
.io-drop.is-uploading > :not(.io-progress):not(input) { opacity: .35; }
.io-drop__icon {
  display: grid; place-items: center; width: 64px; height: 64px; margin-bottom: 8px;
  border-radius: 18px; background: var(--brand-soft); color: var(--brand); font-size: 32px;
  transition: transform .2s var(--ease);
}
.io-drop.is-dragover .io-drop__icon { transform: translateY(-4px) scale(1.05); }
.io-drop__title { font-size: 17px; font-weight: 700; }
.io-drop__limits { margin-top: 10px; font-size: 12px; }

.io-progress { position: absolute; left: 50%; bottom: 36px; transform: translateX(-50%); width: min(320px, 80%); }
.io-progress__bar { height: 6px; border-radius: 99px; background: var(--border); overflow: hidden; margin-bottom: 8px; }
.io-progress__bar span { display: block; height: 100%; width: 0; background: var(--brand); border-radius: inherit; transition: width .2s; }

/* ---------- редактор ---------- */
.io-editor__bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.io-file-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.io-file-info > i {
  display: grid; place-items: center; flex-shrink: 0; width: 40px; height: 40px;
  border-radius: 10px; background: var(--brand-soft); color: var(--brand); font-size: 20px;
}
.io-file-info > div { min-width: 0; }
.io-file-info__name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.io-file-info__meta { font-size: 12px; }

.io-stage {
  display: flex; align-items: center; justify-content: center;
  height: 460px; padding: 16px;
  /* шахматка — видно прозрачность */
  background-color: var(--surface-2);
  background-image:
    linear-gradient(45deg, var(--border) 25%, transparent 25%),
    linear-gradient(-45deg, var(--border) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--border) 75%),
    linear-gradient(-45deg, transparent 75%, var(--border) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
.io-stage img { display: block; max-width: 100%; max-height: 100%; }
.io-stage.is-cropping { padding: 0; }
.io-stage .cropper-container { max-width: 100%; }
@media (max-width: 640px) { .io-stage { height: 320px; } }

.io-crop-info { padding: 10px 16px; font-size: 12px; border-top: 1px solid var(--border); }

/* ---------- результат ---------- */
.io-result { padding: 20px 16px; border-top: 1px solid var(--border); animation: io-fade .3s var(--ease); }
@keyframes io-fade { from { opacity: 0; transform: translateY(6px); } }

.io-stats { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.io-stat { display: flex; flex-direction: column; gap: 2px; font-size: 12px; }
.io-stat strong { font-size: 20px; line-height: 1.2; color: var(--text); }
.io-stats__arrow { font-size: 22px; color: var(--text-3); }
.io-stat--saved {
  margin-left: auto; padding: 10px 16px; border-radius: var(--radius);
  background: var(--success-soft);
}
.io-stat--saved strong { color: var(--success); }
.io-stat--saved.is-bad { background: var(--warning-soft); }
.io-stat--saved.is-bad strong { color: var(--warning); }
@media (max-width: 640px) { .io-stat--saved { margin-left: 0; width: 100%; } }

.io-note {
  display: flex; gap: 8px; margin-top: 14px; padding: 10px 12px;
  border-radius: var(--radius-sm); background: var(--warning-soft); color: var(--text); font-size: 13px;
}
.io-note i { color: var(--warning); font-size: 18px; }

/* сравнение до/после */
.io-compare {
  position: relative; margin-top: 16px; overflow: hidden;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface-2); user-select: none;
  --pos: 50%;
}
.io-compare__img { display: block; width: 100%; height: auto; max-height: 520px; object-fit: contain; }
.io-compare__after {
  position: absolute; inset: 0;
  clip-path: inset(0 0 0 var(--pos));
  background: var(--surface-2);
}
.io-compare.is-single .io-compare__after { position: static; clip-path: none; }
.io-compare.is-single #io-compare-before,
.io-compare.is-single .io-compare__handle,
.io-compare.is-single .io-compare__label,
.io-compare.is-single .io-compare__range { display: none; }
.io-compare__after .io-compare__img { height: 100%; }
.io-compare__handle {
  position: absolute; top: 0; bottom: 0; left: var(--pos); width: 2px; margin-left: -1px;
  background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .15); pointer-events: none;
}
.io-compare__handle span {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: #fff; color: #161a2e; font-size: 20px; box-shadow: 0 2px 10px rgba(0, 0, 0, .25);
}
.io-compare__label {
  position: absolute; top: 12px; padding: 3px 10px; border-radius: 99px;
  background: rgba(17, 16, 29, .65); color: #fff; font-size: 12px; font-weight: 600; pointer-events: none;
}
.io-compare__label--left { left: 12px; }
.io-compare__label--right { right: 12px; }
.io-compare__range {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0;
  opacity: 0; cursor: ew-resize;
}

.io-result__actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.io-result__actions .btn { flex: 1; min-width: 220px; }

/* ---------- настройки ---------- */
.io-settings .segmented button { padding: 0 4px; white-space: nowrap; font-size: 12px; }
.io-settings .is-disabled { opacity: .45; pointer-events: none; }

/* ---------- история ---------- */
.io-history { margin-top: 20px; }
.io-history__hint { font-size: 12px; }
.io-history__hint:hover { color: var(--brand); }
.io-history__grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}
.io-history__skeleton { height: 230px; border-radius: var(--radius); }
.io-history__grid .empty { grid-column: 1 / -1; }

.io-item {
  position: relative; display: flex; flex-direction: column;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  background: var(--surface); cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.io-item:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
.io-item.is-current { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.io-item__thumb {
  position: relative; aspect-ratio: 4 / 3; background: var(--surface-2);
}
.io-item__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.io-item__badge { position: absolute; left: 8px; top: 8px; }
.io-item__actions {
  position: absolute; right: 8px; top: 8px; display: flex; gap: 4px;
  opacity: 0; transition: opacity .15s;
}
.io-item:hover .io-item__actions, .io-item:focus-within .io-item__actions { opacity: 1; }
@media (hover: none) { .io-item__actions { opacity: 1; } }
.io-item__actions .btn { background: var(--surface); box-shadow: var(--shadow); }
.io-item__body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.io-item__name { font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.io-item__meta { font-size: 12px; color: var(--text-2); }
.io-item__date { font-size: 11px; color: var(--text-3); }

/* ---------- гость ---------- */
.io-guest { padding: 40px 32px; }
.io-guest__intro { max-width: 560px; margin: 0 auto; text-align: center; }
.io-guest__intro h2 { font-size: 22px; margin-bottom: 8px; }
.io-guest__icon {
  display: grid; place-items: center; width: 72px; height: 72px; margin: 0 auto 20px;
  border-radius: 20px; background: var(--brand-soft); color: var(--brand); font-size: 36px;
}
.io-guest__actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 24px; }
.io-features {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
  margin-top: 40px; padding-top: 32px; border-top: 1px solid var(--border);
}
.io-feature { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.io-feature i { font-size: 24px; color: var(--brand); }
.io-feature strong { font-size: 14px; }
@media (max-width: 800px) {
  .io-guest { padding: 28px 18px; }
  .io-features { grid-template-columns: 1fr; }
}

/* ---------- cropper под тему ---------- */
.cropper-view-box { outline-color: var(--brand); outline: 2px solid var(--brand); }
.cropper-line, .cropper-point { background-color: var(--brand); }
.cropper-point { width: 8px; height: 8px; opacity: 1; border-radius: 2px; }
.cropper-modal { background-color: #0b0c14; }
