:root {
  --bg: #14161a;
  --bg2: #1b1f25;
  --bg3: #232830;
  --line: #2f3540;
  --fg: #e6e9ef;
  --muted: #8b94a3;
  --accent: #4da3ff;
  --ok: #38c172;
  --danger: #e05561;
  --pano: #7c5cff;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
}
button {
  background: var(--bg3); color: var(--fg); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 11px; font: inherit; cursor: pointer;
}
button:hover { border-color: #46505f; background: #2b313b; }
button.primary { border-color: #2b6cb0; background: #1d3a5a; }
button.danger { border-color: #6d2b31; background: #3a1d21; color: #ffb3b8; }
button.icon { padding: 4px 9px; }
button:disabled { opacity: .45; cursor: not-allowed; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

header {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; background: var(--bg2); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; letter-spacing: .2px; }
.brand .root { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; }
.crumbs { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; color: var(--muted); }
.crumbs a { color: var(--fg); text-decoration: none; padding: 2px 5px; border-radius: 4px; }
.crumbs a:hover { background: var(--bg3); }
.cap { font-size: 12px; color: var(--muted); }
.cap.bad { color: #d8a33c; }

main { flex: 1; display: flex; min-height: 0; }
.tree {
  width: 300px; min-width: 220px; border-right: 1px solid var(--line);
  background: var(--bg2); display: flex; flex-direction: column; min-height: 0;
}
.tree-head { padding: 10px 14px; font-size: 12px; text-transform: uppercase; color: var(--muted); }
.tree-body { overflow: auto; padding: 0 6px 18px; }
.node { }
.node > .row {
  display: flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 5px;
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.node > .row:hover { background: var(--bg3); }
.node > .row.current { background: #1d3a5a; }
.node > .row .tw { width: 14px; color: var(--muted); font-size: 11px; }
.node > .row .n { color: var(--muted); font-size: 11px; margin-left: auto; }
.node .kids { margin-left: 12px; border-left: 1px solid var(--line); }

.content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.toolbar {
  display: flex; gap: 8px; align-items: center; padding: 10px 16px;
  border-bottom: 1px solid var(--line); background: var(--bg2); flex-wrap: wrap;
}
.divider { width: 1px; height: 22px; background: var(--line); }
.progress { position: relative; height: 6px; background: var(--bg3); }
.progress .bar { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); }
.progress .label { position: absolute; right: 8px; top: 8px; font-size: 12px; color: var(--muted); }

.folders { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px 0; }
.folder {
  border: 1px solid var(--line); background: var(--bg2); border-radius: 6px;
  padding: 6px 10px; cursor: pointer; display: flex; gap: 8px; align-items: center;
}
.folder:hover { border-color: #46505f; }
.folder .n { color: var(--muted); font-size: 11px; }

.grid {
  display: grid; gap: 14px; padding: 16px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); overflow: auto;
}
.card {
  position: relative; background: var(--bg2); border: 1px solid var(--line);
  border-radius: 8px; overflow: hidden; display: flex; flex-direction: column;
}
.card.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.card .shot {
  aspect-ratio: 16 / 9; background: #0d0f12 center/contain no-repeat; cursor: zoom-in;
  display: flex; align-items: center; justify-content: center;
}
.card .shot img { max-width: 100%; max-height: 100%; display: block; }
.card .meta { padding: 8px 10px; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.card .meta .label { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .meta .sub { color: var(--muted); font-size: 11px; }
.card .badge {
  font-size: 10px; letter-spacing: .4px; text-transform: uppercase; padding: 2px 6px;
  border-radius: 4px; border: 1px solid var(--line); color: var(--muted);
}
.card .badge.pano { color: #cbb9ff; border-color: #4a3a86; background: #241d3d; }
.card .badge.single { color: #a9d8ff; border-color: #2b567f; background: #16293b; }
.card .warn { color: #d8a33c; font-size: 11px; padding: 0 10px 8px; }
.chip {
  position: absolute; z-index: 2; top: 8px; left: 38px; font-size: 10px; letter-spacing: .4px;
  text-transform: uppercase; padding: 3px 7px; border-radius: 5px; border: 1px solid #2b6b45;
  background: #16321f; color: #8ff0b5; pointer-events: none;
}
.chip.crop { border-color: #7a6a2b; background: #322c16; color: #f0d88f; }
.chip.note { left: auto; right: 8px; top: 34px; border-color: #3a4f7a; background: #16233b;
  color: #a9c8ff; }
.mode { font-size: 11px; padding: 3px 8px; border-radius: 5px; border: 1px solid var(--line);
  color: var(--muted); }
.mode.hdr { border-color: #2b6b45; background: #16321f; color: #8ff0b5; }
.notes { border-top: 1px solid var(--line); padding: 10px 14px 14px; }
.notes-head { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.notelist { max-height: 180px; overflow: auto; font-size: 12px; }
.notelist .n { border-left: 2px solid #3a4f7a; padding: 4px 8px; margin: 6px 0;
  background: #161c26; border-radius: 0 5px 5px 0; white-space: pre-wrap; }
.notelist .n .when { display: block; color: var(--muted); font-size: 10px; margin-top: 3px; }
.notelist .n .x { float: right; cursor: pointer; color: var(--muted); padding: 0 3px; }
.info textarea { width: 100%; margin-top: 8px; background: var(--bg2); color: var(--fg);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: inherit; resize: vertical; }
.chip .deg { text-transform: none; letter-spacing: 0; }
.card .check {
  position: absolute; top: 8px; left: 8px; width: 22px; height: 22px; z-index: 2;
  appearance: none; border-radius: 5px; border: 1px solid #7a8496; background: #000a;
  cursor: pointer;
}
.card .check:checked { background: var(--accent); border-color: var(--accent); }
.card .check:checked::after {
  content: "✓"; position: absolute; inset: 0; color: #06121f; font-size: 15px;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.card .open {
  position: absolute; top: 8px; right: 8px; z-index: 2; font-size: 11px; padding: 3px 7px;
  background: #000a; border: 1px solid #7a8496; border-radius: 5px; color: var(--fg);
}
.empty { padding: 40px 16px; color: var(--muted); }

.overlay {
  position: fixed; inset: 0; background: #000c; display: flex; align-items: center;
  justify-content: center; z-index: 20; backdrop-filter: blur(2px);
}
/* The preview takes ~80% of the window in both directions: the panorama is the subject and the
   levelling controls need the room beside it. Capped so it does not sprawl on a very large screen. */
.panel {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  width: 80vw; height: 80vh; max-width: 2400px; max-height: 1400px;
  display: flex; flex-direction: column; overflow: hidden;
}
.panel-head {
  display: flex; gap: 10px; align-items: center; padding: 10px 14px;
  border-bottom: 1px solid var(--line); background: var(--bg2);
}
.panel-body { display: flex; min-height: 0; flex: 1; }
.stage-wrap { flex: 1; position: relative; display: flex; min-width: 0; overflow: hidden; }
.stage { flex: 1; display: flex; align-items: center; justify-content: center; padding: 12px; min-width: 0; }
/* max-width/max-height CAP the picture but never enlarge it, so a source smaller than the stage (a
   heavy crop, a small panorama, or a preview file under the window width) sat at its natural size in
   the middle of a much bigger stage. A definite 100%/100% box with object-fit: contain makes the
   picture as large as the stage allows in both directions, whether that means shrinking or growing. */
.stage img { width: 100%; height: 100%; object-fit: contain; background: #0a0c0f; }
.rot { position: relative; }
/* The picture rotates in place; the scale keeps the WHOLE rotated frame inside the stage, which is
   what makes a horizon judgeable. Nothing is cropped while levelling - that is what Crop is for. */
.stage .rot { display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;                 /* definite size, so the picture can be capped by it */
  transform-origin: 50% 50%; transition: transform .06s linear; }

.leveller { border-top: 1px solid var(--line); padding: 10px 14px; }
.leveller .lev-head { display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12px; color: var(--muted); }
.leveller .degread { font-size: 15px; color: var(--fg); font-variant-numeric: tabular-nums; }
.leveller input[type=range] { width: 100%; margin: 6px 0; }
.leveller .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.leveller .small { font-size: 11px; color: var(--muted); }
.leveller .plan { margin: 6px 0 0; }
.infocol { width: 340px; border-left: 1px solid var(--line); display: flex; flex-direction: column;
  min-height: 0; }
.info { padding: 12px 14px 4px; overflow: auto; font-size: 13px; flex: 1; min-height: 0; }
.info dt { color: var(--muted); font-size: 11px; text-transform: uppercase; margin-top: 10px; }
.info dd { margin: 2px 0 0; word-break: break-all; }
.info a { color: var(--accent); }
.info .row { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* The levelling window is where the work is done, so it takes the screen rather than sitting in a
   1600px box: the panorama is the subject and every pixel of height helps judge a horizon. */

.controls .row { display: flex; gap: 6px; margin: 10px 0; flex-wrap: wrap; }
.controls label { display: block; }
.plan { font-size: 12px; color: var(--muted); margin: 10px 0; white-space: pre-line; }
.hint { color: var(--muted); font-size: 12px; }
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 16px; z-index: 40; max-width: 70vw; font-size: 13px;
}
.toast.busy { border-color: #2f4f6d; background: #16212e; color: #cfe4f7; }
.toast.err { border-color: #6d2b31; background: #3a1d21; color: #ffb3b8; }
.toast.ok { border-color: #2b6b45; background: #16321f; }

/* full screen, and back - the same panel, just filling the window */
.panel.full { width: 100vw; height: 100vh; max-width: none; max-height: none; border-radius: 0;
  border: 0; }

.queue {
  position: fixed; top: 56px; right: 0; bottom: 0; width: 340px; z-index: 40;
  background: var(--bg2); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; box-shadow: -12px 0 24px rgba(0,0,0,.35);
}
.queue-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--line); font-weight: 600; }
.queue-summary { padding: 10px 12px; font-size: 12px; color: var(--muted);
  border-bottom: 1px solid var(--line); white-space: pre-line; }
.queue-running { padding: 0 12px; font-size: 12px; color: var(--muted); }
.queue-running:not(:empty) { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.queue-list { flex: 1; overflow: auto; }
.queue-item { display: flex; gap: 8px; align-items: baseline; padding: 8px 12px;
  border-bottom: 1px solid var(--line); cursor: pointer; font-size: 13px; }
.queue-item:hover { background: #1b2129; }
.queue-item .g { font-weight: 600; min-width: 52px; }
.queue-item .fam { color: var(--muted); font-size: 11px; margin-left: auto; }
.queue-item .note { color: #d8b25a; font-size: 11px; }
.queue-empty { padding: 14px 12px; color: var(--muted); font-size: 13px; }
.queue-foot { padding: 8px 12px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); }

/* the full-screen button must never be mistaken for the close button beside it */
#d-full.restore { color: var(--fg); }
#d-full { font-size: 15px; line-height: 1; }

.tree-legend { padding: 0 14px 10px; font-size: 11px; line-height: 1.35; color: var(--muted); }
.tree-legend b { color: var(--fg); font-weight: 600; }

/* the draggable crop window: rides inside the rotating wrapper, so it turns with the picture */
.rot { position: relative; }
.rot canvas.straightened { display: block; background: #0a0c0f; }
.stage img.hidden, .stage canvas.hidden { display: none; }
/* The stroke is drawn OUTSIDE the box (a shadow, not a border): a border eats 1.5 px of the picture and
   makes a correctly placed crop look that much inside the edge. */
.cropbox {
  position: absolute; cursor: move; box-sizing: content-box; touch-action: none;
  box-shadow: 0 0 0 1.5px rgba(77,163,255,.95), inset 0 0 0 1px rgba(0,0,0,.35);
  transition: box-shadow .1s linear;
}
.cropbox.bad { box-shadow: 0 0 0 1.5px #e2604a, inset 0 0 0 1px rgba(0,0,0,.35); }
/* Grips sit INSIDE the outline: on the frame edge they used to hang half outside the picture, which
   made the suggested crop look like it was outside the image. */
.cropbox .grip { position: absolute; width: 12px; height: 12px; background: rgba(77,163,255,.95);
  border: 1px solid #0a0c0f; border-radius: 2px; box-sizing: border-box; }
.lastaction { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.lastaction.live { color: #7ec98f; }
.cropbox.bad .grip { background: #e2604a; }
.cropbox .grip.nw { left: 0; top: 0; cursor: nwse-resize; }
.cropbox .grip.n  { left: calc(50% - 6px); top: 0; cursor: ns-resize; }
.cropbox .grip.ne { right: 0; top: 0; cursor: nesw-resize; }
.cropbox .grip.e  { right: 0; top: calc(50% - 6px); cursor: ew-resize; }
.cropbox .grip.se { right: 0; bottom: 0; cursor: nwse-resize; }
.cropbox .grip.s  { left: calc(50% - 6px); bottom: 0; cursor: ns-resize; }
.cropbox .grip.sw { left: 0; bottom: 0; cursor: nesw-resize; }
.cropbox .grip.w  { left: 0; top: calc(50% - 6px); cursor: ew-resize; }

/* amber means the crop is the owner's, blue means it is the app's suggestion */
.cropbox.custom { box-shadow: 0 0 0 1.5px #d8b25a, inset 0 0 0 1px rgba(0,0,0,.35); }
.cropbox.custom .grip { background: #d8b25a; }

/* which server build this tab is talking to - a stale tab should be obvious, not argued about */
.build { position: fixed; right: 8px; bottom: 6px; font-size: 11px; color: #5a6470;
  pointer-events: none; z-index: 30; }

.check { font-size: 11px; color: #5f7a8a; margin: 2px 0 0; }
.check.warn { color: #e2604a; }

#d-crop.busy { opacity: .75; }

.leveller button.reset { min-width: 58px; font-weight: 600; }

/* The amount a picture was levelled by, and the way back, on the line that says it. */
.levelinfo { display: none; }
.levelinfo.on {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 6px 0 2px; padding: 5px 8px; border-radius: 6px;
  background: rgba(255, 196, 0, 0.10); border: 1px solid rgba(255, 196, 0, 0.35);
  color: #ffd166; font-size: 12px;
}
.levelinfo.on .leveltext { flex: 1 1 220px; }
.levelinfo.on button.undolevel {
  background: rgba(255, 196, 0, 0.16); border: 1px solid rgba(255, 196, 0, 0.5);
  color: #ffd166; font-size: 12px; padding: 3px 9px; border-radius: 5px; cursor: pointer;
}
.levelinfo.on button.undolevel:hover { background: rgba(255, 196, 0, 0.28); }
.levelinfo.on button.undolevel:disabled { opacity: 0.6; cursor: default; }

/* Thirds inside the crop window: the horizon is judged against the crop that will be delivered. Two
   hairlines each way, drawn with a dark shadow so they read on both a bright sky and a dark foreground. */
.cropbox .thirds { position: absolute; inset: 0; pointer-events: none; }
.cropbox .thirds i {
  position: absolute; background: rgba(150, 200, 255, 0.75);
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.45);
}
.cropbox .thirds i.v { top: 0; bottom: 0; width: 1px; }
.cropbox .thirds i.h { left: 0; right: 0; height: 1px; }
.cropbox .thirds i.v1 { left: 33.333%; }
.cropbox .thirds i.v2 { left: 66.666%; }
.cropbox .thirds i.h1 { top: 33.333%; }
.cropbox .thirds i.h2 { top: 66.666%; }

/* The panel's info block: a glance, not a data dump. */
#d-info dd.filelinks { display: flex; gap: 10px; }
#d-info dd.filelinks a { color: #8fc4ff; text-decoration: none; font-size: 12px; }
#d-info dd.filelinks a:hover { text-decoration: underline; }
#d-info details.more { grid-column: 1 / -1; margin-top: 4px; }
#d-info details.more summary {
  cursor: pointer; color: var(--muted); font-size: 11px; letter-spacing: .04em;
  text-transform: uppercase; list-style: none;
}
#d-info details.more summary::marker { content: ''; }
#d-info details.more .morebody {
  margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all;
}
