:root {
  /* Dark is the default, matching the AECObank pane. */
  --bg: #1e2024;
  --surface: #26292e;
  --surface-2: #2d3136;
  --text: #e7e9ec;
  --muted: #9aa0a8;
  --line: #3a3f46;
  --accent: #4aa3ff;
  --accent-dark: #2f8fe6;
  --brand: #b7f000;         /* AECOtech green */
  --brand-ink: #14160f;     /* near-black text on green */
  --open: #ff5b52;
  --progress: #f5a623;
  --review: #b07bff;
  --closed: #4caf50;
  /* Pills: dark = black bg / green text inactive, green bg / black text active. */
  --pill-bg: #000000;
  --pill-fg: var(--brand);
  --pill-active-bg: var(--brand);
  --pill-active-fg: #000000;
  --card-nav-bg: rgba(38, 41, 46, 0.92);
}
body.light {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eceef1;
  --text: #1b1d21;
  --muted: #6b7280;
  --line: #d6d9de;
  --accent: #0f6cbd;
  --accent-dark: #0b559a;
  --brand: #b7f000;
  --brand-ink: #14160f;
  --open: #d93025;
  --progress: #e8871e;
  --review: #7b3ff2;
  --closed: #188038;
  /* Light = green bg / black text inactive, black bg / green text active (the inverse of dark). */
  --pill-bg: var(--brand);
  --pill-fg: #000000;
  --pill-active-bg: #000000;
  --pill-active-fg: var(--brand);
  --card-nav-bg: rgba(255, 255, 255, 0.92);
}

* { box-sizing: border-box; margin: 0; }

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* The `hidden` attribute must always win: several elements toggled via hidden also
   carry a class with `display: flex/grid`, which would otherwise outrank the UA
   `[hidden]` rule and keep them visible (and un-closable). */
[hidden] { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-size: 20px; font-weight: 700; letter-spacing: -0.5px; display: flex; align-items: center; gap: 8px; }
.brand span { color: var(--accent); }
.brand img { width: 28px; height: 28px; border-radius: 7px; }

.new-issue-btn {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  border: none; background: none; cursor: pointer; padding: 2px 4px;
}
.new-issue-btn img { width: 42px; height: 42px; border-radius: 10px; display: block; }
.new-issue-btn span { font-size: 11px; font-weight: 800; color: var(--brand); letter-spacing: 0.5px; }
.new-issue-btn:hover img { outline: 2px solid var(--brand); outline-offset: 1px; }
.new-issue-btn:disabled { opacity: 0.5; cursor: default; }
.spacer { flex: 1; }

select, input, textarea {
  font: inherit;
  color: inherit;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
#userInput { width: 190px; }
.user-badge { font-size: 13px; color: var(--muted); white-space: nowrap; }
.user-badge a { color: var(--accent); }
textarea { resize: vertical; }

.btn {
  font: inherit;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.add { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 700; }
.btn.add:hover { filter: brightness(1.05); }
.btn.subtle:hover { background: var(--bg); }
/* Light-grey buttons, visible in both themes. */
.btn.grey { background: #c9ced4; color: #1b1d21; border-color: #aeb4bb; }
.btn.grey:hover { background: #dce0e5; }
#refreshBtn, #settingsBtn { background: #c9ced4; color: #1b1d21; border-color: #aeb4bb; font-size: 15px; }
#refreshBtn:hover, #settingsBtn:hover { background: #dce0e5; }
.btn.danger { color: var(--open); border-color: var(--open); }

.filters { display: flex; gap: 8px; padding: 14px 18px 0; align-items: center; flex-wrap: wrap; }
.chip-group { display: flex; gap: 8px; }
.filter-select { padding: 6px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 13px; }
.disc-filter-btn { cursor: pointer; text-align: left; }
.check-all { display: inline-flex; align-items: center; }
.check-all input, .card-check input { width: 17px; height: 17px; cursor: pointer; accent-color: var(--brand); }

.bulk-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 18px; margin: 4px 18px 0;
  background: var(--surface); border: 1px solid var(--brand); border-radius: 8px;
}
.bulk-bar #bulkCount { font-weight: 600; font-size: 13px; }
.bulk-bar .spacer { flex: 1; }

.card-check {
  position: absolute; top: 8px; left: 8px; z-index: 2;
  background: var(--card-nav-bg); border-radius: 5px; padding: 2px 3px 0;
  display: flex;
}
.card.selected { outline: 2px solid var(--brand); outline-offset: -1px; }
.chip {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--brand);
  background: var(--pill-bg);
  color: var(--pill-fg);
  cursor: pointer;
}
.chip.active { background: var(--pill-active-bg); border-color: var(--pill-active-bg); color: var(--pill-active-fg); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 14px;
  padding: 16px 18px 40px;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s;
}
.card-nav {
  position: absolute;
  bottom: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--card-nav-bg);
  color: var(--accent);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(20, 40, 60, 0.15);
}
.card-nav:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.card:hover { box-shadow: 0 4px 16px rgba(20, 40, 60, 0.12); transform: translateY(-1px); }
.card .thumb {
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--surface-2) center/cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
}
.card .thumb canvas { width: 100%; height: 100%; object-fit: cover; }
.card .body { padding: 10px 12px 12px; }
.card h3 { font-size: 14.5px; margin-bottom: 6px; line-height: 1.35; }
.card .meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; padding-right: 42px; }
.issue-number { color: var(--muted); font-weight: 600; }

.badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  color: #fff;
  white-space: nowrap;
}
.badge.s-Open { background: var(--open); }
.badge.s-InProgress { background: var(--progress); }
.badge.s-ReadyForReview { background: var(--review); }
.badge.s-Closed { background: var(--closed); }
.badge.p-Low { background: #90a4ae; }
.badge.p-Normal { background: #607d8b; }
.badge.p-High { background: #ef6c00; }
.badge.p-Critical { background: #b71c1c; }

/* Discipline chip on cards */
.disc-badge {
  display: inline-block; font-size: 11px; font-weight: 700; color: #fff;
  padding: 1px 7px; border-radius: 4px; letter-spacing: 0.3px;
}

/* Editable pill-dropdowns in the detail header */
.badge-select {
  font-size: 12px; font-weight: 600; color: #fff;
  border: none; border-radius: 999px; padding: 3px 10px; cursor: pointer;
  appearance: none; -webkit-appearance: none; text-align: center;
  background: #607d8b;
}
.badge-select option { color: var(--text); background: var(--surface); font-weight: 500; }
.badge-select.s-Open { background: var(--open); }
.badge-select.s-InProgress { background: var(--progress); }
.badge-select.s-ReadyForReview { background: var(--review); }
.badge-select.s-Closed { background: var(--closed); }
.badge-select.p-Low { background: #90a4ae; }
.badge-select.p-Normal { background: #607d8b; }
.badge-select.p-High { background: #ef6c00; }
.badge-select.p-Critical { background: #b71c1c; }

.discipline-rows { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.disc-row { display: flex; gap: 6px; align-items: center; }
.disc-row input[type="text"] { padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.disc-row .disc-code { width: 64px; text-transform: uppercase; }
.disc-row .disc-label { flex: 1; }
.disc-row input[type="color"] { width: 30px; height: 30px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; }
.disc-row .disc-del { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 18px; }
.settings-sub { margin: 16px 0 4px; font-size: 15px; }
.settings-hint { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.muted-inline { font-size: 12px; color: var(--muted); font-weight: 400; }

.account-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
  padding: 10px 12px; margin-bottom: 14px;
  background: var(--bg); border-radius: 8px; font-size: 13px;
}
.account-row .account-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.account-row a { color: var(--accent); cursor: pointer; white-space: nowrap; }
.account-row input { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: none; background: var(--surface); color: var(--text); font: inherit; padding: 6px 14px; cursor: pointer; }
.seg button.active { background: var(--brand); color: var(--brand-ink); font-weight: 700; }

.group-rows { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.group-row { display: flex; gap: 6px; align-items: center; }
.group-row input { padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; font: inherit; background: var(--surface); color: var(--text); }
.group-row .group-name { width: 120px; }
.group-row .group-members { flex: 1; }
.group-row .disc-del { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 18px; }
.group-row .pick-users { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; cursor: pointer; padding: 4px 7px; }

.user-table-wrap { overflow-x: auto; margin-bottom: 8px; }
.user-table { border-collapse: collapse; width: 100%; font-size: 12px; }
.user-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 3px 4px; white-space: nowrap; }
.user-table td { padding: 2px 3px; }
.user-table input, .user-table select { padding: 4px 5px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); color: var(--text); font: inherit; }
.user-table input.u-email { width: 150px; }
.user-table input.u-first, .user-table input.u-last, .user-table input.u-company, .user-table input.u-disc { width: 74px; }
.user-table input.u-init { width: 40px; text-transform: uppercase; }

/* User checklist popup (pick group members) */
.user-checklist {
  position: fixed; z-index: 60; width: 230px; max-height: 260px; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4); padding: 6px;
}
.user-checklist .ucl-list { overflow-y: auto; flex: 1; }
.user-checklist label { display: flex; align-items: center; gap: 6px; padding: 4px 6px; font-size: 13px; cursor: pointer; border-radius: 5px; }
.user-checklist label:hover { background: var(--bg); }
.user-checklist .ucl-done { margin-top: 6px; }

.empty { text-align: center; color: var(--muted); padding: 60px 0; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 25, 35, 0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4vh 16px;
  z-index: 50;
  overflow-y: auto;
}
.panel {
  position: relative;
  background: var(--surface);
  border-radius: 12px;
  padding: 22px 24px;
  width: 100%;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.25);
}
.detail-panel { max-width: 860px; }
.create-panel { max-width: 640px; }
.close {
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: 26px;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.detail-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; padding-right: 30px; }
.detail-head h2 { font-size: 19px; }
.detail-meta { font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.detail-desc { font-size: 14px; margin-bottom: 14px; white-space: pre-wrap; }

.detail-props {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  align-items: flex-end;
  margin-bottom: 16px;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 8px;
}
.detail-props .prop { display: flex; flex-direction: column; gap: 3px; }
.detail-props .prop > label {
  font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.3px;
}
.detail-props .prop input { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.detail-props .prop > span { font-size: 13px; padding: 5px 0; }
.detail-props .elem-ids { font-family: ui-monospace, "Cascadia Code", monospace; font-size: 12px; max-width: 340px; word-break: break-word; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.field span { font-weight: 600; }
.settings-panel { max-width: 440px; }
.settings-savebar { margin: -4px 0 12px; }

.snapshots { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.snapshot-block { flex: 1 1 340px; min-width: 280px; }
.snapshot-block .label { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.4px; }
.snapshot-block canvas, .snapshot-block img { width: 100%; border: 1px solid var(--line); border-radius: 8px; display: block; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }

.comments h3 { font-size: 14px; margin-bottom: 8px; }
.comment {
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 13.5px;
}
.comment .who { font-weight: 600; }
.comment .when { color: var(--muted); font-size: 12px; margin-left: 6px; }
.comment .status-change { color: var(--accent); font-weight: 600; }
.comment-box { display: flex; gap: 8px; margin-top: 10px; }
.comment-box input { flex: 1; }

.create-panel h2 { margin-bottom: 14px; }
.form-row { margin-bottom: 10px; display: flex; }
.form-row > * { flex: 1; }
.form-row.split { gap: 10px; }
.form-row.right { justify-content: flex-end; }
.form-row.right > * { flex: 0; }
.file-label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }

.capture-info { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }

.markup-tools { display: flex; gap: 5px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.tool {
  width: 32px;
  height: 32px;
  font-size: 15px;
  border: 1px solid #aeb4bb;
  border-radius: 6px;
  background: #c9ced4;
  color: #1b1d21;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tool:hover { background: #dce0e5; }
.tool.active { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.tool.active:hover { filter: brightness(1.05); }
.tool:disabled { opacity: 0.4; cursor: default; }
.tool-sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 3px; }
.swatch { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.swatch input[type="color"] { width: 30px; height: 30px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); cursor: pointer; }
#fontSize { padding: 5px 6px; }

/* Line / Fill colour swatches (open the custom picker) */
.swatch-label { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.colour-swatch {
  width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 6px;
  cursor: pointer; background: #E53935; padding: 0;
}
.colour-swatch.is-none {
  background:
    linear-gradient(to top right, transparent 45%, #e53935 45%, #e53935 55%, transparent 55%), #fff;
}

/* Custom colour picker popup */
.colour-popup {
  position: fixed; z-index: 60; width: 236px;
  background: #2b2b2b; border: 1px solid #111; border-radius: 8px;
  padding: 8px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  color: #e7e9ec; font-size: 12px;
}
.cp-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; }
.cp-grid button { height: 22px; border: 1px solid #00000055; border-radius: 3px; cursor: pointer; padding: 0; }
.cp-grid button:hover { outline: 2px solid #fff; outline-offset: -1px; }
.cp-grid .cp-nofill {
  background: linear-gradient(to top right, transparent 44%, #e53935 44%, #e53935 56%, transparent 56%), #fff;
}
.cp-grid .cp-eyedrop { background: #3a3a3a; display: flex; align-items: center; justify-content: center; color: #fff; }
.cp-section-label { font-size: 11px; color: #9aa0a8; margin: 8px 0 3px; }
.cp-saved { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; min-height: 22px; }
.cp-saved button { height: 22px; border: 1px solid #00000055; border-radius: 3px; cursor: pointer; padding: 0; }
.cp-saved .cp-empty { background: #333; border-style: dashed; cursor: default; }
.cp-spectrum, .cp-gradient {
  position: relative; height: 16px; border-radius: 4px; margin-top: 8px; cursor: pointer;
  border: 1px solid #111;
}
.cp-spectrum {
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
}
.cp-gradient { background: linear-gradient(to right, #000, #808080, #fff); }
.cp-thumb {
  position: absolute; top: -3px; width: 6px; height: 22px; border-radius: 3px;
  border: 2px solid #fff; box-shadow: 0 0 2px #000; transform: translateX(-50%); pointer-events: none;
}
.cp-row { display: flex; align-items: center; gap: 5px; margin-top: 8px; }
.cp-lbl { color: #9aa0a8; width: 26px; }
.cp-row input {
  flex: 1; width: 40px; padding: 4px 5px; border: 1px solid #111; border-radius: 4px;
  background: #1e1e1e; color: #e7e9ec; font: inherit; text-align: center;
}
.cp-hex { text-transform: uppercase; }
.cp-add {
  width: 26px; height: 26px; border: 1px solid #111; border-radius: 4px;
  background: #3a3a3a; color: #fff; cursor: pointer; font-size: 16px; line-height: 1;
}
.control-group { display: inline-flex; align-items: center; gap: 5px; }
.hl-swatch {
  width: 30px; height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}
.hl-swatch.active { outline: 2px solid var(--text); outline-offset: -1px; }
#annotCanvas { width: 100%; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 10px; cursor: crosshair; touch-action: none; }

@media (max-width: 640px) {
  #userInput { display: none; }
  .filters { flex-wrap: wrap; }
}
