:root {
  --bg: #f3f6f6;
  --surface: #ffffff;
  --surface-alt: #edf5f4;
  --border: #dde5e4;
  --text: #17181a;
  --text-muted: #6b7280;
  --accent: #0ABAB5;
  --accent-hover: #099b97;
  --accent-soft: #e2f7f6;
  --success: #16a34a;
  --success-soft: #ecfdf3;
  --error: #dc2626;
  --error-soft: #fef2f2;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --accent-text: #17332f;
}

:root[data-theme="dark"] {
  --bg: #1c1c1f;
  --surface: #26262a;
  --surface-alt: #2e2e33;
  --border: #3c3c40;
  --text: #f5f5f6;
  --text-muted: #9b9b9e;
  --accent: #0ABAB5;
  --accent-hover: #2fd4cf;
  --accent-soft: rgba(10, 186, 181, 0.14);
  --success: #22c55e;
  --success-soft: #16281c;
  --error: #f87171;
  --error-soft: #2c1a1c;
  --warn: #fbbf24;
  --warn-soft: #2b2415;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 6px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }

.app { display: flex; flex-direction: column; min-height: 100vh; }
.app.login-page { align-items: center; justify-content: center; }
.app.login-page main.content { padding: 0; max-width: none; width: auto; margin: 0; flex: none; }

.topbar {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 14px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 800; font-size: 18px; letter-spacing: 0.2px; }
.topbar nav { display: flex; gap: 18px; flex: 1; }
.topbar nav a { font-size: 14px; color: var(--text-muted); padding: 6px 2px; border-bottom: 2px solid transparent; }
.topbar nav a.active, .topbar nav a:hover { color: var(--text); border-bottom-color: var(--accent); }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.linklike { background: none; border: none; color: var(--text-muted); cursor: pointer; font: inherit; padding: 0; }
.linklike:hover { color: var(--text); }

main.content { flex: 1; padding: 32px 40px; max-width: 1080px; width: 100%; margin: 0 auto; }
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; gap: 12px; padding: 12px 16px; }
  main.content { padding: 20px; }
}

h1 { font-size: 24px; margin: 0 0 4px; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 14px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.muted { color: var(--text-muted); }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 20px;
}
.panel.narrow { max-width: 560px; }

.grid-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); font-weight: 500; }
.stack { display: flex; flex-direction: column; gap: 16px; }

input, select, textarea, button {
  font: inherit;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 90px; resize: vertical; font-family: inherit; }

button, a.button {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  transition: background 0.12s ease;
}
button:hover, a.button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.secondary, a.button.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
button.secondary:hover, a.button.secondary:hover { background: var(--surface-alt); }
button.small, a.button.small { padding: 7px 12px; font-size: 13px; }
button:disabled { opacity: 0.6; cursor: default; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-alt);
  color: var(--text-muted);
}
.badge-generated { background: var(--success-soft); color: var(--success); }
.badge-error { background: var(--error-soft); color: var(--error); }
.badge-draft { background: var(--warn-soft); color: var(--warn); }
.badge-generating { background: var(--warn-soft); color: var(--warn); }

.generating-panel { display: flex; gap: 14px; align-items: center; }
.spinner { flex: 0 0 22px; width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--warn-soft); border-top-color: var(--warn); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.flashes { margin-bottom: 18px; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 12px 16px; border-radius: 10px; font-size: 14px; }
.flash-success { background: var(--success-soft); color: var(--success); }
.flash-error { background: var(--error-soft); color: var(--error); }

.center-box {
  width: 100%;
  max-width: 340px;
  padding: 36px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.center-box h1 { text-align: center; margin-bottom: 4px; }

.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.project-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  min-height: 140px;
}
.project-card:hover { border-color: var(--accent); }
.project-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.project-card-title { font-weight: 600; font-size: 15px; }
.project-card-brief { font-size: 13px; line-height: 1.4; margin: 0; }

