/* ---------------------------------------------------------------------------
   Shared shell styling, then the incident tab.

   The incident tab reproduces the original static demo: the same MOA theme
   variables, the same iPhone frame, the same card and field treatment. Shiny
   emits Bootstrap markup rather than the original's hand-written HTML, so the
   rules below are the original stylesheet plus a layer that bends Bootstrap's
   .form-control / .radio / .checkbox output back into the original's shapes.
--------------------------------------------------------------------------- */

:root {
  /* Pulled from the PCI theme (MOATheme / moaui.common). */
  --moa-primary: #8E5CF0;
  --moa-primary-heavy: #6741C7;
  --moa-primary-soft: #F3EDFE;
  --moa-bg: #F5F4F1;
  --moa-card: #FFFFFF;
  --moa-ink: #212529;
  --moa-ink-alt: #344054;
  --moa-muted: #667085;
  --moa-border: #D0D5DD;
  --moa-error: #F04433;
  --moa-success: #12B76A;
  --radius: 10px;
  --radius-lg: 14px;
}

/* --- the other tabs ------------------------------------------------------- */

.container { max-width: 900px; padding: 28px 16px 64px; }
h1 { font-size: 26px; font-weight: 800; margin: 0 0 6px; }
.lede { color: #5A6270; margin: 0 0 20px; max-width: 62ch; }
.overview .card { height: 100%; }
.overview .card-header { font-weight: 700; }

/* ===========================================================================
   Incident tab
   =========================================================================== */

.phone-wrap {
  display: flex; justify-content: center; align-items: flex-start;
  padding: 18px 12px 28px; background: #fff;
}

/* ---------- iPhone frame (same geometry as the original) ---------- */

.phone {
  position: relative; background: #000; padding: 10px; border-radius: 56px;
  border: 1px solid #2c2d33;
  box-shadow: 0 30px 70px rgba(20, 22, 40, .3);
}
.phone::before { /* power button */
  content: ""; position: absolute; right: -3px; top: 210px; width: 3px; height: 76px;
  background: #2c2d33; border-radius: 0 3px 3px 0;
}
.phone::after { /* volume buttons */
  content: ""; position: absolute; left: -3px; top: 170px; width: 3px; height: 120px;
  background: #2c2d33; border-radius: 3px 0 0 3px;
}
.shell {
  position: relative;
  width: 373px; max-width: 373px; height: min(812px, calc(100vh - 150px));
  display: flex; flex-direction: column;
  background: var(--moa-bg); border-radius: 46px; overflow: hidden;
}
.island {
  width: 116px; height: 30px; background: #000; border-radius: 18px;
  margin: 10px auto 0; flex-shrink: 0;
}
@media (max-width: 520px), (max-height: 720px) {
  .phone-wrap { padding: 0; }
  .phone { padding: 0; border: none; border-radius: 0; box-shadow: none; width: 100%; }
  .phone::before, .phone::after, .island { display: none; }
  .shell { width: 100%; max-width: none; height: calc(100vh - 62px); border-radius: 0; }
}

/* ---------- App chrome ---------- */

.appbar {
  flex-shrink: 0; background: var(--moa-card);
  border-bottom: 1px solid var(--moa-border);
  padding: 12px 16px 0;
}
.appbar-row { display: flex; align-items: center; gap: 10px; }
.org { font-size: 16px; font-weight: 800; margin-right: auto; letter-spacing: -.01em; }
.tabs { display: flex; gap: 4px; margin-top: 10px; }
.tab {
  font-size: 13px; font-weight: 700; padding: 9px 14px;
  border-radius: 8px 8px 0 0; color: var(--moa-muted);
}
.tab.active {
  color: var(--moa-primary); background: var(--moa-primary-soft);
  box-shadow: inset 0 -3px 0 var(--moa-primary);
}
.tab .dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--moa-error); margin-left: 6px; vertical-align: middle;
}

