:root {
  --ink: #0f172a;
  --text: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --bg: #f1f5f9;
  --card: #ffffff;
  --hover: #f8fafc;
  --accent: #0e7490;
  --accent-hover: #155e75;
  --accent-soft: #ecfeff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --marker: #f97316;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(15 23 42 / 0.06), 0 4px 16px rgb(15 23 42 / 0.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { color: var(--ink); line-height: 1.25; }
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.boot { padding: 48px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--hover); border-color: var(--muted); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); border-color: var(--line); }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 32px; min-height: 32px; padding: 0; }
.btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

input[type=text], input[type=email], input[type=password], input[type=search], input[type=url], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--card); color: var(--ink); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea { resize: vertical; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-weight: 600; color: var(--ink); margin-bottom: 4px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.error-text { color: var(--danger); margin: 8px 0 0; }

/* ---------- auth pages ---------- */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.auth-card h1 { margin-bottom: 6px; }
.auth-card p.lead { margin: 0 0 20px; color: var(--muted); }
.auth-card .btn.primary { width: 100%; min-height: 40px; }
.auth-foot { margin-top: 16px; text-align: center; color: var(--muted); }
.brand-mark { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff; margin-bottom: 14px; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 700; font-size: 15px; text-decoration: none; }
.brand .logo { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: #fff; }
.ws-switch { width: auto; max-width: 220px; min-height: 34px; padding: 4px 8px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; border: none; background: #cffafe; color: var(--accent);
  font-weight: 700; cursor: pointer;
}
.menu-toggle { display: none; }

.layout { display: flex; min-height: calc(100vh - 56px); }
.sidebar { width: 240px; flex: none; padding: 16px 10px; border-right: 1px solid var(--line); background: var(--card); }
.sidebar .section-label { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 6px; font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.nav-item {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; border-radius: 7px; border: none; background: none;
  color: var(--text); font: inherit; text-decoration: none; text-align: left; cursor: pointer;
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .count { margin-left: auto; font-size: 12px; color: var(--muted); }
.nav-item .folder-actions { margin-left: auto; display: none; gap: 2px; }
.nav-item:hover .folder-actions { display: flex; }
.nav-item:hover .count { display: none; }
.folder-actions button { border: none; background: none; color: var(--muted); cursor: pointer; padding: 0 3px; font-size: 13px; }
.folder-actions button:hover { color: var(--ink); }
.main { flex: 1; min-width: 0; padding: 24px; }

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 190px; padding: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.dropdown-menu button, .dropdown-menu a {
  display: block; width: 100%; padding: 8px 10px; border: none; border-radius: 6px; background: none;
  color: var(--ink); font: inherit; text-align: left; text-decoration: none; cursor: pointer;
}
.dropdown-menu button:hover, .dropdown-menu a:hover { background: var(--hover); }
.dropdown-menu .danger { color: var(--danger); }
.dropdown-menu .menu-head { padding: 8px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }

/* ---------- dashboard ---------- */
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .search { width: 260px; }
.guide-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.guide-card {
  position: relative; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; overflow: hidden; text-decoration: none; color: inherit; transition: box-shadow 0.15s, border-color 0.15s;
}
.guide-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.guide-card .thumb { aspect-ratio: 16 / 9; background: #e2e8f0 center top / cover no-repeat; border-bottom: 1px solid var(--line); display: grid; place-items: center; color: var(--muted); }
.guide-card .info { padding: 12px 14px 14px; }
.guide-card .title { margin: 0 0 4px; color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.guide-card .meta { font-size: 12px; color: var(--muted); }
.guide-card .card-menu { position: absolute; top: 8px; right: 8px; }
.guide-card .card-menu > .btn { background: rgb(255 255 255 / 0.92); }
.badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--accent-soft); color: var(--accent); }

.empty { text-align: center; padding: 56px 16px; background: var(--card); border: 1px dashed var(--line-strong); border-radius: 14px; }
.empty h2 { margin-bottom: 6px; }
.empty p { color: var(--muted); margin: 0 0 18px; }

/* ---------- editor ---------- */
.editor { max-width: 900px; margin: 0 auto; }
.editor-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.save-state { font-size: 12px; color: var(--muted); min-width: 60px; }
.save-state.error { color: var(--danger); }
.title-input {
  width: 100%; border: 1px solid transparent; border-radius: 8px; padding: 4px 8px; margin: 0 -8px;
  background: transparent; color: var(--ink); font: 700 26px/1.25 inherit; font-family: inherit;
}
.title-input:hover { border-color: var(--line); }
.desc-input { border-color: transparent; background: transparent; margin: 6px -8px 0; width: calc(100% + 16px); padding: 4px 8px; min-height: 34px; color: var(--text); }
.desc-input:hover { border-color: var(--line); }
.guide-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 10px 0 22px; color: var(--muted); font-size: 13px; }
.guide-meta select { width: auto; min-height: 30px; padding: 2px 8px; font-size: 13px; }

.steps { list-style: none; margin: 0; padding: 0; }
.step-card {
  position: relative; display: flex; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; transition: border-color 0.12s, box-shadow 0.12s;
}
.step-card:focus-within { border-color: var(--line-strong); box-shadow: var(--shadow); }
.step-card.dragging { opacity: 0.4; }
.step-card.drop-before { box-shadow: 0 -3px 0 var(--accent); }
.step-card.drop-after { box-shadow: 0 3px 0 var(--accent); }
.step-side { display: flex; flex-direction: column; align-items: center; gap: 8px; flex: none; }
.handle { cursor: grab; color: var(--muted); font-size: 16px; line-height: 1; padding: 4px; user-select: none; border-radius: 4px; }
.handle:hover { background: var(--hover); color: var(--ink); }
.step-num { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.step-main { flex: 1; min-width: 0; }
.step-title { border: 1px solid transparent; padding: 3px 6px; margin: 0 -6px; width: calc(100% + 12px); background: transparent; color: var(--ink); font-weight: 600; font-size: 15px; resize: none; overflow: hidden; }
.step-title:hover, .step-body:hover { border-color: var(--line); }
.step-body { border: 1px solid transparent; padding: 3px 6px; margin: 4px -6px 0; width: calc(100% + 12px); background: transparent; resize: none; overflow: hidden; font-size: 14px; }
.step-card.kind-heading { background: transparent; border-color: transparent; padding: 18px 16px 6px; }
.step-card.kind-heading:focus-within { background: var(--card); }
.step-card.kind-heading .step-title { font-size: 20px; font-weight: 700; }
.step-card.kind-tip { background: var(--accent-soft); border-color: #a5f3fc; border-left: 4px solid var(--accent); }
.step-card.kind-alert { background: var(--danger-soft); border-color: #fecaca; border-left: 4px solid var(--danger); }
.callout-label { font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--accent); }
.kind-alert .callout-label { color: var(--danger); }

.shot { position: relative; margin-top: 12px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; line-height: 0; background: #f8fafc; }
.shot img { width: 100%; height: auto; display: block; }
.shot .g-marker { position: absolute; }
.add-image { margin-top: 10px; width: 100%; min-height: 64px; border: 1px dashed var(--line-strong); border-radius: 8px; background: var(--hover); color: var(--muted); font: inherit; cursor: pointer; }
.add-image:hover { border-color: var(--accent); color: var(--accent); }
.step-tools { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; margin-top: 10px; opacity: 0; transition: opacity 0.12s; }
.step-card:hover .step-tools, .step-card:focus-within .step-tools { opacity: 1; }
.step-tools select { width: auto; min-height: 30px; padding: 2px 6px; font-size: 13px; }

.insert-row { position: relative; height: 18px; display: flex; align-items: center; justify-content: center; }
.insert-row .insert-btn {
  opacity: 0; width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--card);
  color: var(--accent); font-weight: 700; cursor: pointer; line-height: 1; transition: opacity 0.12s;
}
.insert-row:hover .insert-btn, .insert-row .insert-btn:focus { opacity: 1; }
.insert-row .dropdown-menu { right: auto; left: 50%; transform: translateX(-50%); top: 26px; }

.add-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 20px; padding: 16px; border: 1px dashed var(--line-strong); border-radius: 12px; background: var(--card); }
.drop-hint { margin-left: auto; font-size: 12px; color: var(--muted); }
.editor.drop-active .add-bar { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgb(15 23 42 / 0.5); display: grid; place-items: center; padding: 16px; }
.modal { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; background: var(--card); border-radius: 14px; box-shadow: 0 20px 60px rgb(15 23 42 / 0.3); }
.modal.wide { max-width: 1100px; }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; flex: 1; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.copy-field { display: flex; gap: 8px; }
.copy-field input, .copy-field textarea { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.switch-row { display: flex; align-items: flex-start; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 16px; }
.switch-row > input[type=checkbox] { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--accent); }

/* image editor */
.img-editor-tools { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.img-editor-stage { position: relative; line-height: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #e2e8f0; user-select: none; touch-action: none; }
.img-editor-stage canvas { width: 100%; height: auto; display: block; }
.img-editor-stage.mode-marker { cursor: crosshair; }
.img-editor-stage.mode-blur, .img-editor-stage.mode-crop { cursor: crosshair; }
.img-editor-stage .g-marker { position: absolute; }
.sel-rect { position: absolute; border: 2px dashed var(--accent); background: rgb(14 116 144 / 0.12); pointer-events: none; }

/* ---------- tables / settings ---------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 20px; }
.panel > p { margin-top: 0; }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list th { font-size: 12px; color: var(--muted); font-weight: 600; }
table.list select { width: auto; min-height: 30px; padding: 2px 6px; }
.table-scroll { overflow-x: auto; }
.narrow { max-width: 760px; }
ol.install { padding-left: 20px; }
ol.install li { margin-bottom: 8px; }
code { background: var(--hover); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 12px; }

/* read-only guide inside the app */
.readonly-guide .g-step { margin-bottom: 16px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 90vw; }
.toast.error { background: var(--danger); }

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  .menu-toggle { display: inline-flex; }
  .sidebar { position: fixed; top: 56px; bottom: 0; left: 0; z-index: 25; transform: translateX(-100%); transition: transform 0.18s; box-shadow: var(--shadow); overflow-y: auto; }
  .sidebar.open { transform: none; }
  .main { padding: 16px; }
  .ws-switch { max-width: 130px; }
  .brand .name { display: none; }
  .page-head .search { width: 100%; }
  .step-tools { opacity: 1; }
  .drop-hint { margin-left: 0; }
}
@media (max-width: 480px) {
  #new-guide .label { display: none; }
  .step-card { padding: 12px; gap: 8px; }
}
