/* ПРОМТЫ — тёмный минимализм, монохром с одним акцентом */

:root {
  --bg: #0d0d0f;
  --bg-2: #16161a;
  --bg-3: #1e1e24;
  --line: #2a2a32;
  --text: #ece9e4;
  --muted: #8b8b96;
  --accent: #d8c9a3;      /* тёплый песочный — акцент PT */
  --accent-dim: #6b6250;
  --danger: #d97066;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin-top: 4px; }

button, input, textarea, select { font-family: inherit; font-size: 16px; color: inherit; }

/* ---------- Вход ---------- */

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-box {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.gate-mark {
  width: 64px; height: 64px;
  margin: 0 auto 8px;
  border: 1px solid var(--accent-dim);
  border-radius: 50%;
  display: grid; place-items: center;
  font-family: Didot, "Bodoni 72", Georgia, serif;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--accent);
}

.gate h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 6px;
  font-weight: 500;
}

.gate p { margin: 0 0 12px; font-size: 14px; }

input, textarea, select {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  width: 100%;
  outline: none;
}

input:focus, textarea:focus, select:focus { border-color: var(--accent-dim); }

textarea { resize: vertical; min-height: 90px; font-family: var(--mono); font-size: 14px; line-height: 1.5; }

.btn {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 16px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #26262e; }
.btn.primary { background: var(--accent); color: #16140f; border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: #e6d8b6; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #4a2b28; }
.btn:disabled { opacity: .45; cursor: default; }

.icon-btn {
  background: none; border: none; color: var(--muted);
  font-size: 20px; cursor: pointer; padding: 6px 10px; border-radius: 8px;
}
.icon-btn:hover { color: var(--text); background: var(--bg-2); }

/* ---------- Шапка ---------- */

.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  background: rgba(13,13,15,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: Didot, "Bodoni 72", Georgia, serif;
  font-weight: 700;
  letter-spacing: 3px;
  font-size: 15px;
  color: var(--accent);
}

.tabs { display: flex; gap: 4px; margin-left: auto; }

.tab {
  background: none; border: none; color: var(--muted);
  padding: 7px 14px; border-radius: 999px; cursor: pointer; font-size: 14px;
}
.tab.active { background: var(--bg-3); color: var(--text); }

/* ---------- База ---------- */

.view { padding: 16px 16px 120px; max-width: 1400px; margin: 0 auto; }

.search-row { margin-bottom: 12px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; margin-bottom: 14px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 13px; font-size: 13px;
  color: var(--muted); cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--accent); color: #16140f; border-color: var(--accent); font-weight: 600; }
.chip .n { opacity: .6; margin-left: 5px; font-size: 11px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}

.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  display: flex; flex-direction: column;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent-dim); transform: translateY(-2px); }

.card-cover { aspect-ratio: 4 / 3; background: var(--bg-3); overflow: hidden; position: relative; }
.card-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-cover.none { display: grid; place-items: center; color: var(--line); font-size: 30px; }

.card-body { padding: 12px 13px 13px; display: flex; flex-direction: column; gap: 7px; flex: 1; }
.card-title { font-size: 14px; font-weight: 600; line-height: 1.3; }
.card-snippet {
  font-family: var(--mono); font-size: 11.5px; color: var(--muted);
  line-height: 1.45; max-height: 51px; overflow: hidden;
}
.card-meta { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; margin-top: auto; padding-top: 4px; font-size: 11px; color: var(--muted); }
.badge { background: var(--bg-3); border-radius: 5px; padding: 2px 7px; }
.badge.inbox { background: #3a3320; color: var(--accent); }
.stars { color: var(--accent); letter-spacing: 1px; }
.fav-mark { color: var(--accent); }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; font-size: 15px; }

.fab {
  position: fixed;
  right: 20px; bottom: calc(20px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #16140f;
  border: none; font-size: 30px; line-height: 1;
  cursor: pointer; z-index: 30;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
}

/* ---------- Модалка ---------- */

.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.72); backdrop-filter: blur(4px); }
.modal-box {
  position: relative;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  width: min(720px, 100%);
  max-height: 88dvh;
  overflow-y: auto;
  padding: 20px;
  -webkit-overflow-scrolling: touch;
}

