/* Left column: template list, wordmark, theme toggle */

#sidebar {
  background: var(--surface2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-height: 0; min-width: 0;
  overflow: hidden;          /* clip content while the width animates */
  white-space: nowrap;
}
/* fixed-height head in both states so the icons below keep their vertical position */
.side-head {
  flex: none; height: 48px;
  padding: 0 10px 0 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
}
/* the wordmark doubles as a "home" button: clears the selection and shows the
   welcome state in-app (no separate welcome.html). Reset the native button look. */
.side-brand {
  display: block; text-decoration: none; color: inherit;
  background: none; border: 0; padding: 0; margin: 0; font: inherit;
  text-align: left; cursor: pointer;
}
.wordmark {
  font-family: var(--mono); font-size: 15px; font-weight: 700; letter-spacing: -.4px;
}
.wordmark em { font-style: normal; color: var(--accent); }
.new-btn {
  margin: 8px 12px 4px;
  padding: 6px 10px;
  border: 1px dashed var(--border-strong);
  border-radius: 7px;
  color: var(--muted);
  text-align: left;
  transition: border-color .12s, color .12s;
}
.new-btn:hover { border-color: var(--accent); color: var(--accent-ink); }
.new-btn[disabled] { opacity: .45; cursor: default; }
.new-btn[disabled]:hover { border-color: var(--border-strong); color: var(--muted); }
.new-btn-icon { display: none; }
.side-label {
  padding: 14px 16px 6px;
  font-size: 10px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  color: var(--faint);
}
#tplList { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.tpl-item {
  display: block; width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  margin-bottom: 2px;
  position: relative;
  cursor: pointer;
}
.tpl-item:hover { background: var(--sel); }
.tpl-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* hover actions (edit + delete), top-right; hidden until the row is hovered */
.tpl-acts {
  position: absolute; top: 6px; right: 6px;
  visibility: hidden;
  display: inline-flex; gap: 2px;
}
.tpl-item:hover .tpl-acts, .tpl-item:focus-within .tpl-acts { visibility: visible; }
.tpl-act {
  width: 19px; height: 19px; border-radius: 5px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.tpl-edit:hover { background: var(--sel); color: var(--ink); }
.tpl-del:hover { background: var(--danger-soft); color: var(--danger); }
.tpl-item.active { background: var(--surface); border-color: var(--border); box-shadow: 0 1px 2px rgba(0,0,0,.04); }
/* both lines must stay on one line and clip — long document-type names
   (CashRegisterCorrectionChequeAddition) overflowed the sidebar before */
.tpl-item .nm { font-weight: 550; display: flex; align-items: center; gap: 7px; padding-right: 46px; min-width: 0; }
.tpl-item .nm .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); flex: none; }
.tpl-item .nm .dot.ok { background: var(--accent); }
.tpl-item .nm .dot.err { background: var(--danger); }
.tpl-item .nm-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* flex like .nm so the inner .sub-text is a padding-free clip box the auto-width
   can measure exactly (same as .nm-text) */
.tpl-item .sub {
  color: var(--muted); font-size: 11.5px; margin-top: 2px; padding-left: 13px; padding-right: 46px;
  display: flex; align-items: center; min-width: 0;
}
.tpl-item .sub-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* unsaved/modified indicator: a compact amber dot (a "не сохранён" tooltip
   carries the meaning), not a long label that crowds the row */
.tpl-item .dirty {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--warn); margin-left: 6px; vertical-align: middle;
}
/* workspace switcher at the bottom of the sidebar */
.ws-bar {
  position: relative; flex: none;
  border-top: 1px solid var(--border);
  padding: 8px;
  display: flex; align-items: center; gap: 2px;
}
.ws-btn {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 8px;
  text-align: left;
}
.ws-btn:hover { background: var(--sel); }
.ws-avatar {
  flex: none; width: 24px; height: 24px; border-radius: 7px;
  background: var(--accent-soft); color: var(--accent-ink);
  font-size: 10.5px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.ws-name {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 550; font-size: 12.5px;
}
.ws-menu {
  position: fixed; min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 9px;
  box-shadow: var(--shadow);
  padding: 4px; z-index: 90;
}
.ws-mi {
  display: block; width: 100%; text-align: left;
  padding: 7px 9px; border-radius: 6px; font-size: 12px;
}
.ws-mi:hover { background: var(--sel); }
.ws-mi.danger { color: var(--danger); }
.ws-mi.danger:hover { background: var(--danger-soft); }
.ws-div { height: 1px; background: var(--border); margin: 4px 6px; }

.side-foot {
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between;
  color: var(--faint); font-family: var(--mono); font-size: 10.5px;
}
.icon-btn {
  width: 26px; height: 26px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px;
}
.icon-btn:hover { background: var(--sel); color: var(--ink); }

/* collapsed sidebar: narrow rail with toggle, new-template and theme icons.
   .side-head keeps its 48px height and .new-btn its 8px top margin in both
   states so the icons do not jump vertically on collapse/expand. */
body.side-collapsed { --side-w: 42px; }
body.side-collapsed #sidebar { align-items: center; }
body.side-collapsed .side-head {
  padding: 0; justify-content: center; width: 100%;
}
body.side-collapsed .side-brand,
body.side-collapsed .side-label,
body.side-collapsed #tplList,
body.side-collapsed .side-foot > span { display: none; }
body.side-collapsed #sideToggle svg { transform: scaleX(-1); }
body.side-collapsed .new-btn {
  margin: 8px 0 4px; padding: 0; width: 28px; height: 28px;
  border-radius: 6px; border: 1px dashed var(--border-strong);
  display: flex; align-items: center; justify-content: center;
}
body.side-collapsed .new-btn-label { display: none; }
body.side-collapsed .new-btn-icon { display: block; font-size: 15px; line-height: 1; }
/* collapsed: theme icon stacks above the avatar (column-reverse), so the
   workspace avatar keeps its bottom-anchored vertical position */
body.side-collapsed .ws-bar {
  border-top: none; padding: 8px 4px; margin-top: auto; width: 100%;
  flex-direction: column-reverse; gap: 6px; align-items: center;
}
body.side-collapsed .ws-btn { flex: none; justify-content: center; padding: 6px 4px; }
body.side-collapsed .ws-name,
body.side-collapsed .ws-btn .dd-arr { display: none; }
body.side-collapsed .side-foot {
  border-top: none; padding: 0; margin-bottom: 8px;
  justify-content: center; width: 100%;
}