/* The themed button, overriding Bootstrap's .btn on the elements we mark. */
.phone .btn-moa, .devbar .btn-moa {
  font-size: 13px; font-weight: 700; padding: 8px 14px; border: none;
  border-radius: var(--radius); background: var(--moa-primary); color: #fff;
}
.phone .btn-moa:hover { background: var(--moa-primary-heavy); color: #fff; }
.phone .btn-moa:disabled, .phone .btn-moa.disabled { background: #C9C6D3; color: #fff; }
.phone .fill-btn { width: 100%; margin-top: 12px; padding: 12px; font-size: 14.5px; }

/* Busy state for a button that has kicked off a slow call. The spinner reuses
   the same border-arc trick as the pipeline stage dots, so the two read as one
   idea rather than two loading styles. */
.phone .btn-moa.busy {
  background: var(--moa-primary); opacity: .85; cursor: progress;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
}
.phone .btn-moa.busy::before {
  content: ""; width: 15px; height: 15px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, .45); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
.phone .btn-moa.busy:disabled, .phone .btn-moa.busy[disabled] {
  background: var(--moa-primary); color: #fff;
}
.phone .submit-btn { width: 100%; padding: 13px; font-size: 15px; }

/* ---------- Scrolling form body ---------- */

.shell .body {
  flex: 1; overflow-y: auto; padding: 12px 12px 28px;
  -webkit-overflow-scrolling: touch;
}

.phone .card {
  background: var(--moa-card); border: 1px solid var(--moa-border);
  border-radius: var(--radius-lg); margin-bottom: 12px; overflow: hidden;
}
.phone .card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px; cursor: pointer; user-select: none;
}
.phone .card-head .ic {
  width: 26px; height: 26px; border-radius: 7px; flex-shrink: 0;
  background: var(--moa-primary-soft); color: var(--moa-primary);
  display: flex; align-items: center; justify-content: center;
}
.phone .card-head h2 {
  font-size: 15px; font-weight: 800; margin: 0; flex: 1; letter-spacing: -.01em;
}
.phone .card-head .chev { color: var(--moa-primary); transition: transform .2s; }
.phone .card.collapsed .chev { transform: rotate(-90deg); }
.phone .card.collapsed .card-body { display: none; }
.phone .card-body { padding: 0 14px 14px; }
.phone .card-note {
  font-size: 12.5px; line-height: 1.5; color: var(--moa-muted);
  background: var(--moa-bg); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 14px;
}
.phone .sub-header {
  font-size: 13px; font-weight: 800; color: var(--moa-ink-alt);
  text-transform: uppercase; letter-spacing: .04em;
  padding-top: 6px; margin: 4px 0 12px;
  border-top: 1px solid var(--moa-border);
}

/* ---------- Fields ---------- */

.phone .fg { margin-bottom: 16px; }
.phone .fg > label.lbl,
.phone .card-body > label.lbl {
  display: block; font-size: 13.5px; font-weight: 600;
  color: var(--moa-ink-alt); line-height: 1.4; margin-bottom: 6px;
}
.phone .req { color: var(--moa-error); margin-left: 3px; font-weight: 700; }

/* Shiny wraps every input in .form-group.shiny-input-container and gives it a
   bottom margin; the .fg wrapper owns spacing here, so flatten it. */
.phone .shiny-input-container { margin-bottom: 0; width: 100% !important; }
.phone .shiny-input-container > label:empty { display: none; }

.phone input[type=text], .phone input[type=number], .phone select, .phone textarea,
.phone .form-control, .phone .form-select {
  width: 100%; font-family: inherit; font-size: 15px; color: var(--moa-ink);
  padding: 10px 12px; border: 1px solid var(--moa-border);
  border-radius: var(--radius); background: #fff; box-shadow: none;
}
.phone input:focus, .phone select:focus, .phone textarea:focus,
.phone .form-control:focus, .phone .form-select:focus {
  outline: none; border-color: var(--moa-primary);
  box-shadow: 0 0 0 3px rgba(142, 92, 240, .16);
}
.phone textarea, .phone textarea.form-control { resize: vertical; line-height: 1.5; }

.phone select, .phone .form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23667085' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 30px;
}
.phone select.placeholder { color: var(--moa-muted); }

.phone .dt { display: flex; gap: 8px; }
.phone .dt .shiny-input-container { flex: 1; }

/* Radio and checkbox groups as bordered option boxes. Shiny renders each option
   as .radio > label > input, so the label is what gets the box. :has() gives the
   selected state without any JavaScript. */
.phone .opts .shiny-options-group { display: flex; flex-direction: column; gap: 8px; }
.phone .opts.row .shiny-options-group { flex-direction: row; flex-wrap: wrap; }
.phone .opts .radio, .phone .opts .checkbox { margin: 0; flex: 1 1 auto; }
.phone .opts .radio label, .phone .opts .checkbox label {
  display: flex; align-items: flex-start; gap: 9px; cursor: pointer; width: 100%;
  font-size: 14px; line-height: 1.35; color: var(--moa-ink); font-weight: 400;
  padding: 9px 11px; border: 1px solid var(--moa-border);
  border-radius: var(--radius); background: #fff; margin: 0;
}
/* bslib's Sass resets form controls with `appearance: none` and a 2px width,
   which leaves the radio as a sliver. Restore the native control — the original
   used plain inputs tinted with accent-color, and !important is what it takes
   to beat the framework reset. */