.modal-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.modal-head h2 { margin: 0; font-size: 19px; font-weight: 600; line-height: 1.25; flex: 1; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; letter-spacing: .5px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.prompt-box {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; font-family: var(--mono); font-size: 13px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word; max-height: 300px; overflow-y: auto;
}

.tag-list { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { background: var(--bg-3); border-radius: 6px; padding: 3px 9px; font-size: 12px; color: var(--muted); }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.gallery figure { margin: 0; position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--bg-3); }
.gallery img, .gallery video { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery .del {
  position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%;
  background: rgba(0,0,0,.7); border: none; color: #fff; cursor: pointer; font-size: 14px; line-height: 1;
}
.gallery figure .role { position: absolute; bottom: 0; left: 0; right: 0; font-size: 10px; text-align: center; background: rgba(0,0,0,.6); padding: 2px; color: var(--muted); }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.actions .spacer { flex: 1; }

.seg { display: flex; gap: 6px; margin-bottom: 16px; }
.seg button { flex: 1; background: var(--bg-3); border: 1px solid var(--line); border-radius: 9px; padding: 9px; cursor: pointer; color: var(--muted); font-size: 14px; }
.seg button.on { background: var(--accent); color: #16140f; border-color: var(--accent); font-weight: 600; }

.rating-pick { display: flex; gap: 6px; }
.rating-pick button { background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer; color: var(--muted); font-size: 13px; }
.rating-pick button.on { background: var(--accent); color: #16140f; border-color: var(--accent); }

.drop {
  border: 1px dashed var(--line); border-radius: 12px; padding: 22px; text-align: center;
  color: var(--muted); cursor: pointer; font-size: 14px;
}
.drop:hover { border-color: var(--accent-dim); color: var(--text); }

.thinking { display: flex; align-items: center; gap: 10px; color: var(--accent); font-size: 14px; padding: 10px 0; }
.spinner {
  width: 15px; height: 15px; border: 2px solid var(--accent-dim); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Схемы: список ---------- */

.flows-head { margin-bottom: 16px; }
.flow-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.flow-card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; cursor: pointer; transition: border-color .15s;
}
.flow-card:hover { border-color: var(--accent-dim); }
.flow-card h3 { margin: 0 0 6px; font-size: 15px; font-weight: 600; }
.flow-card .meta { font-size: 12px; color: var(--muted); }

/* ---------- Холст ---------- */

.canvas-screen { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: flex; flex-direction: column; }

.canvas-top {
  display: flex; align-items: center; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  border-bottom: 1px solid var(--line); background: var(--bg-2);
}
.flow-title { flex: 1; background: none; border: none; font-size: 16px; font-weight: 600; padding: 6px 8px; }
.flow-title:focus { background: var(--bg-3); border-radius: 8px; }
.saved { font-size: 11px; color: var(--muted); opacity: 0; transition: opacity .3s; }
.saved.show { opacity: 1; }

.canvas-wrap {
  flex: 1; position: relative; overflow: hidden;
  background-image: radial-gradient(circle, #26262e 1px, transparent 1px);
  background-size: 26px 26px;
  touch-action: none;
  cursor: grab;
}
.canvas-wrap.panning { cursor: grabbing; }

.edges { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.edges path { fill: none; stroke: var(--accent-dim); stroke-width: 2; }
.edges path.hot { stroke: var(--accent); }
.edges .hit { stroke: transparent; stroke-width: 16; pointer-events: stroke; cursor: pointer; }

.canvas { position: absolute; top: 0; left: 0; transform-origin: 0 0; }

.node {
  position: absolute;
  width: 230px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  user-select: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.35);
}
.node.sel { border-color: var(--accent); }

.node-head {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 10px; background: var(--bg-3);
  font-size: 11px; color: var(--muted); letter-spacing: .5px;
  cursor: move;
}
.node-head .grow { flex: 1; }
.node-head button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px 4px; }
.node-head button:hover { color: var(--text); }

.node-body { padding: 10px; font-size: 12.5px; }
.node-body .ph { color: var(--muted); font-size: 12px; }
.node-body img, .node-body video { width: 100%; border-radius: 7px; display: block; max-height: 190px; object-fit: cover; }
.node-text {
  font-family: var(--mono); font-size: 11px; line-height: 1.5; color: var(--text);
  max-height: 130px; overflow: hidden; white-space: pre-wrap; word-break: break-word;
}
.node-note { font-size: 12.5px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.node-actions { display: flex; gap: 6px; padding: 0 10px 10px; }
.node-actions button {
  flex: 1; background: var(--bg-3); border: 1px solid var(--line); border-radius: 7px;
  padding: 5px; font-size: 11px; color: var(--muted); cursor: pointer;
}
.node-actions button:hover { color: var(--text); border-color: var(--accent-dim); }

.port {
  position: absolute; top: 50%; width: 15px; height: 15px; margin-top: -7px;
  border-radius: 50%; background: var(--bg-3); border: 2px solid var(--accent-dim);
  cursor: crosshair; z-index: 2;
}
.port:hover, .port.armed { background: var(--accent); border-color: var(--accent); }
.port.out { right: -8px; }
.port.in { left: -8px; }

.canvas-tools {
  display: flex; gap: 6px; align-items: center; overflow-x: auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--bg-2);
  scrollbar-width: none;
}
.canvas-tools::-webkit-scrollbar { display: none; }
.tool {
  flex: none; background: var(--bg-3); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 13px; font-size: 13px; color: var(--text); cursor: pointer;
}
.tool:hover { border-color: var(--accent-dim); }
.tool-sep { flex: 1; min-width: 8px; }

.hint-line { font-size: 12px; color: var(--muted); padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--bg-2); }

/* ---------- Перетаскивание файла в окно ---------- */

body.dragging::after {
  content: 'Отпусти - разберу скриншот';
  position: fixed; inset: 14px;
  border: 2px dashed var(--accent);
  border-radius: 20px;
  background: rgba(13,13,15,.86);
  display: grid; place-items: center;
  font-size: 19px; color: var(--accent); letter-spacing: 1px;
  z-index: 300; pointer-events: none;
}

/* ---------- Тост ---------- */

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(28px + env(safe-area-inset-bottom));
  background: var(--accent); color: #16140f;
  padding: 11px 20px; border-radius: 999px; font-size: 14px; font-weight: 600;
  z-index: 200; box-shadow: 0 6px 22px rgba(0,0,0,.5);
}

/* ---------- Телефон ---------- */

@media (max-width: 620px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .view { padding: 12px 12px 110px; }
  .modal { padding: 0; align-items: flex-end; }
  .modal-box { border-radius: 18px 18px 0 0; max-height: 92dvh; width: 100%; padding: 18px 16px calc(20px + env(safe-area-inset-bottom)); }
  .card-snippet { max-height: 34px; }
  .node { width: 200px; }
  .field-row { flex-direction: column; gap: 0; }
}
