/* PRS Phone App — at-bay stage card UI */

:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #555555;
  --hint: #888888;
  --border: #000000;
  --border-soft: #cccccc;
  --hdr: #e6e6e6;
  --zebra: #f6f6f6;
  --blue: #378ADD;
  --blue-bg: #E6F1FB;
  --blue-text: #185FA5;
  --red: #A32D2D;
  --amber-bg: #FAEEDA;
  --amber-text: #854F0B;
  --amber-border: #EF9F27;
  --info-text: #185FA5;
  --info-bg: #E6F1FB;
  --green: #1d9e75;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
    --fg: #f0f0f0;
    --muted: #b0b0b0;
    --hint: #808080;
    --border: #f0f0f0;
    --border-soft: #444444;
    --hdr: #2a2a2a;
    --zebra: #1a1a1a;
    /* Semantic palette — overridden for dark mode so focused cells stay
       readable (was: light-blue bg + light fg text = invisible). */
    --blue: #5BA3F0;
    --blue-bg: #1e3a5f;
    --blue-text: #93C5FD;
    --red: #F87171;
    --amber-bg: #3D2E15;
    --amber-text: #FCD34D;
    --amber-border: #92400E;
    --info-bg: #1e3a5f;
    --info-text: #93C5FD;
    --green: #34D399;
  }
}

* { box-sizing: border-box; }

/* Ensure hidden attribute always wins over component display rules */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* When the keypad is open, reserve scroll space at the bottom so the user
   can scroll the active cell into view above the keypad's fixed overlay. */
body.kp-open { padding-bottom: var(--kp-h, 280px); }

button { font-family: inherit; }

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  padding-bottom: env(safe-area-inset-bottom);
}

/* App bar */
.appbar {
  padding: 4px 10px;
  padding-top: calc(4px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 0.5px solid var(--border-soft);
  background: var(--bg);
}
.appbar .title { font-size: 13px; font-weight: 500; color: var(--muted); }
.appbar .ic {
  background: none; border: none; cursor: pointer;
  font-size: 18px; color: var(--muted); padding: 2px 6px;
}
.ti { font-family: inherit; }

/* Stage nav */
.stage-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 14px;
  background: var(--zebra);
  border-bottom: 0.5px solid var(--border-soft);
  font-size: 13px; color: var(--muted);
}
.stage-nav .nav-btn {
  background: none; border: none; cursor: pointer;
  font-size: 22px; color: var(--fg); padding: 4px 12px;
  font-weight: 500;
}

