/* ===================== Темы ===================== */
:root {
  /* тёмная (по умолчанию) */
  --bg: #0b0f17;
  --bg2: #0f1420;
  --card: #151b28;
  --card2: #10151f;
  --border: #232c40;
  --text: #e6eaf2;
  --muted: #8b93a7;
  --accent: #3b82f6;
  --accent-h: #2563eb;
  --accent-soft: rgba(59, 130, 246, .16);
  --green: #34d399;
  --red: #f87171;
  --amber: #f59e0b;
  --topbar: rgba(11, 15, 23, .82);
  --shadow: 0 30px 80px rgba(0, 0, 0, .45);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --radius: 14px;

  --space: 22px;   /* базовый отступ */
  --gap: 20px;     /* промежуток между блоками */
}

/* светлая при системной настройке (если пользователь не выбрал вручную) */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #eef1f7;
    --bg2: #e7ebf3;
    --card: #ffffff;
    --card2: #f4f6fb;
    --border: #e3e8f0;
    --text: #14202e;
    --muted: #64748b;
    --accent-soft: rgba(59, 130, 246, .1);
    --green: #059669;
    --red: #dc2626;
    --topbar: rgba(255, 255, 255, .8);
    --shadow: 0 24px 60px rgba(15, 23, 42, .14);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  }
}

/* светлая — выбрана вручную */
:root[data-theme="light"] {
  --bg: #eef1f7;
  --bg2: #e7ebf3;
  --card: #ffffff;
  --card2: #f4f6fb;
  --border: #e3e8f0;
  --text: #14202e;
  --muted: #64748b;
  --accent-soft: rgba(59, 130, 246, .1);
  --green: #059669;
  --red: #dc2626;
  --topbar: rgba(255, 255, 255, .8);
  --shadow: 0 24px 60px rgba(15, 23, 42, .14);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
}

/* ===================== База ===================== */
* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  transition: background-color .2s ease, color .2s ease;
}

h1, h2 { font-weight: 650; letter-spacing: .2px; }
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- поля / кнопки ---------- */
input, textarea, button { font: inherit; color: var(--text); }
input[type="text"], input[type="password"], input[type="number"], input:not([type]), textarea {
  width: 100%;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background-color .2s;
}
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; }
input[type="file"] {
  width: 100%; padding: 9px; background: var(--card2);
  border: 1px dashed var(--border); border-radius: 10px; margin-bottom: 8px;
}

button {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 11px 18px;
  background: var(--card);
  transition: background .15s, border-color .15s, opacity .15s, transform .05s;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-h); border-color: var(--accent-h); }
button.ghost { background: transparent; border-color: var(--border); color: var(--text); }
button.ghost:hover { border-color: var(--accent); }
button.block { width: 100%; }
button.big { padding: 15px 30px; font-size: 16px; }

/* переключатель темы */
.theme-btn {
  width: 40px; height: 40px; border-radius: 11px;
  background: transparent; border: 1px solid var(--border);
  font-size: 18px; line-height: 1; display: grid; place-items: center;
}
.theme-btn:hover { border-color: var(--accent); }
.theme-fixed { position: fixed; top: 20px; right: 20px; z-index: 10; background: var(--card); box-shadow: var(--shadow-sm); }

/* ===================== Вход ===================== */
.login-body {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1100px 520px at 18% -12%, rgba(59, 130, 246, .18), transparent 60%),
    radial-gradient(900px 520px at 112% 112%, rgba(139, 92, 246, .15), transparent 55%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 400px;
  background: linear-gradient(180deg, var(--card), var(--card2));
  border: 1px solid var(--border); border-radius: 20px;
  padding: 40px 34px 30px; box-shadow: var(--shadow); text-align: center;
}
.login-logo {
  width: 60px; height: 60px; margin: 0 auto 16px;
  display: grid; place-items: center; font-size: 28px; color: #fff;
  border-radius: 17px; background: linear-gradient(135deg, var(--accent), #8b5cf6);
  box-shadow: 0 12px 34px rgba(59, 130, 246, .42);
}
.login-card h1 { margin: 6px 0 2px; font-size: 23px; }
.login-card .field { text-align: left; margin: 18px 0 0; display: block; }
.login-card .field span { display: block; margin-bottom: 7px; font-size: 13px; color: var(--muted); }
.login-card .primary { margin-top: 24px; }
.dev-note { margin-top: 20px; }
.alert {
  margin-top: 18px; padding: 11px 13px; border-radius: 10px;
  background: rgba(248, 113, 113, .12); border: 1px solid rgba(248, 113, 113, .4);
  color: #ef8f8f; font-size: 14px;
}

/* ===================== Приложение ===================== */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px;
  background: var(--topbar); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; letter-spacing: .3px; font-size: 16px; }
