/* RakshaRath UAT Defect Tracker */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #dfe3e8;
  --border-strong: #c6ccd4;
  --text: #16202c;
  --text-dim: #5b6875;
  --accent: #1d63d1;
  --accent-soft: #e6eefc;

  --critical: #c62828;  --critical-bg: #fdecec;
  --high:     #d1620a;  --high-bg:     #fdf0e3;
  --medium:   #9a7407;  --medium-bg:   #fbf4dd;
  --low:      #5b6875;  --low-bg:      #eceff3;

  --open:     #c62828;  --open-bg:     #fdecec;
  --progress: #b26a00;  --progress-bg: #fdf1dd;
  --tbd:      #6d4bb6;  --tbd-bg:      #f0eafb;
  --resolved: #1d63d1;  --resolved-bg: #e6eefc;
  --closed:   #1e7a4d;  --closed-bg:   #e4f4ec;

  --bug: #b3335a;
  --feature: #4b45b8;
  --observation: #17708a;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151a;
    --surface: #191f26;
    --surface-2: #212933;
    --border: #2c3540;
    --border-strong: #3d4855;
    --text: #e7ecf2;
    --text-dim: #9aa7b5;
    --accent: #6ea8fe;
    --accent-soft: #1c2b44;

    --critical: #ff8a80;  --critical-bg: #3a1e1e;
    --high:     #ffb570;  --high-bg:     #3a2a19;
    --medium:   #e8cd6a;  --medium-bg:   #35301a;
    --low:      #9aa7b5;  --low-bg:      #262e38;

    --open:     #ff8a80;  --open-bg:     #3a1e1e;
    --progress: #ffc46b;  --progress-bg: #3a2c14;
    --tbd:      #c4a7ff;  --tbd-bg:      #2b2340;
    --resolved: #6ea8fe;  --resolved-bg: #1c2b44;
    --closed:   #6fd39b;  --closed-bg:   #17311f;

    --bug: #ff92b1;
    --feature: #a6a0ff;
    --observation: #6fd0e8;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

/* Several rules below set display on elements that also get toggled with [hidden]
   (dialog .field, and tr/td at mobile widths). Those would out-specify the UA's
   [hidden] rule, so state it once, decisively. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--text-dim); }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand .mark { font-size: 26px; line-height: 1; }
.brand strong { display: block; font-size: 17px; letter-spacing: -.01em; }
.brand em { display: block; font-style: normal; font-size: 13px; color: var(--text-dim); }

.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  font: inherit;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.primary:disabled { opacity: .6; cursor: default; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.who { color: var(--text-dim); }
.btn.who.unset { border-style: dashed; }

.linkish {
  font: inherit; background: none; border: 0; padding: 0;
  color: var(--accent); text-decoration: underline; cursor: pointer;
}

main { max-width: 1400px; margin: 0 auto; padding: 20px 24px 64px; }

/* ---------- KPI tiles ---------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.kpi {
  text-align: left;
  font: inherit;
  color: var(--text);   /* buttons don't inherit colour — without this the number goes UA-black */
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--tint, var(--border-strong));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .1s, border-color .12s;
}
.kpi:hover { transform: translateY(-1px); }
.kpi[aria-pressed="true"] { border-color: var(--tint, var(--accent)); background: var(--tint-bg, var(--accent-soft)); }
.kpi .n { display: block; font-size: 26px; font-weight: 650; line-height: 1.15; letter-spacing: -.02em; }
.kpi .k { display: block; font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; }

/* ---------- filters ---------- */

.controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 14px;
}

.searchwrap { margin-bottom: 12px; }

#search {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
#search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.facets { display: flex; flex-wrap: wrap; gap: 16px 22px; align-items: flex-start; }
.facet { display: flex; flex-direction: column; gap: 6px; }
.facet-label {
  font-size: 11px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-dim);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  font: inherit;
  font-size: 13px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] {
  border-color: var(--tint, var(--accent));
  background: var(--tint-bg, var(--accent-soft));
  color: var(--tint, var(--accent));
  font-weight: 600;
}
.chip .c { opacity: .65; font-variant-numeric: tabular-nums; margin-left: 4px; }
.chip[data-count="0"] { opacity: .45; }

.select {
  font: inherit;
  font-size: 14px;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  min-width: 160px;
}

/* ---------- result bar ---------- */

.resultbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 0 2px 10px; min-height: 32px;
}
.count { font-size: 14px; color: var(--text-dim); }
.count b { color: var(--text); }
.active-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.active-filters .tag {
  font-size: 12px; padding: 3px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
}

/* ---------- table ---------- */

.tablewrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

table { width: 100%; border-collapse: collapse; }

thead th {
  text-align: left;
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-dim);
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody.defect { border-bottom: 1px solid var(--border); }
tbody.defect:last-child { border-bottom: none; }
tbody.defect.is-open { background: var(--surface-2); }