/* Stage info bar */
.stage-info {
  display: grid;
  grid-template-columns: 42px 30px 50px minmax(0, 1fr) 36px auto;
  border-bottom: 1px solid var(--border);
}
.stage-info > div {
  padding: 6px 6px;
  border-right: 1px solid var(--border);
  display: flex; align-items: center;
}
.stage-info > div:last-child { border-right: none; }
.stage-info .lbl {
  background: var(--hdr); font-size: 11px; font-weight: 500;
  justify-content: center;
}
.stage-info .val { font-size: 18px; font-weight: 500; }
.stage-info .stage-num { justify-content: center; }
.stage-info .descr { font-size: 16px; font-weight: 500; padding: 4px 6px; min-width: 0; }
.stage-info .descr-text {
  outline: none; padding: 2px 4px; border-radius: 3px;
  min-height: 18px; cursor: text; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stage-info .descr-text:focus {
  background: var(--blue-bg); box-shadow: inset 0 0 0 1.5px var(--blue);
}
.stage-info .descr-text:empty::before {
  content: attr(data-placeholder); color: var(--hint); font-style: italic; font-weight: 400;
}
.stage-info .val.rds { justify-content: center; padding: 4px 8px; }
.rds-text {
  outline: none; padding: 2px 4px; border-radius: 3px; cursor: text;
  min-width: 18px; text-align: center;
}
.rds-text:focus {
  background: var(--blue-bg); box-shadow: inset 0 0 0 1.5px var(--blue);
}
.flag-chip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--info-bg); color: var(--info-text);
  font-size: 12px; font-weight: 500; cursor: pointer;
  margin-left: 4px;
}
.flag-chip.sev-warning { background: var(--amber-bg); color: var(--amber-text); }
.flag-chip.sev-error { background: var(--red); color: #fff; }

/* Column header */
.col-head {
  display: grid;
  grid-template-columns: 1fr 36px 56px 56px 56px 110px;
  background: var(--hdr);
  font-size: 13px; font-weight: 500;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.col-head > div {
  padding: 4px 0;
  border-right: 1px solid var(--border);
}
.col-head > div:last-child { border-right: none; }
.col-head .wind-cell { display: flex; flex-direction: column; padding: 0; }
.col-head .wind-cell .w-top { padding: 2px 0; border-bottom: 1px solid var(--border); }
.col-head .wind-cell .w-sub { display: grid; grid-template-columns: 1fr 1fr; font-size: 11px; color: var(--muted); }
.col-head .wind-cell .w-sub div { padding: 1px 0; }
.col-head .wind-cell .w-sub div:first-child { border-right: 1px solid var(--border); }

/* POS block */
.pos-block { border-bottom: 1px solid var(--border); }
.pos-label {
  padding: 10px 12px;
  font-size: 17px; font-weight: 500;
  border-bottom: 0.5px solid var(--border-soft);
  display: flex; align-items: center;
}
.pos-label-text {
  flex: 1; outline: none; padding: 2px 4px; border-radius: 3px;
  cursor: text; min-height: 18px;
}
.pos-label-text:focus {
  background: var(--blue-bg); box-shadow: inset 0 0 0 1.5px var(--blue);
}

.pos-empty {
  padding: 14px 14px;
  font-size: 17px; font-weight: 500; color: var(--muted);
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.pos-empty .add {
  font-size: 17px; color: var(--blue-text); cursor: pointer;
}

/* Rows */
.row {
  display: grid;
  grid-template-columns: 1fr 36px 56px 56px 56px 110px;
  min-height: 44px;
}
.row > div {
  padding: 4px 4px;
  border-right: 0.5px solid var(--border-soft);
  border-bottom: 0.5px solid var(--border-soft);
  font-size: 18px; font-weight: 500;
  text-align: center;
  display: flex; align-items: center; justify-content: center;
}
.row > div:last-child { border-right: none; }
.row .target {
  text-align: left; padding-left: 8px;
  justify-content: flex-start; gap: 4px; min-width: 0;
}
.row .target .icon { width: 12px; height: 14px; flex-shrink: 0; }
.row .target .icon-ipsc { background: var(--fg); clip-path: polygon(50% 0, 100% 25%, 100% 100%, 0 100%, 0 25%); }
.row .target .icon-circle { border: 1.5px solid var(--fg); border-radius: 50%; }
.row .target .icon-square { border: 1.5px solid var(--fg); }
.row .target .icon-diamond { border: 1.5px solid var(--fg); transform: rotate(45deg); width: 10px; height: 10px; margin: 2px; }
.row .target .icon-animal { background: var(--fg); clip-path: polygon(0 60%, 25% 60%, 30% 40%, 70% 40%, 80% 60%, 100% 60%, 100% 100%, 0 100%); }
.row .target .icon-kyl { background: var(--fg); clip-path: polygon(10% 50%, 35% 50%, 35% 30%, 50% 30%, 50% 50%, 90% 50%, 90% 70%, 10% 70%); }
.row .target .icon-tip { background: var(--fg); clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.row .target .icon-iron-maiden { background: var(--fg); clip-path: polygon(35% 0, 65% 0, 65% 100%, 35% 100%); }
.row .target .icon-placeholder { border: 1px dashed var(--border-soft); }
.row .target .tg-text {
  flex: 1; min-width: 0; padding: 2px 2px;
  border-radius: 3px; outline: none; cursor: text;
  font-size: 17px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row .target .tg-text:focus {
  background: var(--blue-bg); box-shadow: inset 0 0 0 1.5px var(--blue);
  overflow: visible;
}
.row .target .tg-text:empty::before {
  content: attr(data-placeholder); color: var(--hint);
  font-style: italic; font-weight: 400;
}
.row.alt > div { background: var(--zebra); }
.row .wind-split { padding: 0; display: grid; grid-template-columns: 1fr 1fr; }
.row .wind-split .ws-cell {
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 500; cursor: pointer;
  padding: 4px 2px; min-height: 36px;
}
.row .wind-split .ws-cell:first-child { border-right: 0.5px solid var(--muted); }
.row.alt .wind-split .ws-cell { background: var(--zebra); }

.editable { cursor: pointer; }
.empty-cell::after {
  content: ""; display: inline-block;
  width: 6px; height: 1px; background: var(--border-soft);
}
.auto-cell { color: var(--blue-text); }
.auto-cell.negative { color: var(--red); }
.cell-active {
  box-shadow: inset 0 0 0 2px var(--blue) !important;
  background: var(--blue-bg) !important;
}
.cell-invalid {
  box-shadow: inset 0 0 0 2px var(--red) !important;
  background: rgba(220, 80, 80, 0.18) !important;
  color: var(--red) !important;
}
.cell-active.cell-invalid {
  box-shadow: inset 0 0 0 2.5px var(--red) !important;
}
.keypad .kp-hint-error { color: var(--red) !important; font-weight: 500; }

/* Stage dial bar */
.stage-dial {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-bottom: 0.5px solid var(--border-soft);
  font-size: 16px; font-weight: 500;
}
.stage-dial .field {
  width: 60px; height: 36px;
  border: 1px solid var(--border-soft); border-radius: 4px;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 500;
}
.stage-dial .field.editable.empty-cell { color: var(--hint); }
.stage-dial .field.editable.empty-cell::after { content: ""; }
.sug-field {
  background: var(--zebra) !important;
  color: var(--blue-text);
  border-style: dashed !important;
}
.sug-tag { font-size: 10px; color: var(--hint); margin-left: 2px; }

/* Notes */
.notes-row {
  display: flex; align-items: center; gap: 6px;
  padding: 14px 14px;
  font-size: 19px; color: var(--muted);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background: var(--bg);
}
.notes-row .nlbl { font-weight: 500; }
.notes-row .ncount {
  background: var(--info-bg); color: var(--info-text);
  font-size: 10px; padding: 1px 6px; border-radius: 8px;
  font-weight: 500;
}
.notes-row .ic-chev {
  margin-left: auto; font-size: 16px;
  transition: transform .2s;
}
.notes-row.open .ic-chev { transform: rotate(90deg); }
.notes-panel {
  padding: 10px 12px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--zebra);
}
.notes-panel textarea {
  width: 100%; box-sizing: border-box;
  min-height: 130px; padding: 12px 14px;
  font-family: inherit; font-size: 20px;
  line-height: 1.4;
  border: 1px solid var(--border-soft); border-radius: 4px;
  resize: vertical; outline: none;
  background: var(--bg); color: var(--fg);
}
.notes-panel textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(55,138,221,0.18);
}

/* Bottom bar */
.bottom-bar {
  margin-top: auto;
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  padding: 10px 0 calc(14px + env(safe-area-inset-bottom));
  border-top: 0.5px solid var(--border-soft);
  background: var(--zebra);
}
.bbtn {
  display: flex; flex-direction: column;
  align-items: center; gap: 2px;
  cursor: pointer; color: var(--fg);
  background: none; border: none;
  padding: 4px 0;
  font-size: 11px;
}
.bbtn .ic2 { font-size: 24px; }
.bbtn .lbl2 { font-size: 11px; }

/* Keypad */
.keypad {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--hdr);
  z-index: 8;
  box-shadow: 0 -1px 0 var(--border-soft);
}
.keypad .kp-hdr {
  display: flex; justify-content: space-between;
  padding: 6px 12px;
  font-size: 12px; color: var(--muted); font-weight: 500;
}
.keypad .grid {
  display: grid; grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 6px; padding: 0 8px 8px;
}
.keypad button {
  background: var(--bg); color: var(--fg);
  border: 0.5px solid var(--border-soft);
  padding: 14px 0; font-size: 18px; font-weight: 500;
  border-radius: 8px; cursor: pointer;
}
.keypad button:active { background: var(--blue-bg); }
.keypad button.done {
  background: var(--green); color: #fff; border-color: var(--green);
}
.keypad button.dot, .keypad button.dir { background: var(--zebra); font-size: 16px; }
.keypad button.bk { background: var(--zebra); }
.keypad button.clr { background: var(--zebra); font-size: 13px; font-weight: 500; }

/* Flag popover */
.flag-pop {
  position: absolute; top: 100px; left: 12px; right: 12px;
  background: var(--info-bg);
  border: 1px solid var(--blue);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 16px; color: var(--info-text);
  line-height: 1.4;
  z-index: 5;
}
.flag-pop.sev-warning { background: var(--amber-bg); border-color: var(--amber-border); color: var(--amber-text); }
.flag-pop.sev-error { background: rgba(220, 80, 80, 0.18); border-color: var(--red); color: var(--red); }
.flag-pop .ttl { font-weight: 500; font-size: 17px; margin: 0 0 6px; }
.flag-pop .msg { font-size: 16px; }
.flag-pop .lnk { font-size: 16px; padding: 6px 12px; }
.flag-pop .msg { margin: 0; }
.flag-pop .flag-actions { margin-top: 8px; text-align: right; }
.flag-pop .lnk { font-weight: 500; cursor: pointer; }

/* Capture modal — multi-photo flow */
.capture-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 25; padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.capture-modal .cm-card {
  background: var(--bg); border-radius: 16px;
  padding: 18px 18px 14px; width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 12px;
  border: 1px solid var(--border-soft);
}
.cm-title { font-size: 18px; font-weight: 500; margin: 0; }
.cm-sub { font-size: 14px; color: var(--muted); margin: 0; line-height: 1.4; }
.cm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.cm-btn {
  padding: 14px 0; border-radius: 8px;
  background: var(--bg); color: var(--fg);
  font-size: 16px; font-weight: 500;
  border: 1px solid var(--border-soft);
  cursor: pointer;
}
.cm-add { color: var(--blue-text); border-color: var(--blue); background: var(--blue-bg); }
.cm-parse { background: var(--green); color: #fff; border-color: var(--green); }
.cm-cancel {
  background: none; border: none; color: var(--muted);
  font-size: 14px; padding: 6px; cursor: pointer; align-self: center;
}

/* Toast */
.toast {
  position: fixed; bottom: 100px; left: 16px; right: 16px;
  background: rgba(20,20,20,0.92); color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px; text-align: center;
  opacity: 0; transition: opacity .25s;
  pointer-events: none; z-index: 20;
}
.toast.show { opacity: 1; }

/* Empty state */
.empty-state {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 2rem;
  color: var(--muted);
  text-align: center;
  gap: 16px;
}
.empty-state .es-icon {
  font-size: 56px;
  color: var(--border-soft);
  line-height: 1;
}
.empty-state .es-title {
  font-size: 20px; font-weight: 500;
  color: var(--fg);
  margin: 0;
}
.empty-state .es-sub {
  font-size: 15px;
  line-height: 1.45;
  margin: 0;
  max-width: 320px;
}
.empty-state .es-btn {
  margin-top: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--blue-text);
  background: var(--blue-bg);
  border: 1px solid var(--blue);
  border-radius: 8px;
  cursor: pointer;
}
.empty-state .es-hint {
  font-size: 12px;
  color: var(--hint);
  margin: 0;
  max-width: 280px;
  line-height: 1.4;
}
.empty-state.hidden { display: none; }

/* Loading */
.loading {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 30;
  color: #fff;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.ld-msg { font-size: 14px; margin: 0; }
.ld-timer { font-size: 22px; font-weight: 500; margin: 8px 0 0; font-variant-numeric: tabular-nums; opacity: 0.9; }
