:root {
  color-scheme: dark;
  --bg: #070b14;
  --panel: rgba(14, 22, 36, .78);
  --panel-strong: rgba(18, 30, 50, .94);
  --line: rgba(148, 163, 184, .2);
  --text: #edf5ff;
  --muted: #9fb0c7;
  --accent: #38bdf8;
  --success: #34d399;
  --danger: #fb7185;
  --warn: #fbbf24;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  width: 380px;
  min-height: 650px;
  margin: 0;
  background:
    radial-gradient(circle at 20% 0%, rgba(56, 189, 248, .18), transparent 32%),
    linear-gradient(160deg, #070b14 0%, #0b1220 52%, #101827 100%);
  color: var(--text);
  font: 13px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; }
.icon-sprite { display: none; }
.shell { padding: 14px; }

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "brand badge"
    "actions actions";
  align-items: center;
  gap: 8px 10px;
  padding: 8px 2px 12px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

h1, h2, p { margin: 0; }
h1 { font-size: 23px; line-height: 1.05; }
h2 { font-size: 14px; }

.state-badge,
.mini-badge {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(148, 163, 184, .1);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
}

.state-badge { min-width: 106px; }
.state-badge.active { color: #b9f6ff; border-color: rgba(56, 189, 248, .45); background: rgba(56, 189, 248, .14); }
.state-badge.waiting { color: #fde68a; border-color: rgba(251, 191, 36, .45); background: rgba(251, 191, 36, .12); }
.state-badge.otp, .state-badge.error { color: #fecdd3; border-color: rgba(251, 113, 133, .45); background: rgba(251, 113, 133, .12); }
.state-badge.done { color: #bbf7d0; border-color: rgba(52, 211, 153, .45); background: rgba(52, 211, 153, .12); }

.panel {
  margin-bottom: 9px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel-strong), var(--panel));
  box-shadow: 0 18px 40px rgba(0, 0, 0, .22);
  backdrop-filter: blur(18px);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
}

.section-title .mini-badge { margin-left: auto; }

svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  flex: 0 0 auto;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.status-grid article,
.preview-card,
.last-action {
  min-width: 0;
  padding: 8px;
  border: 1px solid rgba(148, 163, 184, .16);
  border-radius: 7px;
  background: rgba(2, 6, 23, .28);
}

.status-grid span,
.preview-card span,
label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.status-grid strong,
.preview-card strong {
  display: block;
  margin-top: 3px;
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 12px;
}

.last-action {
  display: grid;
  gap: 3px;
  margin-top: 7px;
}

.last-action span { font-weight: 800; }
.last-action small { color: var(--muted); overflow-wrap: anywhere; }

.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 8px 9px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  font-size: 12px;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn.primary { background: linear-gradient(135deg, #0891b2, #22c55e); box-shadow: 0 12px 24px rgba(8, 145, 178, .24); }
.btn.secondary { border-color: rgba(56, 189, 248, .34); background: rgba(56, 189, 248, .12); }
.btn.ghost { border-color: rgba(148, 163, 184, .24); background: rgba(148, 163, 184, .08); }
.btn.danger { border-color: rgba(251, 113, 133, .36); background: rgba(127, 29, 29, .52); }
.wide-btn { width: 100%; margin-top: 8px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.scheduler-grid {
  grid-template-columns: 1fr 1fr;
}

label {
  display: grid;
  gap: 5px;
}

input, select {
  width: 100%;
  min-height: 34px;
  border: 1px solid rgba(148, 163, 184, .22);
  border-radius: 7px;
  outline: none;
  background: rgba(2, 6, 23, .44);
  color: var(--text);
  padding: 7px 8px;
}

input:focus, select:focus {
  border-color: rgba(56, 189, 248, .75);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, .12);
}

textarea {
  width: 100%;
  min-height: 118px;
  resize: vertical;
  border: 1px solid rgba(148, 163, 184, .22);
  border-radius: 7px;
  outline: none;
  background: rgba(2, 6, 23, .44);
  color: var(--text);
  padding: 8px;
}

textarea:focus {
  border-color: rgba(56, 189, 248, .75);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, .12);
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding-top: 17px;
}

.switch-row input {
  width: 16px;
  min-height: auto;
}

.button-row {
  display: grid;
  gap: 7px;
  margin-top: 8px;
}

.button-row.three {
  grid-template-columns: 1.3fr .8fr .8fr;
}

.preview-card {
  margin-top: 8px;
}

.toast-viewport {
  position: fixed;
  right: 14px;
  bottom: 14px;
  display: grid;
  gap: 8px;
  width: min(310px, calc(100vw - 28px));
  pointer-events: none;
  z-index: 100;
}

.toast {
  transform: translateY(10px);
  opacity: 0;
  padding: 10px 12px;
  border: 1px solid rgba(52, 211, 153, .38);
  border-radius: 8px;
  background: rgba(6, 78, 59, .94);
  color: #ecfdf5;
  box-shadow: 0 18px 36px rgba(0, 0, 0, .28);
  transition: opacity .2s ease, transform .2s ease;
}

.toast.error {
  border-color: rgba(251, 113, 133, .4);
  background: rgba(127, 29, 29, .94);
  color: #fff1f2;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}


@media (max-width: 440px) {
  body { width: 380px; }
  .status-grid, .form-grid, .quick-actions, .button-row.three { grid-template-columns: 1fr; }
  .switch-row { padding-top: 0; }
  .hdr-btns { gap: 5px; }
  .hdr-panel span { display: none; }
}

/* ── Header top-bar layout update ─────────────────────────── */
.topbar-brand {
  grid-area: brand;
  min-width: 0;
}

.topbar-brand .eyebrow {
  max-width: 150px;
  line-height: 1.18;
}

.topbar-controls {
  display: contents;
}

/* ── Compact header Start / Stop buttons ──────────────────── */
.hdr-btns {
  grid-area: actions;
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
  width: 100%;
}

.hdr-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 29px;
  min-width: 0;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: .04em;
  transition:
    transform .15s ease,
    box-shadow .15s ease,
    background .15s ease,
    border-color .15s ease;
  white-space: nowrap;
}

.state-badge {
  grid-area: badge;
  justify-self: end;
}

.hdr-btn svg {
  width: 13px;
  height: 13px;
  fill: currentColor;
  flex: 0 0 auto;
}

/* Start — green glassmorphism */
.hdr-start {
  color: #bbf7d0;
  background: rgba(34, 197, 94, .18);
  border-color: rgba(34, 197, 94, .40);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
}
.hdr-start:hover {
  transform: translateY(-1px);
  background: rgba(34, 197, 94, .28);
  border-color: rgba(34, 197, 94, .70);
  box-shadow: 0 0 12px rgba(34, 197, 94, .32);
}
.hdr-start:active {
  transform: translateY(0);
  box-shadow: 0 0 18px rgba(34, 197, 94, .50);
}
.hdr-start.loading {
  opacity: .65;
  cursor: not-allowed;
  pointer-events: none;
  animation: hdrPulse 1s ease-in-out infinite;
}

body[data-active-context="fiva"] .hdr-start {
  color: #bae6fd;
  background: rgba(14, 165, 233, .18);
  border-color: rgba(14, 165, 233, .42);
}

body[data-active-context="fiva"] .hdr-start:hover {
  background: rgba(14, 165, 233, .28);
  border-color: rgba(14, 165, 233, .7);
  box-shadow: 0 0 12px rgba(14, 165, 233, .3);
}

body[data-active-context="fiva"] .hdr-stop {
  color: #fecdd3;
  background: rgba(190, 18, 60, .18);
  border-color: rgba(251, 113, 133, .42);
}

/* Stop — red glassmorphism */
.hdr-stop {
  color: #fecdd3;
  background: rgba(251, 113, 133, .14);
  border-color: rgba(251, 113, 133, .36);
  box-shadow: 0 0 0 0 rgba(251, 113, 133, 0);
}
.hdr-stop:hover {
  transform: translateY(-1px);
  background: rgba(251, 113, 133, .26);
  border-color: rgba(251, 113, 133, .65);
  box-shadow: 0 0 12px rgba(251, 113, 133, .28);
}
.hdr-stop:active {
  transform: translateY(0);
  box-shadow: 0 0 18px rgba(251, 113, 133, .46);
}

.hdr-panel {
  color: #bfdbfe;
  background: rgba(59, 130, 246, .14);
  border-color: rgba(59, 130, 246, .34);
}
.hdr-panel:hover {
  transform: translateY(-1px);
  background: rgba(59, 130, 246, .24);
  border-color: rgba(59, 130, 246, .62);
  box-shadow: 0 0 12px rgba(59, 130, 246, .24);
}

/* Loading pulse animation */
@keyframes hdrPulse {
  0%, 100% { opacity: .65; }
  50%       { opacity: 1;   }
}

/* ── Header status strip ──────────────────────────────────── */
.hdr-strip {
  min-height: 0;
  max-height: 0;
  overflow: hidden;
  margin: -4px 0 6px;
  padding: 0 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  transition: max-height .25s ease, opacity .25s ease;
  opacity: 0;
}
.hdr-strip.is-visible {
  max-height: 22px;
  opacity: 1;
}
.hdr-strip.is-error { color: var(--danger); }
.hdr-strip.is-success { color: var(--success); }

.tab-context-notice {
  margin: 0 0 9px;
  padding: 8px 10px;
  border: 1px solid rgba(148, 163, 184, .18);
  border-radius: 8px;
  background: rgba(2, 6, 23, .3);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.tab-context-notice.is-active {
  border-color: rgba(52, 211, 153, .34);
  background: rgba(52, 211, 153, .09);
  color: #bbf7d0;
}

.tab-context-notice.is-passive {
  border-color: rgba(251, 191, 36, .34);
  background: rgba(251, 191, 36, .09);
  color: #fde68a;
}

/* FIVA module */
.popup-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin: 0 0 9px;
  padding: 4px;
  border: 1px solid rgba(148, 163, 184, .18);
  border-radius: 8px;
  background: rgba(2, 6, 23, .26);
}

.popup-tab {
  min-height: 32px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.popup-tab.is-active {
  border-color: rgba(56, 189, 248, .42);
  background: rgba(56, 189, 248, .14);
  color: var(--text);
}

.popup-view[hidden] { display: none; }

.fiva-subtitle {
  color: var(--muted);
  font-size: 12px;
}

.fiva-dropzone {
  display: grid;
  place-items: center;
  gap: 5px;
  min-height: 112px;
  padding: 14px;
  border: 1px dashed rgba(56, 189, 248, .45);
  border-radius: 8px;
  background: rgba(56, 189, 248, .08);
  cursor: pointer;
  text-align: center;
}

.fiva-dropzone.is-dragging {
  border-color: rgba(52, 211, 153, .8);
  background: rgba(52, 211, 153, .12);
}

.fiva-dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.fiva-dropzone strong {
  color: var(--text);
  font-size: 14px;
}

.fiva-paste-card,
.fiva-paste-panel {
  display: grid;
  gap: 8px;
}

.fiva-paste-panel[hidden] {
  display: none;
}

.fiva-dropzone[data-state="UPLOADING"],
.fiva-dropzone[data-state="PARSING"] {
  border-color: rgba(14, 165, 233, .72);
  background: rgba(14, 165, 233, .13);
}

.fiva-dropzone[data-state="READY"],
.fiva-dropzone[data-state="SUCCESS"] {
  border-color: rgba(52, 211, 153, .72);
  background: rgba(52, 211, 153, .11);
}

.fiva-dropzone[data-state="FAILED"] {
  border-color: rgba(248, 113, 113, .72);
  background: rgba(248, 113, 113, .11);
}

.button-row.two {
  grid-template-columns: 1fr 1fr;
}

.fiva-action-card {
  display: grid;
  gap: 8px;
}

.fiva-start-btn {
  min-height: 46px;
  width: 100%;
  font-size: 13px;
  letter-spacing: 0;
}

.fiva-busy {
  opacity: .62;
}

.fiva-busy .fiva-action-card button,
.fiva-busy .fiva-dropzone {
  pointer-events: none;
}

.fiva-activity-panel {
  min-height: 142px;
}

.fiva-activity-list {
  display: grid;
  gap: 7px;
  min-height: 82px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.fiva-activity-list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 22px;
  padding: 7px 8px;
  border: 1px solid rgba(148, 163, 184, .14);
  border-radius: 7px;
  background: rgba(2, 6, 23, .24);
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.fiva-activity-list li::before {
  content: "";
  width: 6px;
  height: 6px;
  margin-top: 5px;
  border-radius: 999px;
  background: var(--success);
  flex: 0 0 auto;
}

.fiva-activity-list li.warn::before { background: var(--warn); }
.fiva-activity-list li.error::before { background: var(--danger); }

.fiva-status-line {
  margin-top: 10px;
  padding: 8px 9px;
  border: 1px solid rgba(148, 163, 184, .16);
  border-radius: 7px;
  background: rgba(15, 23, 42, .58);
  color: var(--text);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

@media (max-width: 440px) {
  body { width: 380px; }
  .button-row.two { grid-template-columns: 1fr; }
}

/* OTP Pulse alarm overlay for Popup UI */
.otp-pulse-active {
  animation: otpPulseBg 1s ease-in-out infinite;
}
@keyframes otpPulseBg {
  0%, 100% { background: linear-gradient(160deg, #070b14 0%, #0b1220 52%, #101827 100%); }
  50% { background: linear-gradient(160deg, #1f0808 0%, #170505 52%, #2d0a0a 100%); }
}
