/* ===================== Inter (self-hosted, cyrillic + latin) ===================== */
/* Cyrillic range covers Cyrillic + Cyrillic Supplement/Extended so RU renders in Inter */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/inter-cyrillic-400-normal.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/inter-latin-400-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/fonts/inter-cyrillic-500-normal.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/fonts/inter-latin-500-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/inter-cyrillic-600-normal.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/inter-latin-600-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/inter-cyrillic-700-normal.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/inter-latin-700-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #16181c;
  --bg-elev: #1e2127;
  --bg-elev-2: #262a31;
  --border: #313640;
  --text: #e6e8eb;
  --text-dim: #9aa1ab;
  --accent: #6c8cff;
  --accent-hover: #7f9bff;
  --accent-soft: rgba(108, 140, 255, .16);
  --danger: #e5645a;

  /* Font */
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  /* Radius system */
  --radius: 10px;      /* cards, fields, buttons */
  --radius-sm: 8px;    /* small blocks, tabs */
  --radius-pill: 999px;

  /* Spacing scale (4/8) */
  --gap: 16px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;

  /* Control heights */
  --control-h: 42px;
  --control-h-sm: 34px;

  /* Type scale */
  --fs-base: 15px;
  --fs-small: 12.5px;
  --fs-label: 13px;
  --fs-title: 15px;
  --lh-base: 1.55;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ---------- Buttons / fields ---------- */
.btn {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--control-h);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0 16px;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
  white-space: nowrap;
}
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--accent);
}
.btn-primary {
  background: var(--accent);
  color: #0d1016;
  font-weight: 600;
  width: 100%;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { background: var(--accent); }
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-dim); background: var(--bg-elev-2); }
.btn-ghost:active { background: var(--bg-elev); }

.field { display: block; margin-bottom: var(--gap); }
.field-label {
  display: block;
  font-size: var(--fs-label);
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 6px;
  line-height: 1.35;
}
input[type="text"], input[type="password"] {
  width: 100%;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  color: var(--text);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: var(--control-h);
  padding: 0 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input[type="text"]:focus, input[type="password"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--text-dim); opacity: .8; }

/* ---------- Login ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
}
.login-title { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.login-sub { margin: 4px 0 24px; color: var(--text-dim); font-size: 14px; }
.login-form .btn-primary { margin-top: 4px; }
.login-error { color: var(--danger); font-size: 13px; margin: 12px 0 0; text-align: center; }

/* ---------- App shell ---------- */
.app-header {
  display: flex;
  align-items: center;
  gap: var(--gap);
  flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; letter-spacing: -.01em; font-size: 17px; }
.app-header .btn-ghost { min-height: var(--control-h-sm); }
.tabs { display: flex; gap: 6px; flex: 1 1 auto; }
.tab {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  transition: background .15s, color .15s;
}
.tab:hover { color: var(--text); }
.tab:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.tab.is-active {
  color: var(--text);
  background: var(--bg-elev-2);
  border-color: var(--border);
}

.app-main { padding: 24px 16px; max-width: 960px; margin: 0 auto; }
.tab-panel { animation: fade .2s ease; }
.tab-panel:not(.is-active) { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.placeholder {
  background: var(--bg-elev);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
}
.placeholder h2 { margin: 0 0 8px; font-size: 18px; font-weight: 600; letter-spacing: -.01em; }
.placeholder p { margin: 0; color: var(--text-dim); }

/* ---------- Cards / layout ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: var(--gap);
}
.card-title { margin: 0 0 14px; font-size: var(--fs-title); font-weight: 600; letter-spacing: -.01em; }
.muted { color: var(--text-dim); }
.small { font-size: var(--fs-small); }
.card-title .muted { font-weight: 400; }

.ph-layout { display: flex; flex-direction: column; gap: 0; }
.ph-col { min-width: 0; }

select {
  width: 100%;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  color: var(--text);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: var(--control-h);
  padding: 0 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.row-inline { display: flex; gap: 8px; align-items: stretch; }
.row-inline input[type="text"] { flex: 1 1 auto; }
.row-inline .btn { white-space: nowrap; flex: 0 0 auto; }

.btn-block { width: 100%; }
.btn-sm {
  min-height: var(--control-h-sm);
  padding: 0 12px;
  font-size: 13px;
}
.btn-danger { color: var(--danger); border-color: var(--border); background: transparent; }
.btn-danger:hover { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; box-shadow: none; }

/* ---------- Chips (ракурсы / пол) ---------- */
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--control-h-sm);
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-elev-2);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  user-select: none;
  transition: border-color .15s, background .15s, color .15s;
}
.chip:hover { border-color: var(--text-dim); }
.chip input { accent-color: var(--accent); margin: 0; }
.chip:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