.user { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.uname { color: var(--muted); }
.logout { color: var(--muted); }
.logout:hover { color: var(--red); }

.nav { display: flex; gap: 6px; }
.nav-item {
  background: transparent; border: none; color: var(--muted);
  padding: 8px 16px; border-radius: 9px; font-size: 14px; font-weight: 500;
}
.nav-item:hover { color: var(--text); background: var(--card2); }
.nav-item.active { color: var(--text); background: var(--accent-soft); }

.container { max-width: 1440px; margin: 0 auto; padding: 32px 28px 80px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 26px;
  margin-bottom: var(--gap);
  transition: background-color .2s, border-color .2s;
}
.card h2 { margin: 0 0 20px; font-size: 17px; }
.field { margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }
.field > label { display: block; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; }
.row > input { flex: 1; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
.check { display: flex; align-items: center; gap: 9px; font-size: 14px; cursor: pointer; margin-top: 16px; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }

.actions { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.status-wrap { flex: 1; min-width: 240px; }
.progress { height: 6px; background: var(--card2); border-radius: 999px; overflow: hidden; margin-bottom: 8px; }
.progress .bar {
  height: 100%; width: 40%; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #8b5cf6);
  animation: slide 1.1s ease-in-out infinite;
}
@keyframes slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }

/* ---------- результаты ---------- */
.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.tcard {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column;
  box-shadow: var(--shadow-sm);
}
.tcard .thumb {
  aspect-ratio: 4 / 3; background: var(--card2);
  display: grid; place-items: center; color: var(--muted); font-size: 13px; text-align: center; padding: 10px;
}
.tcard .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tcard .thumb.zoom { cursor: zoom-in; }
.tcard .body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 7px; }
.tcard .headline { font-weight: 650; font-size: 15px; }
.tcard .count { font-size: 13px; }
.tcard .count.ok { color: var(--green); }
.tcard .count.over { color: var(--red); }
.tcard .why { font-size: 13px; color: var(--muted); }
.tcard .btns { display: flex; gap: 8px; margin-top: 8px; }
.tcard .btns button, .tcard .btns a { flex: 1; text-align: center; font-size: 13px; padding: 9px; }
.tcard .btns a.disabled { pointer-events: none; opacity: .5; }

/* ---------- примеры тизеров: два списка ---------- */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; }
.two-col .col > label { display: block; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.two-col textarea { min-height: 240px; }

.image-list {
  display: flex; flex-direction: column; gap: 7px;
  min-height: 160px;
  border: 1px dashed var(--border); border-radius: 12px; padding: 10px;
}
.img-empty { color: var(--muted); font-size: 13px; padding: 40px 10px; text-align: center; }
.img-item {
  display: flex; align-items: center; gap: 9px;
  background: var(--card2); border: 1px solid var(--border);
  border-radius: 9px; padding: 8px 10px;
}
.img-item.dragging { opacity: .45; }
.img-item .drag { color: var(--muted); cursor: grab; user-select: none; }
.img-item .num { color: var(--muted); font-size: 12px; width: 16px; text-align: right; }
.img-item .thumb2 { width: 46px; height: 34px; display: grid; place-items: center; flex: 0 0 auto; color: var(--muted); }
.img-item .thumb2 img { width: 46px; height: 34px; object-fit: cover; border-radius: 5px; display: block; }
.img-item.img-bad { border-color: var(--amber); }
.img-item.img-bad .thumb2 { color: var(--amber); font-size: 18px; }
.img-item .iname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.img-item .x { background: transparent; border: none; color: var(--muted); padding: 2px 6px; }
.img-item .x:hover { color: var(--red); }
.img-actions { display: flex; gap: 8px; margin-top: 10px; }
.link-panel { margin-top: 10px; }
.link-panel .row { margin-top: 8px; gap: 8px; }

.pair-status { margin-top: 18px; display: flex; flex-direction: column; gap: 3px; }
.pair-warn { color: var(--amber); font-size: 13px; margin-bottom: 6px; }
.pair-ok { color: var(--green); font-size: 13px; margin-bottom: 6px; }
.pair {
  display: grid; grid-template-columns: 26px minmax(0, 1fr) 20px minmax(0, 1fr);
  gap: 10px; align-items: center; font-size: 13px; padding: 4px 0;
  border-top: 1px solid var(--border);
}
.pair .pn { color: var(--muted); }
.pair .pa { text-align: center; color: var(--muted); }
.pair .pi, .pair .pt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pair .miss { color: var(--amber); }

/* подсказка под кнопкой генерации */
#ready_hint:not(:empty) { color: var(--amber); margin-top: 6px; }

/* ---------- история (ранее сгенерированное) ---------- */
.hist-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.hist-head h2 { margin: 0; }
.hist-tools { display: flex; align-items: center; gap: 10px; }
.hist-tools input { width: 260px; max-width: 60vw; }
.history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; margin-top: 14px; }
.hist-group { margin-top: 24px; }
.hist-group:first-child { margin-top: 6px; }
.hist-task {
  margin: 0 0 12px; font-size: 15px; font-weight: 650;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.hist-group .history-grid { margin-top: 0; }

/* ---------- селекты ---------- */
select {
  width: 100%; background: var(--card2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; outline: none; color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.row > select { flex: 1; }

/* ---------- под-вкладки истории ---------- */
.subnav { display: flex; gap: 4px; background: var(--card2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.subnav-item { background: transparent; border: none; color: var(--muted); padding: 7px 16px; border-radius: 8px; font-size: 14px; }
.subnav-item:hover { color: var(--text); }
.subnav-item.active { background: var(--accent); color: #fff; }
.more-wrap { text-align: center; margin-top: 20px; }

/* ---------- заголовок задачи ---------- */
.task-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin: 22px 0 12px; padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.hist-group:first-child .task-head { margin-top: 4px; }
.task-title { font-weight: 650; font-size: 15px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.task-folder { font-size: 12px; color: var(--muted); font-weight: 400; }
.task-actions { display: flex; gap: 8px; }
.task-actions .ghost { font-size: 13px; padding: 7px 12px; }
.ghost.danger { color: var(--red); }
.ghost.danger:hover { border-color: var(--red); }

/* ---------- дерево папок ---------- */
.tree-row { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.tree-row:hover { background: var(--card2); }
.tree-caret { width: 14px; color: var(--muted); font-size: 11px; }
.tree-children { margin-left: 22px; border-left: 1px solid var(--border); padding-left: 6px; }
.tree-sub.active { background: var(--accent-soft); }
.tree-add { margin: 4px 0 6px 8px; font-size: 12px; padding: 5px 10px; }
.tree-tasks-title { margin: 24px 0 4px; font-size: 15px; }
#tree-tasks { margin-top: 8px; }

/* ---------- модалки ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .72); display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal.hidden { display: none; }
#img_modal { cursor: zoom-out; }
#img_modal img { max-width: 96vw; max-height: 92vh; border-radius: 8px; box-shadow: 0 20px 60px rgba(0, 0, 0, .6); }
.modal-box { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 22px 24px; width: 100%; max-width: 420px; box-shadow: var(--shadow); }
.modal-box h3 { margin: 0 0 16px; font-size: 16px; }
.modal-msg { font-size: 14.5px; color: var(--text); line-height: 1.55; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.modal-box .btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.modal-box .btn-danger:hover:not(:disabled) { filter: brightness(1.07); }

/* появление модалок (для ui-modal, создаваемых из JS) */
.ui-modal { opacity: 0; transition: opacity .18s ease; }
.ui-modal.show { opacity: 1; }
.ui-modal .modal-box { transform: translateY(10px) scale(.98); transition: transform .18s ease; }
.ui-modal.show .modal-box { transform: none; }

/* ---------- тосты ---------- */
.toast-wrap {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: 10px; align-items: center;
  pointer-events: none; width: max-content; max-width: 92vw;
}
.toast {
  pointer-events: auto;
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 11px; padding: 12px 18px; font-size: 14px; text-align: center;
  box-shadow: var(--shadow);
  opacity: 0; transform: translateY(-10px);
  transition: opacity .22s ease, transform .22s ease;
}
.toast.show { opacity: 1; transform: none; }
.toast-error { border-left-color: var(--red); }
.toast-info { border-left-color: var(--green); }

@media (max-width: 820px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .container { padding: 22px 18px 60px; }
  .topbar { padding: 12px 18px; }
}
