/* Tcompiler GUI. Copyright 2025 AN602 Ltd. Licensed under the Apache License 2.0. */

:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --text: #16182b;
  --muted: #5d6178;
  --border: #d9dce8;
  --brand: #20247a;
  --brand-hover: #2c3196;
  --brand-soft: #e6e7f6;
  --on-brand: #ffffff;
  --ok: #1d7a46;
  --ok-soft: #e1f3e8;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --err: #b3261e;
  --err-soft: #fbe5e3;
  --log-bg: #11131f;
  --log-text: #d7daea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 22, 50, 0.06), 0 4px 16px rgba(20, 22, 50, 0.05);
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101220;
    --surface: #181b2d;
    --surface-2: #20243a;
    --text: #e6e8f4;
    --muted: #a1a6c0;
    --border: #2e3350;
    --brand: #8f95ff;
    --brand-hover: #a7acff;
    --brand-soft: #262a4d;
    --on-brand: #0e1020;
    --ok: #62c98b;
    --ok-soft: #173325;
    --warn: #f0c060;
    --warn-soft: #3a2f14;
    --err: #ff8a80;
    --err-soft: #3d1c1a;
    --log-bg: #0a0b14;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}

button, input, select { font: inherit; color: inherit; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 6px; }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: 0.2px; }
.brand-sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.env-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  cursor: pointer;
  font-size: 13px;
  max-width: 360px;
}
.env-chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.err { background: var(--err); }

.lang-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.lang-switch button { border: 0; background: transparent; padding: 5px 10px; cursor: pointer; font-size: 13px; }
.lang-switch button[aria-pressed="true"] { background: var(--brand); color: var(--on-brand); }

.env-panel {
  margin: 16px 24px 0;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.env-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px 24px; }
.env-item { display: flex; flex-direction: column; }
.env-item .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
.env-item .v { font-weight: 500; word-break: break-word; }
.env-error { margin-top: 12px; }
.env-error p:first-child { color: var(--err); font-weight: 600; margin: 0 0 4px; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 20px;
  padding: 20px 24px 40px;
  max-width: 1400px;
  margin: 0 auto;
}
@media (max-width: 980px) { .layout { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  min-width: 0;
}
.card h1 { font-size: 20px; margin: 0 0 12px; }
.card h2 { font-size: 18px; margin: 0 0 12px; }
.card h3 { font-size: 14px; margin: 14px 0 4px; }

.step { border: 0; padding: 0; margin: 0 0 22px; min-width: 0; }
.step legend { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; margin-bottom: 10px; padding: 0; }
.step-num {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 13px;
  font-weight: 700;
}

.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 110px;
  padding: 18px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--brand); background: var(--brand-soft); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone:focus-within { outline: 2px solid var(--brand); outline-offset: 2px; }
.dropzone-title { font-weight: 600; }
.dropzone-hint { color: var(--muted); font-size: 13px; }

.file-info { margin-top: 12px; }
.file-row { display: flex; justify-content: space-between; gap: 12px; font-weight: 600; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: var(--muted); font-weight: 400; flex: none; }

.field { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.field.inline { flex-direction: row; align-items: center; gap: 10px; }
.field > span { font-size: 13px; color: var(--muted); }
input[type="text"], select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.field.inline select { width: auto; }
input[type="text"]:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
input.invalid { border-color: var(--err); outline-color: var(--err); }

.inputs-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.inputs-table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 4px 6px; border-bottom: 1px solid var(--border); }
.inputs-table td { padding: 5px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.inputs-table td:first-child { font-family: var(--mono); font-size: 13px; word-break: break-all; }
.inputs-table td:last-child { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.inputs-table input { font-family: var(--mono); font-size: 13px; }

.target-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.target-group { grid-column: 1 / -1; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; margin-top: 6px; }
.target-option { position: relative; }
.target-option input { position: absolute; opacity: 0; }
.target-option label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  height: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  background: var(--surface);
  transition: border-color 0.15s, background 0.15s;
}
.target-option label:hover { border-color: var(--brand); }
.target-option input:checked + label { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }
.target-option input:focus-visible + label { outline: 2px solid var(--brand); outline-offset: 2px; }
.target-title { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.target-desc { color: var(--muted); font-size: 12px; font-family: var(--mono); word-break: break-all; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 500; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }

.segmented { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: block; padding: 7px 14px; cursor: pointer; font-size: 14px; }
.segmented input:checked + span { background: var(--brand); color: var(--on-brand); }
.segmented input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: -2px; }

.check { display: flex; align-items: flex-start; gap: 8px; margin-top: 10px; font-size: 14px; }
.check input { margin-top: 3px; accent-color: var(--brand); }
.check.disabled { color: var(--muted); }

.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.notice { font-size: 14px; padding: 8px 12px; border-radius: 8px; background: var(--surface-2); margin: 10px 0 0; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.err { background: var(--err-soft); color: var(--err); }

.actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
button.primary {
  padding: 10px 22px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: var(--on-brand);
  font-weight: 600;
  cursor: pointer;
}
button.primary:hover:not(:disabled) { background: var(--brand-hover); }
button.primary:disabled { opacity: 0.45; cursor: not-allowed; }
button.secondary {
  padding: 6px 12px;
  border: 1px solid var(--brand);
  border-radius: 8px;
  background: transparent;
  color: var(--brand);
  cursor: pointer;
  font-size: 14px;
}
button.secondary:hover { background: var(--brand-soft); }
.link-button { border: 0; background: none; color: var(--brand); cursor: pointer; padding: 4px 2px; font-size: 14px; }
.link-button:hover { text-decoration: underline; }
.icon-button { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }

.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.progress-bar { height: 100%; width: 0; background: var(--brand); transition: width 0.3s; }

.empty { color: var(--muted); }
.jobs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.job { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; background: var(--surface); }
.job-head { display: flex; align-items: center; gap: 10px; }
.job-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-meta { color: var(--muted); font-size: 13px; margin-top: 2px; word-break: break-word; }
.status-badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 600; flex: none; }
.status-badge.running, .status-badge.queued { background: var(--brand-soft); color: var(--brand); }
.status-badge.succeeded { background: var(--ok-soft); color: var(--ok); }
.status-badge.failed { background: var(--err-soft); color: var(--err); }
.job.done .progress { display: none; }
.job-error { color: var(--err); font-size: 14px; margin: 8px 0 0; white-space: pre-wrap; word-break: break-word; }
.job-result { font-size: 14px; margin-top: 8px; display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; }
.job-result .k { color: var(--muted); }
.job-result .v { word-break: break-word; }
.job-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }

.log {
  background: var(--log-bg);
  color: var(--log-text);
  font: 12px/1.45 var(--mono);
  padding: 10px 12px;
  border-radius: 8px;
  max-height: 300px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 10px 0 0;
}

.ir-dialog {
  width: min(1100px, 94vw);
  height: min(85vh, 900px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
.ir-dialog[open] { display: flex; flex-direction: column; }
.ir-dialog::backdrop { background: rgba(10, 12, 30, 0.55); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { margin: 0; font-size: 16px; }
.ir-text { flex: 1; margin: 0; padding: 14px 18px; overflow: auto; font: 12.5px/1.5 var(--mono); background: var(--surface-2); white-space: pre; }

@media (max-width: 640px) {
  .topbar { padding: 10px 14px; flex-wrap: wrap; }
  .brand-sub { display: none; }
  .layout { padding: 14px; }
  .env-panel { margin: 12px 14px 0; }
}

/* ---------------------------------------------------------- демонстрационный стенд */
.demo-models { margin-bottom: 12px; }
.demo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.demo-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.demo-card.selected { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); background: var(--brand-soft); }
.demo-title { font-weight: 600; }
.demo-desc { font-size: 13px; color: var(--muted); }
.demo-src { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.demo-card button { align-self: flex-start; margin-top: auto; }
.or-line { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 12px 0 8px; }
.or-line::before, .or-line::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
button.small { padding: 6px 14px; font-size: 14px; }
button.secondary:disabled { opacity: 0.45; cursor: not-allowed; }

.bench { margin-top: 10px; display: flex; flex-direction: column; gap: 10px; }
.bench-head { font-size: 13px; color: var(--muted); }
.bench-row { display: grid; grid-template-columns: 1fr; gap: 3px; }
.bench-name { font-size: 14px; font-weight: 600; }
.bench-track { position: relative; display: flex; align-items: center; gap: 8px; }
.bench-bar { height: 16px; border-radius: 4px; background: var(--brand); min-width: 4px; transition: width 0.4s; }
.bench-row.ort .bench-bar { background: var(--muted); }
.bench-row.baseline .bench-bar { background: var(--warn); }
.bench-row.tuned .bench-bar { background: var(--ok); }
.bench-value { font: 600 13px var(--mono); white-space: nowrap; }
.bench-note { font-size: 12px; color: var(--muted); }

.predict { margin-top: 10px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.thumb {
  position: relative;
  width: 84px;
  height: 84px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: var(--surface-2);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb:hover { border-color: var(--brand); }
.thumb.own { display: grid; place-items: center; font-size: 12px; color: var(--brand); text-align: center; padding: 4px; }
.thumb.own input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.predict-out { display: grid; grid-template-columns: 140px 1fr; gap: 14px; margin-top: 12px; align-items: start; }
.predict-img { width: 140px; height: 140px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.predict-list { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.pred-name { font-weight: 600; }
.pred-en { font-weight: 400; color: var(--muted); font-size: 12px; }
.pred-track { display: flex; align-items: center; gap: 8px; }
.pred-bar { height: 10px; border-radius: 3px; background: var(--brand); }
.pred-row:first-child .pred-bar { background: var(--ok); }
.pred-value { font: 12px var(--mono); color: var(--muted); }
@media (max-width: 640px) { .predict-out { grid-template-columns: 1fr; } }
.step-hint { margin: 0 0 10px; }
.demo-card { cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.demo-card:hover { border-color: var(--brand); }
.demo-card.selected { cursor: default; }
.demo-facts { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0 4px; }
.bench-row.tuned .bench-note { color: var(--ok); font-weight: 600; }
