/* ==========================================================================
   Städschema Studio – appens gränssnitt (skärm)
   ========================================================================== */
:root {
  --ui-bg: #EEF1F5;
  --ui-panel: #FFFFFF;
  --ui-border: #DFE4EB;
  --ui-border-strong: #C9D1DC;
  --ui-text: #1C2733;
  --ui-muted: #5F6E7D;
  --ui-accent: #005AA7;
  --ui-accent-hover: #08809D;
  --ui-accent-soft: #E6F0FA;
  --ui-danger: #B42318;
  --ui-warn-bg: #FFF4E5;
  --ui-warn-fg: #8A4B00;
  --ui-ok-bg: #E7F6EC;
  --ui-ok-fg: #1B5E20;
  --ui-shadow: 0 8px 24px rgba(20, 40, 60, .14);
  --ui-radius: 10px;
  --ui-font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--ui-font);
  font-size: 13px;
  line-height: 1.45;
  color: var(--ui-text);
  background: var(--ui-bg);
  display: grid;
  grid-template-rows: 54px 1fr;
  grid-template-columns: 250px minmax(0, 1fr) 340px;
  grid-template-areas: "top top top" "side canvas insp";
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 2px; }
svg { display: block; }

/* ---------- Verktygsfält ---------- */
#topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px 0 16px;
  background: var(--ui-panel);
  border-bottom: 1px solid var(--ui-border);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: 6px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(145deg, #005AA7, #1BB998);
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.brand-mark svg { width: 17px; height: 17px; }
.brand-name { font-weight: 700; font-size: 14px; letter-spacing: -.01em; }
.brand-name small { display: block; font-weight: 500; font-size: 11px; color: var(--ui-muted); letter-spacing: .02em; margin-top: -2px; }
#doc-title { font-weight: 600; color: var(--ui-muted); padding-left: 12px; border-left: 1px solid var(--ui-border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
#save-state { font-size: 11.5px; color: var(--ui-muted); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
#save-state.pending { color: var(--ui-accent); }
#save-state .cloud-dot { width: 8px; height: 8px; border-radius: 50%; background: #9AA5B1; flex: none; }
#save-state.ok .cloud-dot { background: #2E9E5B; }
#save-state.pending .cloud-dot { background: var(--ui-accent); animation: pulse 1s infinite alternate; }
#save-state.warn .cloud-dot { background: #E0A100; }
#save-state.err .cloud-dot { background: var(--ui-danger); }
#save-state.err { color: var(--ui-danger); }
@keyframes pulse { from { opacity: .35; } to { opacity: 1; } }
.spacer { flex: 1; }
.tb-group { display: flex; align-items: center; gap: 4px; padding: 0 8px; border-left: 1px solid var(--ui-border); }
.tb-group:first-of-type { border-left: 0; }
.tb-group[hidden] { display: none; }
.btn-icon {
  all: unset; cursor: pointer; width: 32px; height: 32px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center; color: #3b4754;
}
.btn-icon:hover { background: #EEF3F8; color: var(--ui-accent); }
.btn-icon:disabled { opacity: .35; cursor: default; background: none; }
.btn-icon:focus-visible { outline: 2px solid var(--ui-accent); }
.btn-icon svg { width: 17px; height: 17px; }
.btn-icon.danger:hover { background: #FDECEC; color: var(--ui-danger); }
#zoom-val { min-width: 46px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ui-muted); font-size: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--ui-border-strong); background: #fff; color: var(--ui-text);
  font-weight: 600; font-size: 13px; white-space: nowrap; cursor: pointer;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: #F5F8FB; border-color: #B8C4D2; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--ui-accent); border-color: var(--ui-accent); color: #fff; }
.btn-primary:hover { background: var(--ui-accent-hover); border-color: var(--ui-accent-hover); }
.btn-sm { height: 30px; padding: 0 11px; font-size: 12.5px; }
.btn-danger { background: var(--ui-danger); border-color: var(--ui-danger); color: #fff; }
.btn-danger:hover { background: #8f1c14; }
.btn-danger-ghost { color: var(--ui-danger); }
.btn-danger-ghost:hover { background: #FDECEC; border-color: #F3B1AC; }
.seg { display: inline-flex; background: #EEF1F5; border-radius: 8px; padding: 3px; gap: 2px; }
.seg button {
  all: unset; cursor: pointer; padding: 5px 11px; border-radius: 6px; font-weight: 600; font-size: 12.5px; color: var(--ui-muted); white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.seg button:hover { color: var(--ui-text); }
.seg button.active { background: #fff; color: var(--ui-text); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.seg button:focus-visible { outline: 2px solid var(--ui-accent); }
.seg button svg { width: 14px; height: 14px; }

/* ---------- Sidlista ---------- */
#sidebar {
  grid-area: side;
  background: var(--ui-panel);
  border-right: 1px solid var(--ui-border);
  display: flex; flex-direction: column; min-height: 0;
}
.panel-head { padding: 14px 16px 8px; font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ui-muted); display: flex; align-items: center; justify-content: space-between; }
#page-list { list-style: none; margin: 0; padding: 4px 8px 8px; overflow: auto; flex: 1; }
#page-list li {
  display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: 8px; cursor: pointer; margin-bottom: 2px;
  border: 1px solid transparent;
}
#page-list li:hover { background: #F3F6FA; }
#page-list li.active { background: var(--ui-accent-soft); border-color: #C9DDF1; }
#page-list li.hidden-page { opacity: .6; }
.pl-num { width: 18px; font-size: 11px; color: var(--ui-muted); font-variant-numeric: tabular-nums; text-align: right; flex: none; }
.pl-icon { width: 26px; height: 26px; border-radius: 7px; background: #EEF1F5; color: #4d5b69; display: inline-flex; align-items: center; justify-content: center; flex: none; }
#page-list li.active .pl-icon { background: #fff; color: var(--ui-accent); }
.pl-icon svg { width: 14px; height: 14px; }
.pl-text { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.pl-title { font-weight: 600; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-sub { font-size: 11px; color: var(--ui-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-dot, .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; border: 1px solid rgba(0, 0, 0, .12); }
/* Samma färger som på sidorna: surt röd, basiskt grön, desinfektion gul, övrigt grå */
.dot.type-sur, .pl-dot.type-sur { background: #D63B2F; }
.dot.type-basisk, .pl-dot.type-basisk { background: #43A047; }
.dot.type-desinfektion, .pl-dot.type-desinfektion { background: #F2C200; }
.dot.type-ovrigt, .pl-dot.type-ovrigt { background: #6B7280; }
.pl-warn { color: #B26A00; flex: none; }
.pl-warn svg { width: 14px; height: 14px; }
.sidebar-foot { padding: 10px 12px; border-top: 1px solid var(--ui-border); }
.sidebar-foot .btn { width: 100%; }

/* ---------- Arbetsyta ---------- */
#canvas-root {
  grid-area: canvas;
  overflow: auto;
  position: relative;
  background:
    radial-gradient(circle at 1px 1px, rgba(20, 40, 60, .10) 1px, transparent 1px) 0 0 / 22px 22px,
    var(--ui-bg);
}
#canvas { padding: 32px 32px 80px; display: flex; flex-direction: column; align-items: center; width: max-content; min-width: 100%; }
#hintbar {
  position: sticky; top: 0; z-index: 15;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--ui-border);
  font-size: 12.5px; color: var(--ui-muted);
}
#hintbar[hidden] { display: none; }
#hintbar .hint-text { flex: 1; }
#hintbar b { color: var(--ui-text); }
#hintbar .btn-icon { width: 26px; height: 26px; font-size: 12px; }
body.mode-preview #hintbar { display: none; }
.reg-card { display: flex; flex-direction: column; gap: 6px; padding: 8px; border-radius: 10px; background: #F5F8FB; }
.reg-line { display: flex; align-items: center; gap: 6px; }
.reg-line .input { flex: 1; min-width: 0; height: 30px; font-size: 12.5px; }
.reg-line .btn-icon { width: 28px; height: 28px; flex: none; }
.insp-details { border-bottom: 1px solid var(--ui-border); padding: 12px 0; }
.insp-details summary { cursor: pointer; font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ui-muted); list-style: none; display: flex; align-items: center; gap: 6px; }
.insp-details summary::-webkit-details-marker { display: none; }
.insp-details summary::before { content: '▸'; font-size: 10px; }
.insp-details[open] summary::before { content: '▾'; }
.insp-details > div { margin-top: 10px; }
#loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--ui-muted); font-weight: 600; }

/* ---------- Inspektör ---------- */
#inspector {
  grid-area: insp;
  background: var(--ui-panel);
  border-left: 1px solid var(--ui-border);
  display: flex; flex-direction: column; min-height: 0;
}
#insp-tabs { display: flex; gap: 2px; padding: 10px 12px 0; border-bottom: 1px solid var(--ui-border); }
#insp-tabs button {
  all: unset; cursor: pointer; padding: 8px 10px 10px; font-weight: 600; font-size: 12.5px; color: var(--ui-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
#insp-tabs button:hover { color: var(--ui-text); }
#insp-tabs button.active { color: var(--ui-accent); border-color: var(--ui-accent); }
#insp-tabs button:focus-visible { outline: 2px solid var(--ui-accent); border-radius: 4px; }
#inspector-body { overflow: auto; flex: 1; padding: 6px 16px 30px; }
.insp-section { padding: 14px 0 12px; border-bottom: 1px solid var(--ui-border); }
.insp-section:last-child { border-bottom: 0; }
.insp-section h4 { margin: 0 0 10px; font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ui-muted); }
.insp-section h4:empty { display: none; }
.insp-muted, .insp-text { color: var(--ui-muted); margin: 0 0 10px; font-size: 12.5px; }
.insp-hint { display: block; color: var(--ui-muted); font-size: 11.5px; margin-top: 8px; line-height: 1.4; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.field > span { font-size: 12px; font-weight: 600; color: #3b4754; }
.field small { color: var(--ui-muted); font-size: 11px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.input {
  width: 100%; height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--ui-border-strong); background: #fff;
  font-size: 13px; transition: border-color .12s, box-shadow .12s;
}
textarea.input { height: auto; min-height: 58px; padding: 7px 10px; resize: vertical; line-height: 1.4; }
.input:focus { outline: none; border-color: var(--ui-accent); box-shadow: 0 0 0 3px rgba(0, 90, 167, .15); }
.input.narrow { width: auto; min-width: 0; }
select.input { appearance: auto; }
.check { display: flex; align-items: flex-start; gap: 8px; margin: 6px 0 10px; font-size: 12.5px; cursor: pointer; }
.check input { margin: 2px 0 0; accent-color: var(--ui-accent); }
.chipbox { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--ui-border-strong);
  background: #fff; font-size: 12px; font-weight: 600; cursor: pointer; user-select: none; transition: all .12s;
}
.chip:hover { border-color: var(--ui-accent); }
.chip.on { background: var(--ui-accent); border-color: var(--ui-accent); color: #fff; }
.chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip:focus-within { box-shadow: 0 0 0 3px rgba(0, 90, 167, .25); }
.machine-list { display: flex; flex-direction: column; gap: 6px; }
.machine-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stepper { display: inline-flex; align-items: center; gap: 2px; border: 1px solid var(--ui-border-strong); border-radius: 999px; padding: 2px; background: #fff; }
.stepper button { all: unset; cursor: pointer; width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; color: var(--ui-accent); }
.stepper button:hover { background: var(--ui-accent-soft); }
.stepper button:disabled { color: #B8C2CC; cursor: default; background: none; }
.stepper button:focus-visible { outline: 2px solid var(--ui-accent); }
.stepper-val { min-width: 34px; text-align: center; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.btn-col { display: flex; flex-direction: column; gap: 6px; }
.btn-col .btn { width: 100%; }
.kem-preview { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; background: #F5F8FB; font-size: 12.5px; }
.kem-preview span:last-child { color: var(--ui-muted); }
.fit-info { padding: 9px 11px; border-radius: 8px; font-size: 12.5px; line-height: 1.4; }
.fit-info.ok { background: var(--ui-ok-bg); color: var(--ui-ok-fg); }
.fit-info.warn { background: var(--ui-warn-bg); color: var(--ui-warn-fg); }
.fit-info.bad { background: #FDECEC; color: var(--ui-danger); }
.img-preview { border-radius: 10px; overflow: hidden; border: 1px solid var(--ui-border); background: #f3f5f8; aspect-ratio: 3/2; display: flex; align-items: center; justify-content: center; margin-bottom: 10px; color: var(--ui-muted); }
.img-preview img { width: 100%; height: 100%; object-fit: cover; }
.img-preview.small { aspect-ratio: 210/297; width: 90px; }
.color-row { display: flex; align-items: center; gap: 8px; }
.color-row input[type="color"] { width: 40px; height: 32px; padding: 2px; border: 1px solid var(--ui-border-strong); border-radius: 8px; background: #fff; cursor: pointer; }
.color-row code { font-size: 11.5px; color: var(--ui-muted); }
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input { flex: 1; accent-color: var(--ui-accent); }
.range-val { width: 40px; text-align: right; font-size: 12px; color: var(--ui-muted); font-variant-numeric: tabular-nums; }
.theme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.theme-card {
  all: unset; cursor: pointer; display: flex; flex-direction: column; gap: 2px; padding: 6px; border-radius: 10px; border: 1px solid var(--ui-border);
  background: #fff; transition: border-color .12s, box-shadow .12s;
}
.theme-card:hover { border-color: var(--ui-accent); }
.theme-card.active { border-color: var(--ui-accent); box-shadow: 0 0 0 2px rgba(0, 90, 167, .25); }
.theme-card:focus-visible { outline: 2px solid var(--ui-accent); }
.tc-prev { position: relative; height: 74px; border-radius: 6px; overflow: hidden; border: 1px solid rgba(0, 0, 0, .08); display: block; }
.tc-bg { position: absolute; inset: 0; background-size: cover; background-position: center; mix-blend-mode: multiply; }
.tc-title { position: absolute; left: 10px; top: 12px; width: 52%; height: 9px; border-radius: 3px; }
.tc-acc { position: absolute; left: 10px; top: 28px; width: 28%; height: 5px; border-radius: 2px; }
.tc-line { position: absolute; left: 10px; top: 42px; width: 70%; height: 4px; border-radius: 2px; }
.tc-line.short { top: 52px; width: 55%; }
.tc-rail { position: absolute; right: 5px; top: 8px; bottom: 8px; width: 5px; display: flex; flex-direction: column; justify-content: space-between; }
.tc-rail i { display: block; width: 5px; height: 4px; border-radius: 2px; }
.tc-rail i.on { height: 11px; }
.tc-name { font-weight: 700; font-size: 12.5px; margin-top: 4px; }
.tc-season { font-size: 11px; color: var(--ui-muted); }
.reg-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.reg-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 6px; border-radius: 8px; background: #F5F8FB; }
.reg-row .input { flex: 1; min-width: 90px; height: 30px; font-size: 12.5px; }
.reg-row select.input { flex: 0 1 auto; max-width: 130px; }
.reg-row .btn-icon { width: 28px; height: 28px; }
.reg-icon { width: 26px; height: 26px; object-fit: contain; }
.tips { margin: 0; padding-left: 18px; color: var(--ui-muted); font-size: 12px; }
.tips li { margin-bottom: 5px; }

/* ---------- Popover ---------- */
.popover {
  position: fixed; z-index: 100; min-width: 240px; max-width: 340px; padding: 12px; border-radius: 12px;
  background: #fff; border: 1px solid var(--ui-border); box-shadow: var(--ui-shadow); font-family: var(--ui-font); font-size: 13px; color: var(--ui-text);
  animation: pop .12s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.pop-title { font-weight: 700; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--ui-muted); margin-bottom: 8px; }
.pop-text { margin: 0 0 8px; color: var(--ui-muted); font-size: 12.5px; }
.pop-list { margin: 0 0 10px; padding-left: 18px; font-size: 12.5px; color: var(--ui-muted); max-height: 140px; overflow: auto; }
.pop-scroll { max-height: 320px; overflow: auto; margin: 0 -4px; padding: 0 4px; }
.pop-item {
  all: unset; cursor: pointer; display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 8px; border-radius: 7px; box-sizing: border-box;
}
.pop-item:hover { background: #F3F6FA; }
.pop-item.active { background: var(--ui-accent-soft); }
.pop-item:focus-visible { outline: 2px solid var(--ui-accent); }
.pop-muted { color: var(--ui-muted); font-size: 12px; margin-left: auto; }
.pop-item.lib-item { flex-direction: column; align-items: flex-start; gap: 1px; }
.lib-title { font-weight: 600; }
.lib-prev { font-size: 11.5px; color: var(--ui-muted); line-height: 1.3; }
.popover .chipbox { max-width: 320px; }
.popover .input { margin-bottom: 8px; }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 25, 35, .45); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal { background: #fff; border-radius: 14px; padding: 22px 24px; width: min(440px, 92vw); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal h3 { margin: 0 0 8px; font-size: 16px; }
.modal p { margin: 0 0 18px; color: var(--ui-muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 300; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 10px; background: #1C2733; color: #fff; font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3); opacity: 0; transform: translateY(8px); transition: all .2s; pointer-events: auto; max-width: 520px;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--ui-danger); }
.toast-btn { all: unset; cursor: pointer; font-weight: 700; color: #8FD3FF; padding: 2px 4px; border-radius: 4px; }
.toast-btn:hover { text-decoration: underline; }

/* ---------- Låsskärm ---------- */
#gate {
  position: fixed; inset: 0; z-index: 1000;
  display: grid; place-items: center; padding: 24px;
  background: radial-gradient(120% 90% at 10% 0%, #1BB998 0%, transparent 55%), linear-gradient(160deg, #0B3D63 0%, #005AA7 55%, #08809D 100%);
  transition: opacity .35s ease;
}
#gate[hidden] { display: none; }
#gate.gate-out { opacity: 0; pointer-events: none; }
.gate-card {
  width: min(380px, 100%); background: #fff; border-radius: 18px; padding: 34px 32px 30px;
  box-shadow: 0 30px 80px -20px rgba(0, 20, 40, .55); text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.gate-card.shake { animation: gate-shake .45s; }
@keyframes gate-shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.gate-mark { width: 54px; height: 54px; border-radius: 16px; background: linear-gradient(145deg, #005AA7, #1BB998); color: #fff; display: flex; align-items: center; justify-content: center; margin-bottom: 6px; }
.gate-mark svg { width: 28px; height: 28px; }
.gate-card h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.gate-sub { margin: 0 0 14px; color: var(--ui-muted); font-size: 13px; }
.gate-label { align-self: flex-start; font-size: 12px; font-weight: 600; color: #3b4754; }
.gate-input {
  width: 100%; height: 56px; border-radius: 12px; border: 1.5px solid var(--ui-border-strong);
  font-size: 26px; letter-spacing: .45em; text-align: center; padding: 0 0 0 .45em; font-variant-numeric: tabular-nums;
}
.gate-input:focus { outline: none; border-color: var(--ui-accent); box-shadow: 0 0 0 4px rgba(0, 90, 167, .18); }
.gate-error { margin: 2px 0 0; color: var(--ui-danger); font-size: 12.5px; font-weight: 600; align-self: flex-start; }
.gate-btn { width: 100%; height: 44px; font-size: 14px; margin-top: 10px; }

/* ---------- Sparade scheman ---------- */
/* Knappen i verktygsfältet: visar vilket schema som är öppet och om det ändrats */
.doc-source {
  all: unset; box-sizing: border-box; cursor: pointer; flex: none;
  display: inline-flex; align-items: center; gap: 6px; max-width: 250px; height: 28px; padding: 0 11px 0 9px;
  border-radius: 999px; border: 1px solid var(--ui-border-strong); background: #fff;
  font-size: 12px; font-weight: 600; color: var(--ui-muted); white-space: nowrap;
  transition: border-color .12s, color .12s, background .12s;
}
.doc-source:hover { border-color: var(--ui-accent); color: var(--ui-accent); }
.doc-source:focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 2px; }
.doc-source svg { width: 14px; height: 14px; flex: none; }
.doc-source .ds-name { overflow: hidden; text-overflow: ellipsis; }
.doc-source.linked { color: var(--ui-text); background: var(--ui-accent-soft); border-color: #C9DDF1; }
.doc-source.linked svg { color: var(--ui-accent); }
.doc-source .ds-dirty { flex: none; display: inline-flex; align-items: center; gap: 5px; padding-left: 7px; margin-left: 1px; border-left: 1px solid #C9DDF1; color: var(--ui-warn-fg); }
.doc-source .ds-dirty::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #E0A100; }

.saved-section.flash { animation: ss-flash 1.4s ease-out; }
@keyframes ss-flash { 0%, 30% { box-shadow: inset 3px 0 0 var(--ui-accent); } 100% { box-shadow: inset 3px 0 0 transparent; } }
.ss-current { border: 1px solid var(--ui-border); border-radius: 12px; padding: 12px 13px 13px; margin: 2px 0 12px; background: #fff; }
.ss-current.dirty { border-color: #EFD08C; background: #FFFBF0; }
.ss-current.unsaved { background: #F5F8FB; border-style: dashed; border-color: var(--ui-border-strong); }
.ss-cur-label { font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ui-muted); }
.ss-cur-name { font-size: 16px; font-weight: 700; letter-spacing: -.01em; line-height: 1.3; margin: 3px 0 5px; overflow-wrap: anywhere; }
.ss-cur-state { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ui-muted); margin-bottom: 11px; }
.ss-current.dirty .ss-cur-state { color: var(--ui-warn-fg); font-weight: 600; }
.ss-dot { width: 8px; height: 8px; border-radius: 50%; background: #E0A100; flex: none; }
.ss-ok { width: 16px; height: 16px; border-radius: 50%; background: var(--ui-ok-bg); color: var(--ui-ok-fg); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.ss-ok svg { width: 10px; height: 10px; }
.ss-cur-text { margin: 4px 0 11px; font-size: 12.5px; color: var(--ui-muted); }
.link-btn { all: unset; cursor: pointer; display: inline-block; margin-top: 10px; font-size: 12px; font-weight: 600; color: var(--ui-muted); text-decoration: underline; text-underline-offset: 2px; }
.link-btn:hover { color: var(--ui-danger); }
.link-btn:focus-visible { outline: 2px solid var(--ui-accent); border-radius: 3px; }
.ss-list { list-style: none; margin: 0 0 4px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ss-item { display: flex; align-items: center; gap: 10px; padding: 9px 8px 9px 10px; border: 1px solid var(--ui-border); border-radius: 10px; background: #fff; }
.ss-item.active { border-color: #C9DDF1; background: var(--ui-accent-soft); }
/* Liten sidminiatyr i schemats temafärger */
.ss-thumb { position: relative; flex: none; width: 27px; height: 37px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, .13); box-shadow: 0 1px 2px rgba(0, 0, 0, .07); overflow: hidden; }
.ss-thumb i { position: absolute; left: 4px; border-radius: 1px; }
.ss-thumb .t1 { top: 5px; width: 14px; height: 3px; }
.ss-thumb .t2 { top: 10.5px; width: 18px; height: 1.5px; }
.ss-thumb .t3 { top: 15px; width: 17px; height: 2px; }
.ss-thumb .t4 { top: 19.5px; width: 12px; height: 2px; }
.ss-thumb .t5 { top: 24px; width: 16px; height: 2px; }
.ss-text { flex: 1; min-width: 0; }
.ss-name { display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: 13px; line-height: 1.3; }
.ss-name > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ss-tag { flex: none; font-size: 9.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--ui-accent); background: #fff; border: 1px solid #C9DDF1; border-radius: 999px; padding: 0 6px; line-height: 16px; }
.ss-meta { font-size: 11.5px; color: var(--ui-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.4; }
.ss-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.ss-actions .btn-icon { width: 28px; height: 28px; }
.ss-list-head { margin: 4px 0 7px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ui-muted); }
.pop-item.danger { color: var(--ui-danger); }
.pop-item.danger:hover { background: #FDECEC; }
/* Dialogens namnruta */
.modal-field { display: flex; flex-direction: column; gap: 5px; margin: 0; }
.modal-field > span { font-size: 12px; font-weight: 600; color: #3b4754; }
.modal .modal-error { margin: 6px 0 0; color: var(--ui-danger); font-size: 12.5px; font-weight: 600; }
.modal .modal-actions { flex-wrap: wrap; margin-top: 18px; }

/* ---------- Utskriftsguiden (det som bara går att välja i webbläsarens utskriftsruta) ---------- */
.modal.print-guide { width: min(470px, 92vw); }
.modal.print-guide > p { margin-bottom: 12px; }
.pg-list { display: grid; grid-template-columns: auto 1fr; margin: 0 0 12px; border: 1px solid var(--ui-border); border-radius: 10px; overflow: hidden; }
.pg-list dt, .pg-list dd { margin: 0; padding: 7px 12px; font-size: 13px; line-height: 1.35; border-top: 1px solid var(--ui-border); }
.pg-list dt:first-of-type, .pg-list dd:first-of-type { border-top: 0; }
.pg-list dt { color: var(--ui-muted); }
.pg-list dd { font-weight: 700; color: #1F2328; }
.modal .pg-note { font-size: 12px; line-height: 1.45; margin: 0 0 8px; }
.modal.print-guide .check { margin: 12px 0 0; }

/* ---------- Läge: förhandsgranskning / utskrift ---------- */
body.mode-preview #canvas-root { background: #DCE2E9; }
body.printing #topbar, body.printing #sidebar, body.printing #inspector { display: none; }
body.printing { grid-template-columns: 1fr; grid-template-areas: "canvas"; grid-template-rows: 1fr; }

/* Verktygsfältet får aldrig trycka ihop appnamnet; på smalare skärmar bär bokmärkesknappen namnet */
.brand { flex: none; }
.brand-name { white-space: nowrap; }
#doc-title { min-width: 0; flex: 0 1 auto; }
@media (max-width: 1400px) {
  #doc-title { display: none; }
  .doc-source { max-width: 210px; }
}
@media (max-width: 1100px) {
  body { grid-template-columns: 210px minmax(0, 1fr) 300px; }
}

/* ==========================================================================
   Omgång UX (2026-09-23): verktygsfält som alltid får plats, zoom i hörnet,
   flytande avsnittsverktyg, smalare fönster
   ========================================================================== */
:root { --insp-w: 340px; }
@media (max-width: 1100px) { :root { --insp-w: 300px; } }

/* Verktygsfältet: allt får plats ner till 1024 px – det som krymper är namnen, aldrig knapparna */
#topbar { min-width: 0; }
#topbar > * { flex-shrink: 0; }
#topbar > .spacer { flex: 1 1 0; min-width: 0; }
#topbar > .doc-source { flex: 0 1 auto; min-width: 118px; max-width: 330px; }
@media (max-width: 1400px) { #topbar > .doc-source { max-width: 290px; } }
#save-state { display: block; flex: 0 1 auto !important; min-width: 0; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
#save-state .cloud-dot { display: inline-block; vertical-align: middle; margin: -2px 6px 0 0; }
.doc-source .ds-dirty { white-space: nowrap; }
.doc-source .dd-short { display: none; }
@media (max-width: 1100px) {
  .doc-source .dd-long { display: none; }
  .doc-source .dd-short { display: inline; }
}
@media (max-width: 1320px) {   /* 1320: plats för "Visningssida · Höst 2026" */
  .brand-name { display: none; }
  .brand { margin-right: 0; }
}
@media (max-width: 1100px) {
  #topbar { gap: 8px; padding: 0 10px 0 12px; }
  .tb-group { padding: 0 5px; }
  #mode-seg button svg { display: none; }
  #mode-seg button { padding: 5px 10px; }
  .print-pdf { display: none; }
  #topbar > .doc-source { max-width: 250px; }
  #save-state { max-width: 130px; }
  /* Visningssida-knappen (om den finns) blir bara ikon */
  #topbar .btn-viewpage { gap: 0; padding-left: 8px; padding-right: 8px; }
  #topbar .btn-viewpage > span { display: none; }
}

/* Zoom: liten list i arbetsytans nedre högra hörn */
.zoom-pill {
  position: fixed; right: calc(var(--insp-w) + 18px); bottom: 18px; z-index: 16;
  display: flex; align-items: center; gap: 1px; padding: 3px;
  background: rgba(255, 255, 255, .96); border: 1px solid var(--ui-border); border-radius: 11px;
  box-shadow: 0 4px 14px rgba(20, 40, 60, .12);
}
.zoom-pill .btn-icon { width: 30px; height: 30px; border-radius: 8px; }
.zoom-pill .btn-icon svg { width: 16px; height: 16px; }
.zoom-pill #zoom-val { min-width: 44px; }
.zp-sep { width: 1px; height: 18px; background: var(--ui-border); margin: 0 3px; }
body.printing .zoom-pill { display: none; }
#toasts { bottom: 66px; }   /* ovanför zoomlisten */

/* Avsnittets verktyg: en smal list i marginalen bredvid sidan (editor.js placerar den) */
.sec-bar {
  position: absolute; z-index: 14;
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 3px;
  background: #fff; border: 1px solid var(--ui-border-strong); border-radius: 10px;
  box-shadow: 0 6px 18px rgba(20, 40, 60, .16);
  font-family: var(--ui-font);
}
.sec-bar[hidden] { display: none; }
/* Osynlig brygga över till avsnittet så att listen inte försvinner på vägen dit */
.sec-bar::after { content: ''; position: absolute; top: 0; bottom: 0; left: 100%; width: var(--bridge, 10px); }
.sec-bar.side-right::after { left: auto; right: 100%; }
.sec-bar button {
  all: unset; box-sizing: border-box; cursor: pointer; width: 28px; height: 28px; border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center; color: #3b4754;
}
.sec-bar button svg { width: 16px; height: 16px; }
.sec-bar button:hover { background: #EEF3F8; color: var(--ui-accent); }
.sec-bar button:focus-visible { outline: 2px solid var(--ui-accent); outline-offset: -2px; }
.sec-bar button.danger:hover { background: #FDECEC; color: var(--ui-danger); }
.sec-bar button.on { background: var(--ui-accent-soft); color: var(--ui-accent); }
.sec-bar button:disabled { opacity: .3; cursor: default; background: none; color: #3b4754; }
.sec-bar .grip { cursor: grab; color: #94A3B8; height: 20px; }
.sec-bar .sep { height: 1px; align-self: stretch; background: #E5E9EF; margin: 3px 4px; }
body.mode-preview .sec-bar, body.printing .sec-bar { display: none !important; }

/* Hopp från sidlistan: sidans rubrik landar under tipsraden (--hint-h sätts av App.selectPage) */
#hintbar { left: 0; }   /* följer inte med när sidan rullas i sidled (inzoomat) */
#canvas .sheet { scroll-margin-top: calc((var(--hint-h, 0px) + 16px) * var(--zi, 1)); }

/* Sidlistan: förminskad text i klartext */
.pl-sub.pl-fit { color: var(--ui-warn-fg); font-weight: 600; }
.pl-sub.pl-fit.bad { color: var(--ui-danger); }

/* Kem & utrustning: synliga etiketter på valen */
.reg-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.reg-field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.reg-field > span { font-size: 11px; font-weight: 600; color: var(--ui-muted); }
.reg-field .input { height: 30px; font-size: 12.5px; padding: 0 6px; }

/* Lägg till avsnitt: var avsnittet redan finns */
.lib-where { font-size: 11px; color: #3b4754; margin-top: 1px; }
.popover .lib-empty { width: 100%; margin-top: 8px; }
.popover .lib { margin-top: 2px; }

/* Inspektörens flikar bryts aldrig på två rader */
#insp-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
#insp-tabs button { white-space: nowrap; flex: none; }
@media (max-width: 1100px) {
  #insp-tabs { padding: 10px 8px 0; }
  #insp-tabs button { padding: 8px 7px 10px; font-size: 12px; }
  .pl-num { display: none; }
  #page-list li { gap: 8px; }
}

/* Utskrift: redigeringsverktygen syns aldrig på papperet */
@media print {
  .zoom-pill, .sec-bar { display: none !important; }
  .sec.bar-on { outline: none !important; }
}
