:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1c2330;
  --muted: #6b7280;
  --line: #e4e7ec;
  --accent: #0b3d91;
  --accent-2: #1456c8;
  --danger: #b42318;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); background: var(--bg); line-height: 1.45;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-2); }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(160deg, #0b3d91 0%, #133a7a 60%, #0b1f44 100%); }
.login-card {
  background: var(--panel); padding: 32px; border-radius: 16px; box-shadow: var(--shadow);
  width: min(360px, 92vw); display: flex; flex-direction: column; gap: 14px;
}
.login-card h1 { margin: 0; font-size: 22px; line-height: 1.15; color: var(--accent); }
.login-card .sub { margin: 0 0 6px; color: var(--muted); }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.login-card input { padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 15px; }
.login-card button { margin-top: 6px; padding: 12px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.login-card button:hover { background: var(--accent-2); }

/* ---------- topbar ---------- */
.topbar { display: flex; align-items: center; gap: 14px; padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; color: var(--accent); }
.brand span { font-weight: 500; color: var(--ink); }
.topnav { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.badge { background: #eef2ff; color: var(--accent); padding: 3px 10px; border-radius: 999px; font-size: 12px; }
.link { background: none; border: 0; color: var(--accent-2); cursor: pointer; padding: 6px; font-weight: 500; }
.link:hover { text-decoration: underline; }
.icon-btn { display: none; background: none; border: 0; font-size: 20px; cursor: pointer; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 290px 1fr; min-height: calc(100vh - 53px); }
.sidebar { border-right: 1px solid var(--line); background: var(--panel); padding: 14px; overflow-y: auto; }
.sidebar h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 6px 6px 12px; }
.session-list { display: flex; flex-direction: column; gap: 4px; }
.session-item { display: flex; gap: 10px; align-items: center; text-align: left; background: none; border: 0; border-radius: 10px; padding: 8px; cursor: pointer; }
.session-item:hover { background: #f3f4f6; }
.session-item.active { background: #eef2ff; }
.session-item .thumb { width: 44px; height: 44px; border-radius: 8px; background: #eceef1; overflow: hidden; flex: 0 0 auto; display: grid; place-items: center; }
.session-item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.session-item .meta { display: flex; flex-direction: column; min-width: 0; }
.session-item .title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item .sub { font-size: 12px; color: var(--muted); }

.main { padding: 22px; overflow-y: auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; max-width: 980px; margin: 0 auto; }
.panel h1 { margin: 0 0 16px; font-size: 20px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); }

/* ---------- new form ---------- */
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px; text-align: center; background: #fafbfc; cursor: pointer; }
.dropzone.drag { border-color: var(--accent-2); background: #eef4ff; }
.dropzone p { margin: 4px 0; }
.previews { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0; }
.preview { position: relative; width: 110px; }
.preview img { width: 110px; height: 110px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.preview span { display: block; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview .rm { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border: 0; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; }

.row { margin: 16px 0; }
.row.gap { display: flex; gap: 16px; flex-wrap: wrap; }
.seg { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.seg legend { font-size: 12px; color: var(--muted); padding: 0 6px; }
.seg label { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; }
.check { display: flex; align-items: center; gap: 8px; margin: 12px 0; cursor: pointer; }
.block { display: flex; flex-direction: column; gap: 6px; }
label > select { display: block; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; resize: vertical; font-size: 14px; }
.adv { margin: 14px 0; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 14px; }
.adv summary { cursor: pointer; padding: 8px 0; font-weight: 500; }

.actions { display: flex; align-items: center; gap: 14px; margin-top: 18px; }
.primary { background: var(--accent); color: #fff; border: 0; padding: 11px 22px; border-radius: 10px; font-weight: 600; cursor: pointer; }
.primary:hover { background: var(--accent-2); }
.primary:disabled { background: #aab2c0; cursor: not-allowed; }
.btn { display: inline-block; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line); background: #fff; text-decoration: none; color: var(--ink); cursor: pointer; }
.btn:hover { background: #f3f4f6; }

/* ---------- session chain ---------- */
.session-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.session-head h1 { margin: 0; }
.session-head .spacer { flex: 1; }
.tag { background: #eef2ff; color: var(--accent); padding: 3px 10px; border-radius: 999px; font-size: 12px; }
.chain { display: flex; flex-direction: column; gap: 16px; }
.turn { display: flex; }
.io { display: flex; align-items: center; gap: 16px; width: 100%; flex-wrap: wrap; background: #fafbfc; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.io-side { display: flex; flex-direction: column; gap: 8px; }
.io-side .lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.io-side.result { margin-left: auto; align-items: center; min-width: 220px; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumbs img { width: 86px; height: 86px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.instr { margin: 0; max-width: 360px; font-style: italic; }
.arrow { font-size: 24px; color: var(--muted); }
.io-side.result img { max-width: 320px; width: 100%; border-radius: 10px; border: 1px solid var(--line); }
.res-actions { display: flex; align-items: center; gap: 12px; }
.error-box { padding: 20px; }
.spinner { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--accent-2); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- follow-up ---------- */
.followup { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 16px; }
.fu-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; gap: 12px; }

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .icon-btn { display: block; }
  .topnav .link { font-size: 14px; }
  .sidebar { position: fixed; z-index: 30; top: 53px; bottom: 0; left: 0; width: 82vw; max-width: 320px; transform: translateX(-105%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .io-side.result { margin-left: 0; }
  .arrow { display: none; }
}