/* ---------- Thumbs (загруженные фото) ---------- */
.thumb-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 6px; }
.thumb { position: relative; aspect-ratio: 3 / 4; border-radius: 8px; overflow: hidden; background: var(--bg-elev-2); border: 1px solid var(--border); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-del { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; padding: 0;
  line-height: 20px; text-align: center; border: none; border-radius: 50%; cursor: pointer;
  background: rgba(0,0,0,.6); color: #fff; font-size: 16px; }
.thumb-del:hover { background: var(--danger); }

/* ---------- Результаты ---------- */
.results-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.results-head .card-title { margin: 0; }
.results-head .btn { min-height: var(--control-h-sm); font-size: 13px; }
.result-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.result-card {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.result-img { aspect-ratio: 3 / 4; border-radius: 6px; overflow: hidden; background: var(--bg); }
.result-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.result-img-empty {
  display: flex; align-items: center; justify-content: center;
  color: var(--danger); font-size: 28px;
}
.result-meta { display: flex; }
.result-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.result-actions .btn { flex: 1 1 auto; min-width: max-content; text-align: center; text-decoration: none; }
.result-error { word-break: break-word; }
.badge { font-size: 12px; padding: 3px 8px; border-radius: 6px; }
.badge-ok { background: rgba(90, 200, 130, .18); color: #7fd4a0; }
.badge-fail { background: rgba(229, 100, 90, .18); color: var(--danger); }

/* ---------- Textarea ---------- */
textarea {
  width: 100%;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 12px;
  outline: none;
  resize: vertical;
  transition: border-color .15s, box-shadow .15s;
}
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- Текст карточки ---------- */
.tx-layout { display: flex; flex-direction: column; gap: 0; }
.tx-col { min-width: 0; }

.tx-attrs { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.tx-attr-row { display: flex; gap: 8px; align-items: center; }
.tx-attr-row input { flex: 1 1 0; min-width: 0; }
.tx-attr-del { flex: 0 0 auto; }

.tx-card { display: flex; flex-direction: column; gap: 12px; }
.tx-block {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
.tx-block-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.tx-block-label { font-size: var(--fs-label); font-weight: 600; color: var(--text-dim); letter-spacing: .01em; }
.tx-block-body { white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.5; }

.tx-disclaimer {
  margin-top: 12px;
  background: rgba(230, 180, 80, .16);
  border: 1px solid rgba(230, 180, 80, .5);
  color: #e6c078;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.45;
}
.notice-ok { background: rgba(90, 200, 130, .12); border: 1px solid rgba(90, 200, 130, .4); color: #7fd4a0; }

/* ---------- Notice / плашки ---------- */
.notice { border-radius: 8px; padding: 12px 14px; margin-bottom: 12px; font-size: 14px; }
.notice code { background: rgba(0,0,0,.3); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.notice-warn { background: rgba(230, 180, 80, .14); border: 1px solid rgba(230, 180, 80, .4); color: #e6c078; }
.notice-err { background: rgba(229, 100, 90, .14); border: 1px solid rgba(229, 100, 90, .4); color: var(--danger); }

/* ---------- Найти похожие фото ---------- */
#ph-search-results { margin-top: 8px; }
.thumb-found { display: flex; flex-direction: column; gap: 6px; }
.thumb-found img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 8px; }
.thumb-cap { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb-cap a { color: var(--muted, #9aa); text-decoration: none; }
.thumb-cap a:hover { text-decoration: underline; }

/* ---------- Spinner ---------- */
.spinner-box { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 32px; grid-column: 1 / -1; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Мои модели ---------- */
.model-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.model-card {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.model-thumb { aspect-ratio: 3 / 4; border-radius: 6px; overflow: hidden; background: var(--bg); }
.model-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.model-name { font-weight: 600; word-break: break-word; }
.model-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.model-actions .btn { flex: 1 1 auto; }

/* ---------- Toast ---------- */
.toast-root {
  position: fixed; left: 0; right: 0; bottom: 16px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; z-index: 100; padding: 0 12px;
}
.toast {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  animation: toast-in .2s ease;
  max-width: 90vw;
}
.toast-ok { border-color: rgba(90, 200, 130, .5); }
.toast-err { border-color: rgba(229, 100, 90, .5); color: var(--danger); }
.toast.is-out { opacity: 0; transition: opacity .4s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (min-width: 640px) {
  .app-header { padding: 14px 24px; }
  .app-main { padding: 32px 24px; }
}

@media (min-width: 860px) {
  .ph-layout { flex-direction: row; align-items: flex-start; gap: var(--gap); }
  .ph-col-controls { flex: 0 0 340px; }
  .ph-col-results { flex: 1 1 auto; }
  .result-grid { grid-template-columns: repeat(3, 1fr); }

  .tx-layout { flex-direction: row; align-items: flex-start; gap: var(--gap); }
  .tx-col-source { flex: 0 0 380px; }
  .tx-col-result { flex: 1 1 auto; }
}

/* ---------- Мобильный (≤700px) ---------- */
@media (max-width: 700px) {
  .app-main { padding: 20px 14px; }
  .card { padding: 16px; }
  /* Ряды кнопок в карточках результатов/моделей переносятся без сдавливания */
  .result-actions .btn,
  .model-actions .btn { flex: 1 1 calc(50% - 3px); }
  /* Заголовок + кнопка в шапках карточек могут перенестись */
  .results-head { flex-wrap: wrap; }
  .tx-block-head { flex-wrap: wrap; }
}