.preview-frame { width: 100%; height: 70vh; min-height: 480px; border: none; display: block; background: #fff; }

/* ---------- конструктор ---------- */

.badge-builder { background: var(--accent-soft); color: var(--text); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.niche-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.niche-card { position: relative; flex-direction: column; gap: 4px; padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; color: var(--text); transition: border-color .15s, box-shadow .15s; }
.niche-card:hover { border-color: var(--accent); }
.niche-card:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.niche-card input { position: absolute; opacity: 0; pointer-events: none; }
.niche-name { font-size: 16px; font-weight: 700; }
.niche-meta { font-size: 13px; font-weight: 400; }
.niche-swatch { width: 28px; height: 6px; border-radius: 3px; margin-top: 10px; }

main.content.content-wide { max-width: none; padding: 0; display: flex; }
.editor { display: grid; grid-template-columns: minmax(340px, 420px) 1fr; flex: 1; min-height: 0; height: calc(100vh - 63px); }
.editor-side { overflow-y: auto; border-right: 1px solid var(--border); background: var(--surface); padding: 18px 18px 28px; }
.editor-head { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.small-link { font-size: 13px; }
.title-input { font-size: 18px; font-weight: 700; padding: 6px 8px; margin-left: -8px; border-color: transparent; background: transparent; }
.title-input:hover { border-color: var(--border); }
#save-status.err { color: var(--error); font-weight: 600; }
.editor-foot { margin-top: 24px; }
button.danger { color: var(--error); border-color: var(--error); }

.ed-label { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; margin: 22px 0 8px; }
.ed-panel { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; background: var(--surface); }
.ed-panel.is-off .ed-panel-title { color: var(--text-muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--text-muted) 50%, transparent); }
.ed-panel > summary { list-style: none; display: flex; align-items: center; gap: 8px; padding: 11px 12px; cursor: pointer; font-weight: 600; font-size: 14px; }
.ed-panel > summary::-webkit-details-marker { display: none; }
.ed-panel > summary::before { content: "›"; display: inline-block; width: 10px; color: var(--text-muted); transition: transform .15s; }
.ed-panel[open] > summary::before { transform: rotate(90deg); }
.ed-panel-title { flex: 1; min-width: 0; }
.ed-panel-tools { display: flex; align-items: center; gap: 4px; }
.ed-panel-body { padding: 4px 12px 14px; display: flex; flex-direction: column; gap: 12px; border-top: 1px solid var(--border); padding-top: 12px; }

.f { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-muted); font-weight: 500; }
.f input[type=text], .f textarea, .f select { font-size: 14px; padding: 8px 10px; }
.f textarea { min-height: 64px; }

.icon-btn { background: transparent; border: 1px solid transparent; color: var(--text-muted); padding: 2px 7px; font-size: 13px; font-weight: 500; border-radius: 6px; }
.icon-btn:hover:not(:disabled) { background: var(--surface-alt); border-color: var(--border); color: var(--text); }
.icon-btn:disabled { opacity: .3; }

.switch { position: relative; display: inline-flex; width: 34px; height: 20px; flex: none; cursor: pointer; margin-left: 4px; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-ui { width: 100%; height: 100%; border-radius: 999px; background: var(--border); transition: background .15s; position: relative; pointer-events: none; }
.switch-ui::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + .switch-ui { background: var(--accent); }
.switch input:checked + .switch-ui::after { transform: translateX(14px); }
.switch input:focus-visible + .switch-ui { box-shadow: 0 0 0 3px var(--accent-soft); }

.items { display: flex; flex-direction: column; gap: 10px; }
.item { border: 1px dashed var(--border); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 8px; background: var(--bg); }
.item-tools { display: flex; align-items: center; gap: 2px; }
.item-num { flex: 1; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.add-item { align-self: flex-start; }

.img-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.img-thumb { width: 64px; height: 48px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-alt); }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.swatch { width: 26px; height: 26px; padding: 0; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border); }
.swatch.active { box-shadow: 0 0 0 2px var(--text); }
.swatches input[type=color] { width: 34px; height: 30px; padding: 2px; cursor: pointer; }

.editor-preview { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.preview-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; padding: 2px; background: var(--bg); }
.seg-btn { background: transparent; border: 0; color: var(--text-muted); padding: 6px 12px; font-size: 13px; font-weight: 600; border-radius: 6px; }
.seg-btn:hover { background: transparent; color: var(--text); }
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.preview-stage { flex: 1; min-height: 0; display: flex; justify-content: center; padding: 16px; }
.preview-stage iframe { width: 100%; height: 100%; border: 1px solid var(--border); border-radius: 10px; background: #fff; transition: width .25s ease; }
.preview-stage.mobile iframe { width: 390px; max-width: 100%; border-radius: 28px; border-width: 8px; border-color: #1d1d1f; }

@media (max-width: 900px) {
  .editor { grid-template-columns: 1fr; height: auto; }
  .editor-side { border-right: 0; border-bottom: 1px solid var(--border); }
  .preview-stage { height: 80vh; }
}