tr.main > td { padding: 9px 12px; vertical-align: middle; }
tr.main { cursor: pointer; }
tbody.defect:hover tr.main { background: var(--surface-2); }

.c-id  { width: 78px; }
.c-typ { width: 130px; }   /* "Observation" is the widest pill label */
.c-pri { width: 108px; }
.c-sta { width: 126px; }
.c-asg { width: 120px; }
.c-mod { width: 140px; }
.c-dat { width: 106px; white-space: nowrap; }

td.c-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; color: var(--text-dim); }
td.c-mod, td.c-asg { font-size: 13px; color: var(--text-dim); }
td.c-dat { font-size: 13px; color: var(--text-dim); white-space: nowrap; }
td.c-tit { font-weight: 500; }
td.c-tit .chev { color: var(--text-dim); margin-right: 6px; display: inline-block; width: 10px; transition: transform .12s; }
tbody.defect.is-open td.c-tit .chev { transform: rotate(90deg); }

.who-chip {
  display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-size: 12px; font-weight: 600; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 2px 8px; border-radius: 999px;
}
tbody.defect.is-open .who-chip { background: var(--surface); }

.badge {
  display: inline-block; margin-left: 8px; font-size: 11px; font-weight: 600;
  color: var(--text-dim); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px;
  vertical-align: 1px;
}
tbody.defect.is-open .badge { background: var(--surface); }

mark { background: #ffe08a; color: inherit; border-radius: 3px; padding: 0 1px; }
@media (prefers-color-scheme: dark) { mark { background: #7a6216; color: #fff; } }

/* priority / status / type pickers styled as pills — the wrapper carries the colour tint
   (custom properties inherit) and draws the caret, since <select> can't take ::after */
.pillbox { position: relative; display: inline-block; width: 100%; max-width: 118px; }
.pillbox::after {
  content: '';
  position: absolute; right: 8px; top: 50%; margin-top: -2px;
  border: 3.5px solid transparent; border-top: 4px solid var(--tint);
  opacity: .6; pointer-events: none;
}
.pill {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 18px 4px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--tint-bg);
  color: var(--tint);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
}
.pill:hover { border-color: var(--tint); }
.pill:focus-visible { outline: 2px solid var(--accent); }
.pill.saving { opacity: .5; }
.pill.saved { animation: flash .9s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 3px var(--accent-soft); } 100% { box-shadow: none; } }

/* type reads as outlined so it never gets mistaken for the filled priority beside it */
.t-Bug         { --tint: var(--bug); }
.t-Feature     { --tint: var(--feature); }
.t-Observation { --tint: var(--observation); }
.t-Bug, .t-Feature, .t-Observation { --tint-bg: transparent; }
.t-Bug .pill, .t-Feature .pill, .t-Observation .pill { border-color: var(--tint); }
.chip.t-Bug, .chip.t-Feature, .chip.t-Observation { --tint-bg: var(--surface-2); }

.p-Critical { --tint: var(--critical); --tint-bg: var(--critical-bg); }
.p-High     { --tint: var(--high);     --tint-bg: var(--high-bg); }
.p-Medium   { --tint: var(--medium);   --tint-bg: var(--medium-bg); }
.p-Low      { --tint: var(--low);      --tint-bg: var(--low-bg); }

.s-Open        { --tint: var(--open);     --tint-bg: var(--open-bg); }
.s-In-Progress { --tint: var(--progress); --tint-bg: var(--progress-bg); }
.s-TBD         { --tint: var(--tbd);      --tint-bg: var(--tbd-bg); }
.s-Resolved    { --tint: var(--resolved); --tint-bg: var(--resolved-bg); }
.s-Closed      { --tint: var(--closed);   --tint-bg: var(--closed-bg); }

/* ---------- detail panel ---------- */

tr.detail > td { padding: 4px 14px 18px 14px; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 24px; }
.detail-grid h4 {
  margin: 12px 0 4px; font-size: 11px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-dim); font-weight: 600;
}
.detail-grid h4:first-child { margin-top: 0; }
.detail-grid p { margin: 0; white-space: pre-wrap; }
.detail-meta { margin-top: 12px; font-size: 12px; color: var(--text-dim); }
.detail-buttons { display: flex; gap: 8px; margin-top: 12px; }

.empty { padding: 40px; text-align: center; color: var(--text-dim); margin: 0; }