.phone .opts input[type=radio], .phone .opts input[type=checkbox] {
  appearance: auto !important;
  -webkit-appearance: auto !important;
  width: 16px !important; height: 16px !important; min-width: 16px;
  margin: 1px 0 0 !important; padding: 0 !important;
  accent-color: var(--moa-primary); flex-shrink: 0;
  position: static !important; border: none !important; background: none !important;
  box-shadow: none !important; border-radius: 0 !important;
}
.phone .opts .radio label:has(input:checked),
.phone .opts .checkbox label:has(input:checked),
.phone .opts .radio label.checked, .phone .opts .checkbox label.checked {
  border-color: var(--moa-primary); background: var(--moa-primary-soft);
}

/* ---------- Voice panel ---------- */

.phone .voice-card { border-color: var(--moa-primary); }
.phone .voice-card .card-body { padding-top: 2px; }
.phone .mic-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 14px; text-align: left; cursor: pointer; user-select: none;
}
.phone .mic-btn {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  background: var(--moa-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 10px rgba(142, 92, 240, .4);
  transition: transform .15s;
}
.phone .mic-row:active .mic-btn { transform: scale(.94); }
.phone .mic-text { flex: 1; }
.phone .mic-text b { display: block; font-size: 14.5px; font-weight: 800; color: var(--moa-ink); }
.phone .mic-text span { display: block; font-size: 12px; color: var(--moa-muted); margin-top: 2px; }
.phone .mic-chev { color: var(--moa-primary); transition: transform .2s; }
.phone .voice-card.open .mic-chev { transform: rotate(180deg); }
.phone .voice-panel { display: none; }
.phone .voice-card.open .voice-panel { display: block; }

.phone .rec-strip {
  display: flex; align-items: center; gap: 10px;
  background: var(--moa-bg); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 12px;
}
.phone .rec-btn {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0; border: none;
  background: var(--moa-primary); color: #fff; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.phone .rec-btn.recording { background: var(--moa-error); animation: pulse 1.4s infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240, 68, 51, .5); }
  50% { box-shadow: 0 0 0 8px rgba(240, 68, 51, 0); }
}
.phone .rec-meta { flex: 1; min-width: 0; }
.phone .rec-meta b { display: block; font-size: 13px; font-weight: 700; }
.phone .rec-meta span { font-size: 11.5px; color: var(--moa-muted); }
.phone .level { display: flex; align-items: flex-end; gap: 2px; height: 20px; }
.phone .level i {
  width: 3px; height: 3px; border-radius: 2px; background: var(--moa-primary);
  transition: height .08s;
}

/* Shiny's fileInput is a label + text box + progress bar; strip it back to the
   original's small square icon button. */
.phone .upload-wrap { flex-shrink: 0; }
.phone .upload-wrap .form-group { margin: 0; }
.phone .upload-wrap .input-group-text,
.phone .upload-wrap .form-control,
.phone .upload-wrap .progress { display: none !important; }
.phone .upload-wrap .btn-file, .phone .upload-wrap .input-group-btn > .btn {
  width: 34px; height: 34px; padding: 0; border-radius: var(--radius);
  background: #fff; border: 1px solid var(--moa-border); color: var(--moa-ink-alt);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}

.phone .stage-list { margin: 0 0 12px; padding: 0; list-style: none; }
.phone .stage {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--moa-muted); padding: 3px 0;
}
.phone .stage .sdot {
  width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--moa-border);
}
.phone .stage.active { color: var(--moa-primary); font-weight: 700; }
.phone .stage.active .sdot {
  border-color: var(--moa-primary); border-top-color: transparent;
  animation: spin .8s linear infinite;
}
.phone .stage.done { color: var(--moa-ink-alt); }
.phone .stage.done .sdot { background: var(--moa-success); border-color: var(--moa-success); }
@keyframes spin { to { transform: rotate(360deg); } }

.phone #transcript, .phone textarea#transcript { min-height: 110px; }
.phone .helper { font-size: 12px; color: var(--moa-muted); margin: 6px 0 0; line-height: 1.45; }

.phone .banner {
  font-size: 12.5px; line-height: 1.45; border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 12px; display: none;
}
.phone .banner.show { display: block; }
.phone .banner.err { background: rgba(240, 68, 51, .09); color: #96241a; }
.phone .banner.ok { background: rgba(18, 183, 106, .10); color: #0a6b40; }

/* ---------- Dev bar (outside the phone) ---------- */

.devbar { position: fixed; top: 70px; right: 14px; z-index: 60; display: flex; gap: 6px; }
.devbar .btn {
  font-size: 12px; font-weight: 600; padding: 7px 12px; border-radius: 8px;
  background: #fff; color: #6b7280; border: 1px solid #e2e2e8;
  box-shadow: 0 2px 8px rgba(20, 22, 40, .08);
}
@media (max-width: 900px) { .devbar { display: none; } }
