:root {
  --ink: #1c2430;
  --navy: #001b58;
  --navy-2: #173c5d;
  --red: #8c1515;
  --paper: #f6f3ec;
  --desk: #d7d0c4;
  --line: #d9d1c4;
  --ribbon: #fbfaf7;
  --muted: #5c6778;
  --ok: #2d6a4f;
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--desk);
}

body {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

button, select, input { font: inherit; color: inherit; }

.ribbon {
  background: linear-gradient(#ffffff, #f3f2f1 42%, #e6e6e6);
  border-bottom: 1px solid #b4b4b4;
  color: #444;
}


.ribbon-tab {
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  gap: 0;
  width: 100%;
  height: 70px;
  padding: 3px 4px;
  overflow: visible;
}
.cluster {
  display: flex;
  align-items: center;
  gap: 0;
  flex: 0 0 auto;
  height: 100%;
}
.cluster.fields { gap: 2px; }

.ribbon-tab .sep {
  align-self: stretch;
  width: 1px;
  flex: 0 0 1px;
  margin: 4px 3px;
  background: linear-gradient(#ececec, #c4c4c4 35%, #c4c4c4 65%, #ececec);
}

.ribbon-tab .large {
  position: relative;
  width: auto;
  min-width: 46px;
  height: 64px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 2px;
  display: grid;
  grid-template-rows: 42px 22px;
  align-items: center;
  justify-items: center;
  gap: 0;
  padding: 0 5px;
  cursor: pointer;
  color: #444;
}
.ribbon-tab .large img,
.ribbon-tab .large svg { width: 32px; height: 32px; object-fit: contain; }
.ribbon-tab .large.pressed { background: #fde7d0; border-color: #e0a15a; }
.ribbon-tab .large span {
  display: block;
  align-self: start;
  padding-top: 1px;
  font-size: 11px;
  font-weight: 400;
  line-height: 13px;
  text-align: center;
  white-space: nowrap;
  color: #444;
}
.ribbon-tab .large:hover:not(:disabled),
.split:hover .large:not(:disabled),
.menu button:hover:not(:disabled) { background: #fde7d0; border-color: #f4c28a; }
.ribbon-tab .large:disabled { opacity: 0.35; cursor: not-allowed; }

.split { position: relative; display: flex; align-items: stretch; }
.split .large { border-radius: 2px; }
.split .chev {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 18px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  cursor: pointer;
  padding: 0;
}
.split .chev::after,
.split:not(:has(> .chev)) .large::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 2px;
  transform: translateX(-50%);
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
  border-top: 3px solid #5c5c5c;
}
.ribbon-tab .large:disabled::after { opacity: 0.35; }

.menu {
  display: none;
  position: absolute;
  top: calc(100% - 2px);
  left: 0;
  z-index: 30;
  min-width: 230px;
  background: #fff;
  border: 1px solid #c8c8c8;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
  padding: 4px;
}
.menu.open { display: block; }
.menu button {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 12px;
  color: #222;
}
.menu button img { width: 24px; height: 24px; }
.menu button:disabled { opacity: 0.35; cursor: not-allowed; }

.upload, .ribbon-tab .stack {
  --lab: 36px;
  --ctl: 168px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 2px;
  height: 64px;
  padding: 0 6px;
  font-size: 11px;
  color: #444;
}
.ribbon-tab .stack.people { --lab: 86px; --ctl: 128px; }
.ribbon-tab .stack.sizes { --lab: 68px; --ctl: 78px; }
.ribbon-tab .upload label,
.ribbon-tab .stack label {
  display: grid;
  grid-template-columns: var(--lab) var(--ctl);
  align-items: center;
  column-gap: 6px;
  height: 20px;
  margin: 0;
  font-size: 11px;
  line-height: 1;
  color: #444;
  white-space: nowrap;
}
.ribbon-tab .upload label > span,
.ribbon-tab .stack label > span { text-align: left; }
.upload input, .upload select, .ribbon-tab .stack select {
  height: 18px;
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 0 2px;
  border: 1px solid #b9b9b9;
  background: #fff;
  border-radius: 2px;
  font-size: 11px;
  color: #222;
}
.upload input { color: #888; }
.ribbon-tab .upload label.check,
.ribbon-tab .stack label.check {
  display: flex;
  grid-template-columns: none;
  gap: 5px;
  align-items: center;
  justify-content: flex-start;
  height: 20px;
  color: #444;
  white-space: nowrap;
}

body[data-stage="empty"] .needs-upload,
body[data-stage="empty"] .needs-import,
body[data-stage="file"] .needs-pick,
body[data-stage="file"] .needs-import,
body[data-stage="ready"] .needs-pick,
body[data-stage="ready"] .needs-upload { display: none !important; }

button.tool, button.tool-wide {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 4px;
  padding: 2px 6px 3px;
  cursor: pointer;
  line-height: 1.1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

button.tool { width: auto; min-width: 62px; }
button.tool-wide { width: auto; min-width: 78px; }
button.tool img, button.tool-wide img { width: 28px; height: 28px; object-fit: contain; }

button.tool:hover, button.tool-wide:hover, button.mini:hover { background: #efe8dc; }

button.tool:disabled, button.tool-wide:disabled { opacity: 0.4; cursor: not-allowed; }

button.tool b, button.tool-wide b {
  display: block;
  font-size: 12px;
  font-weight: 650;
  color: var(--navy);
}

button.tool small, button.tool-wide small {
  display: block;
  font-size: 10px;
  color: var(--muted);
  font-weight: 500;
}

.check input { margin: 0; width: 13px; height: 13px; flex: 0 0 auto; }

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.stage-wrap {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.stage {
  flex: 1;
  min-height: 280px;
  display: grid;
  place-items: center;
  place-items: safe center;
  padding: 18px;
  overflow: auto;
}

.holder { position: relative; overflow: visible; }

.scaler {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: top left;
}

.page {
  position: absolute;
  width: 960px;
  height: 540px;
  background: white;
  box-shadow: 0 12px 40px rgba(40, 32, 20, 0.18);
  pointer-events: none;
}

.slide {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  background: transparent;
  user-select: none;
  touch-action: none;
}

body[data-tool="select"] .slide,
body[data-tool="select"] .holder { cursor: crosshair; }
body[data-tool="scale"] .shape { cursor: nwse-resize; }

.slide svg.wires {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}

.slide svg.wires line { pointer-events: stroke; }

.shape {
  position: absolute;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: grab;
  min-height: 0;
  line-height: 1.1;
}

.shape.selected { outline: 1.5px solid #c45500; outline-offset: 1px; }

.card {
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  /* --padx follows the card size (set in app.js): the text gets the same breathing room on every size. */
  --padx: 6px;
  padding: calc(var(--padx) * 0.75) var(--padx) 0;
}

.card .who { font-weight: 700; line-height: 1.05; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .job { font-weight: 400; opacity: 0.92; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .loc {
  margin: auto calc(var(--padx) * -1) 0;
  padding: 1px var(--padx) 2px;
  font-size: 7px;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  min-height: 11px;
}
.card .loc-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.card .new-badge {
  position: absolute;
  top: 2px;
  right: 3px;
  width: 3.4em;
  padding: 0.15em 0;
  border-radius: 2px;
  background: #ffc61a;
  color: #3d2a00;
  font-size: 0.8em; /* a share of the card's name size, so the badge grows with the card */
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  pointer-events: none;
}
.card .new-badge small { display: block; font-size: 0.9em; font-weight: 600; }
.card .hc.corner { position: absolute; right: var(--padx); bottom: 3px; }
.card .hc {
  position: static;
  flex: none;
  font-size: 7px;
  font-weight: 700;
  line-height: 1;
}

.card.ordinary { background: linear-gradient(#00256e, #00123f); }
.card.ordinary .loc { background: #00102f; }
.card.important { background: linear-gradient(#b00000, #6e0000); }
.card.important .loc { background: #4d0000; }
.card.intern { background: linear-gradient(#ffffff, #e4e4e4); color: #1a1a1a; }
.card.intern .loc { background: white; color: #1a1a1a; }
.card.split {
  background-color: #fff;
  background-image: linear-gradient(to top right, #ffffff 50%, #8c0000 50%);
  color: #1a1a1a;
  box-shadow: inset 0 0 0 1px #1a1a1a;
}
.card.split::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    to top right,
    transparent calc(50% - 0.7px),
    #1a1a1a calc(50% - 0.7px),
    #1a1a1a calc(50% + 0.7px),
    transparent calc(50% + 0.7px)
  );
}
.card.split .hc { color: #fff; }
.card.split .loc { background: #fff; color: #1a1a1a; }
.card.tbh { background: white; color: #001b57; }
.card.tbh .loc { background: #f4f7fb; }
/* A vacancy keeps its flag colors and is marked by a dashed inner outline. */
.card.vacant { outline: 1px dashed #001b57; outline-offset: -2px; }
.card.vacant.ordinary, .card.vacant.important { outline-color: rgba(255, 255, 255, 0.9); }

.bubble, .comment, .link, .nav {
  background: white;
  border-radius: 3px;
  font-size: 8px;
  line-height: 1.15;
  padding: 1px 3px;
  overflow: hidden;
  white-space: nowrap;
  box-shadow: inset 0 0 0 1px #8d867c;
}
.bubble, .comment {
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #001b58;
  font-weight: 700;
  background: #fff;
}
.comment {
  white-space: normal;
  font-size: 7px;
  line-height: 1.15;
  font-weight: 700;
}
.link {
  padding: 0 2px;
  text-align: center;
  background: #9BC225;
  color: #000;
  font-weight: 700;
  box-shadow: 0 1px 1.5px rgba(0, 0, 0, 0.28);
  line-height: 11px;
}
.bubble.dotted { box-shadow: inset 0 0 0 1px #001b58; }
.bubble.dotted { background: repeating-linear-gradient(90deg, white, white 3px, #eef2f8 3px, #eef2f8 4px); }
.nav {
  background: transparent;
  color: var(--navy-2);
  text-align: left;
  box-shadow: none;
  font-size: 11px;
  line-height: 16px;
  text-decoration: underline;
}
.shade {
  border-radius: 2px;
  color: var(--navy-2);
  font-size: 11px;
  line-height: 1.15;
  padding: 0 4px 5px;
  text-align: center;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  white-space: normal;
  overflow: hidden;
}
.frame { box-shadow: inset 0 0 0 1.5px var(--red); background: transparent; }
.title { cursor: grab; }
.title .name { font-size: 26px; font-weight: 700; color: var(--navy); line-height: 1.05; }
.title .dept { font-size: 16px; color: #3d4d66; }
.legend { font-size: 11px; display: flex; flex-direction: column; gap: 2px; color: var(--ink); }
.legend-title { font-size: 11px; font-weight: 700; color: var(--muted); }
.stats {
  background: #f3f3f3;
  border: 1px solid #c8c8c8;
  border-radius: 3px;
  color: var(--ink);
  text-align: left;
  padding: 6px 8px;
  cursor: grab;
}
.hiddenlist {
  color: #8a8f98;
  font-size: 8px;
  line-height: 10px;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: grab;
  overflow: hidden;
}
.stats-title { font-size: 11px; font-weight: 700; margin-bottom: 3px; }
.stats ul { margin: 0; padding-left: 14px; }
.stats li { font-size: 10px; line-height: 1.25; }
.legend i {
  display: inline-block;
  width: 14px;
  height: 9px;
  margin-right: 6px;
  vertical-align: -1px;
}
.legend .ordinary { background: #001b58; }
.legend .important { background: #8c0000; }
.legend .intern { background: #e6e6e6; box-shadow: inset 0 0 0 1px #bbb; }

.marquee {
  position: absolute;
  border: 1px solid #c45500;
  background: rgba(196, 85, 0, 0.12);
  pointer-events: none;
  z-index: 9;
}

.selection-frame {
  position: absolute;
  border: 1px dashed #c45500;
  pointer-events: none;
  z-index: 8;
}
.scale-handle {
  position: absolute;
  background: #c45500;
  border: 1px solid white;
  border-radius: 1px;
  cursor: nwse-resize;
  pointer-events: auto;
  padding: 0;
}

.cc {
  background: #00ff00;
  color: #083008;
  font-weight: 700;
  overflow: hidden;
  white-space: nowrap;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: inset 0 0 0 1px #0b6b0b;
}

.empty-slide {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  padding: 40px;
  pointer-events: none;
}
.empty-slide strong { color: var(--navy); display: block; font-size: 22px; margin-bottom: 6px; }

.filmstrip {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  background: #cfc6b8;
  overflow-x: auto;
}
.filmstrip .slide-tab {
  position: relative;
  display: flex;
  align-items: stretch;
  background: white;
  min-width: 156px;
  border: 1px solid transparent;
  border-radius: 3px;
}
.filmstrip .slide-tab.active { border-color: var(--navy); box-shadow: 0 0 0 1px var(--navy); }
.filmstrip .open {
  flex: 1;
  min-width: 112px;
  text-align: left;
  padding: 6px 8px 6px 8px;
  cursor: pointer;
  background: transparent;
  border: 0;
}
.filmstrip b { display: block; font-size: 12px; }
.filmstrip small { display: block; color: var(--muted); }
.filmstrip .slide-actions {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 4px 4px 4px 0;
}
.filmstrip .slide-mini {
  width: 18px;
  height: 16px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  padding: 0;
  font-size: 12px;
}
.filmstrip .slide-mini:hover { background: #efe6d8; color: var(--navy); }
.filmstrip .slide-mini.danger:hover { background: #f3d6d6; color: var(--red); }
.filmstrip input.slide-name {
  display: block;
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--navy);
  border-radius: 2px;
  font-weight: 700;
  font-size: 12px;
  padding: 0 2px;
  margin-bottom: 2px;
}

.issue { color: var(--red); }
.ok { color: var(--ok); }

.export { display: flex; gap: 4px; align-items: center; }
.export .mini { padding: 0 8px; }
.status {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 12px 6px;
  font-size: 12px;
  color: var(--muted);
  background: #efeae2;
  border-top: 1px solid #e4dccc;
}

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 5;
}
.toast.show { opacity: 1; }

.zoom { display: flex; gap: 4px; align-items: center; }
button.mini {
  border: 1px solid #cfc6b8;
  background: white;
  border-radius: 3px;
  height: 22px;
  min-width: 22px;
  cursor: pointer;
}

@media (max-width: 900px) {
  .stage { padding: 10px; }
}

/* ---- Sheet editor dialog ---- */
.sheet-dialog[hidden] { display: none; }
.sheet-dialog {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(20, 28, 40, 0.55);
  display: grid;
  place-items: center;
  padding: 24px;
}
.sheet-panel {
  background: #fff;
  width: min(1480px, 100%);
  height: min(860px, 100%);
  display: flex;
  flex-direction: column;
  border-radius: 6px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.sheet-head, .sheet-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--ribbon);
  flex: 0 0 auto;
}
.sheet-head { border-bottom: 1px solid var(--line); }
.sheet-foot { border-top: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 16px; color: var(--navy); }
.sheet-sub, .sheet-hint { color: var(--muted); font-size: 12px; }
.sheet-dialog .spacer { flex: 1; }
.sheet-dialog button {
  border: 1px solid #b9b2a4;
  background: #fff;
  border-radius: 3px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 12px;
}
.sheet-dialog button:hover:not(:disabled) { background: #fde7d0; border-color: #f4c28a; }
.sheet-dialog button.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.sheet-dialog button.primary:hover:not(:disabled) { background: #0a2f7a; }
.sheet-dialog button:disabled { opacity: 0.4; cursor: not-allowed; }
#sheet-filter { border: 1px solid #b9b2a4; border-radius: 3px; padding: 4px 8px; font-size: 12px; width: 170px; margin-left: 8px; }
.sheet-grid-wrap { flex: 1 1 auto; overflow: auto; min-height: 0; }
.sheet-grid { border-collapse: separate; border-spacing: 0; font-size: 12px; width: max-content; min-width: 100%; }
.sheet-grid th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #efeae2;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid #e4dccc;
  padding: 6px 6px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  color: var(--navy-2);
}
.sheet-grid td { border-bottom: 1px solid #eee8dc; border-right: 1px solid #f1ece2; padding: 0; }
.sheet-grid th.sortable { cursor: pointer; user-select: none; }
.sheet-grid th.sortable:hover { background: #e6dfd2; }
.sheet-grid th.sortable:focus-visible { outline: 2px solid #e0a15a; outline-offset: -2px; }
.sheet-grid .sort-ind { display: inline-block; min-width: 12px; margin-left: 4px; font-size: 10px; color: #b8b0a0; }
.sheet-grid .sort-ind.on { color: #c45500; }
.sheet-sort { display: inline-flex; align-items: center; gap: 6px; margin-left: 10px; padding-left: 10px; border-left: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.sheet-sort select { border: 1px solid #b9b2a4; border-radius: 3px; padding: 4px 6px; font-size: 12px; max-width: 190px; background: #fff; }
.sheet-dialog .sheet-sort button.on { background: #fde7d0; border-color: #e0a15a; font-weight: 600; }
.sheet-grid td.num, .sheet-grid th.num {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #faf8f3;
  color: var(--muted);
  text-align: right;
  padding: 0 8px;
  width: 46px;
  min-width: 46px;
  box-sizing: border-box;
}
.sheet-grid th.num { z-index: 3; background: #efeae2; }
/* Surname stays in view while scrolling across to the flag columns. */
.sheet-grid td:nth-child(2), .sheet-grid th:nth-child(2) {
  position: sticky;
  left: 46px;
  z-index: 1;
  background: #fff;
  box-shadow: 1px 0 0 #d9d1c4;
}
.sheet-grid th:nth-child(2) { z-index: 3; background: #efeae2; }
.sheet-grid tr:hover td:nth-child(2) { background: #fbf9f4; }
.sheet-grid tr.bad td:nth-child(2) { background: #fdecec; }
.sheet-grid td input[type="text"] {
  width: 130px;
  border: 0;
  background: transparent;
  padding: 6px 6px;
  font-size: 12px;
  outline: none;
}
.sheet-grid td:nth-child(4) input[type="text"],
.sheet-grid td:nth-child(10) input[type="text"] { width: 150px; }
.sheet-grid td input[type="text"]:focus { background: #fff6e8; box-shadow: inset 0 0 0 2px #e0a15a; }
.sheet-grid td.flag { text-align: center; width: 80px; }
.sheet-grid tr:hover td { background: #fbf9f4; }
.sheet-grid tr.bad td { background: #fdecec; }
.sheet-grid tr.bad td.num { color: #8c1515; font-weight: 700; }
.sheet-grid td.del { padding: 0 4px; text-align: center; }
.sheet-dialog .row-del { border: 0; background: transparent; color: #8c1515; font-size: 16px; padding: 0 6px; line-height: 1.4; }
.sheet-issues { flex: 0 0 auto; max-height: 110px; overflow: auto; padding: 6px 14px; border-top: 1px solid var(--line); font-size: 12px; }
.sheet-issues p, .sheet-issues ul { margin: 2px 0; }
.sheet-issues ul { padding-left: 18px; }
.sheet-issues .ok { color: var(--ok); }
.sheet-issues .issue { color: #8c1515; }
body.sheet-open { overflow: hidden; }

.import-problem {
  max-width: 260px;
  margin-left: 6px;
  padding: 4px 8px;
  border: 1px solid #e0a0a0;
  border-radius: 3px;
  background: #fdecec;
  color: #8c1515;
  font-size: 11px;
  line-height: 1.25;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}
.import-problem[hidden] { display: none; }
.status .warn { color: var(--red); }