/* screenshots */
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.thumb {
  position: relative; margin: 0; width: 132px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); overflow: hidden;
}
.thumb img { display: block; width: 100%; height: 84px; object-fit: cover; cursor: zoom-in; }
.thumb figcaption {
  font-size: 10px; color: var(--text-dim); padding: 4px 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thumb-del {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px;
  border: 0; border-radius: 50%; cursor: pointer; font-size: 11px; line-height: 1;
  background: rgba(0, 0, 0, .6); color: #fff;
}
.thumb-del:hover { background: var(--critical); }

.dropzone {
  border: 1px dashed var(--border-strong); border-radius: 8px;
  padding: 14px; text-align: center; font-size: 13px; color: var(--text-dim);
  background: var(--bg); cursor: pointer;
}
.dropzone.small { padding: 10px; }
.dropzone:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dropzone strong { color: var(--text); }

/* activity */
.events { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 7px; }
.ev { font-size: 13px; color: var(--text-dim); line-height: 1.45; }
.ev b { color: var(--text); font-weight: 600; }
.ev em { font-style: normal; color: var(--text); font-weight: 500; }
.ev .when { font-size: 11px; opacity: .75; margin-left: 4px; white-space: nowrap; }
.ev.comment {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px;
}
.ev.comment p { margin: 3px 0 0; color: var(--text); white-space: pre-wrap; }

.commentbox { display: flex; gap: 8px; align-items: flex-end; }
.commentbox textarea {
  flex: 1; font: inherit; font-size: 14px; padding: 8px 10px; resize: vertical;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); color: var(--text);
}

/* ---------- module breakdown ---------- */

.breakdown { margin-top: 24px; }
.breakdown h2 {
  font-size: 12px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-dim); margin: 0 0 10px;
}
.bars { display: grid; gap: 6px; }
.bar-row {
  display: grid; grid-template-columns: 160px 1fr 42px; align-items: center; gap: 12px;
  font-size: 13px; cursor: pointer; padding: 3px 4px; border-radius: 6px;
}
.bar-row:hover { background: var(--surface-2); }
.bar-row .name { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.bar-seg { height: 100%; }
.bar-row .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-dim); }

/* ---------- dialogs ---------- */

dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(680px, calc(100vw - 32px));
  box-shadow: 0 20px 50px rgba(16, 24, 40, .25);
}
dialog::backdrop { background: rgba(16, 24, 40, .45); }
dialog form { padding: 22px; display: grid; gap: 12px; }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
dialog .hint { margin: -6px 0 4px; font-size: 13px; color: var(--text-dim); }
dialog label, dialog .field { display: grid; gap: 5px; font-size: 12px; font-weight: 600; color: var(--text-dim); }
dialog .req { color: var(--critical); }
dialog input, dialog textarea, dialog select {
  font: inherit; font-size: 14px; font-weight: 400; color: var(--text);
  padding: 8px 10px; border: 1px solid var(--border-strong);
  border-radius: 8px; background: var(--bg); width: 100%;
}
dialog textarea { resize: vertical; }
dialog .row { display: grid; gap: 12px; }
dialog .row-4 { grid-template-columns: repeat(4, 1fr); }
dialog .row-2 { grid-template-columns: repeat(2, 1fr); }
.form-error { margin: 0; color: var(--critical); font-size: 13px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

#dlg-image {
  width: auto; max-width: 94vw; background: transparent;
  border: 0; box-shadow: none; overflow: visible;
}
#lightbox-img {
  display: block; max-width: 94vw; max-height: 88vh;
  border-radius: 10px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.lightbox-close {
  position: absolute; top: -14px; right: -14px; width: 32px; height: 32px;
  border-radius: 50%; border: 0; cursor: pointer; font-size: 14px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(16, 24, 40, .25); z-index: 50;
}
.toast.err { background: var(--critical); color: #fff; }

/* ---------- narrow screens: table becomes cards ---------- */

@media (max-width: 1080px) {
  .detail-grid { grid-template-columns: 1fr; gap: 16px; }
}

@media (max-width: 900px) {
  main { padding: 16px 12px 48px; }
  .topbar { padding: 12px 14px; }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody.defect {
    border: 1px solid var(--border); border-radius: var(--radius);
    margin-bottom: 8px; overflow: hidden;
  }
  tr.main {
    display: grid; grid-template-columns: repeat(3, auto);
    justify-content: start; align-items: center; gap: 6px 8px; padding: 10px 12px;
  }
  tr.main > td { padding: 0; }
  td.c-tit { grid-column: 1 / -1; order: 1; }
  td.c-typ { order: 2; }
  td.c-pri { order: 3; }
  td.c-sta { order: 4; }
  td.c-id  { order: 5; align-self: center; }
  td.c-asg { order: 6; }
  td.c-mod, td.c-dat { grid-column: 1 / -1; order: 7; }
  .pillbox { max-width: none; width: auto; }
  .pill { width: auto; }
  .bar-row { grid-template-columns: 110px 1fr 36px; }
  .select { min-width: 140px; }
  dialog .row-4, dialog .row-2 { grid-template-columns: 1fr 1fr; }
  .commentbox { flex-direction: column; align-items: stretch; }
}
