/* ============================================================
   Rayna Tours · Visa Agent Runner — ops console
   Palette, type and components come from the customer intake app
   (webapp/static/css/styles.css); the layout is a working surface:
   destinations rail on the left, setup + live log on the right,
   everything on one screen with nothing navigating away.
   ============================================================ */

:root {
  --orange: #F2600C;
  --orange-dark: #D14E04;
  --orange-soft: #FDEBDD;
  --orange-tint: #FFF7F0;
  --bg: #FAF7F2;
  --card: #FFFFFF;
  --ink: #1F2933;
  --muted: #6B7280;
  --line: #F3E8DF;
  --line-strong: #E8D9CB;
  --success: #0E9F6E;
  --success-bg: #F4FBF8;
  --error: #DC2626;
  --error-bg: #FEF2F2;
  --amber: #B45309;
  --amber-line: #E9C46A;
  --amber-bg: #FFFBEB;
  --shadow-sm: 0 1px 3px rgba(31, 41, 51, .07), 0 1px 2px rgba(31, 41, 51, .05);
  --shadow-md: 0 10px 30px -8px rgba(31, 41, 51, .16);
  --font-head: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --topbar-h: 58px;
}

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

[hidden] { display: none !important; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-head); line-height: 1.2; }
button { font-family: inherit; cursor: pointer; }
.spacer { flex: 1; }

/* ---------- Topbar ---------- */

.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.wordmark { display: inline-flex; align-items: center; text-decoration: none; }
.wordmark-logo { height: 30px; width: auto; display: block; }

.topbar-chip {
  font-size: .7rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--orange-dark); background: var(--orange-soft);
  padding: 5px 11px; border-radius: 999px;
}

/* ---------- Shell: rail + work area, exactly one screen ---------- */

.shell {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  gap: 16px;
  padding: 16px 20px;
  height: calc(100vh - var(--topbar-h));
  max-width: 1520px; margin: 0 auto;
}

/* ---------- Left rail ---------- */

.rail {
  display: flex; flex-direction: column; min-height: 0; gap: 6px;
}

.rail-label {
  display: flex; align-items: baseline; gap: 6px;
  font-size: .68rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted);
  padding: 2px 4px 6px;
}
.rail-label .count { font-weight: 500; letter-spacing: 0; text-transform: none; font-size: .72rem; }

.rail-list {
  display: flex; flex-direction: column; gap: 4px;
  overflow-y: auto; min-height: 0;
  padding-right: 2px;
}

/* one destination row — flag, country, portal. The selected row gets the
   orange bar so you can see the active agent without reading. */
.agent-card {
  position: relative;
  display: flex; align-items: center; gap: 10px; text-align: left;
  width: 100%; font: inherit; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: 11px;
  padding: 8px 11px;
  transition: border-color .14s ease, background .14s ease;
}
.agent-card:hover { border-color: var(--line-strong); background: #FFFDFB; }
.agent-card.selected {
  border-color: #F7C9A8; background: var(--orange-tint);
  box-shadow: inset 3px 0 0 var(--orange);
  padding-left: 14px;
}

/* real SVG flags, same set the intake form ships — Windows renders emoji
   regional-indicator pairs as bare letters */
.agent-flag {
  width: 28px; height: auto; flex: 0 0 auto; border-radius: 3px;
  box-shadow: 0 1px 3px rgba(31, 41, 51, .2), 0 0 0 1px rgba(31, 41, 51, .07);
}
.agent-card .body { min-width: 0; display: flex; flex-direction: column; }
.agent-card .name { font-weight: 600; font-size: .88rem; }
.agent-card .portal {
  color: var(--muted); font-size: .72rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* a green dot on the row whose agent is currently running */
.agent-card .live { margin-left: auto; width: 7px; height: 7px; border-radius: 50%; background: var(--orange); display: none; }
.agent-card.running .live { display: block; animation: pulse 1.6s ease-out infinite; }
@keyframes pulse {
  70%  { box-shadow: 0 0 0 7px rgba(242, 96, 12, 0); }
  100% { box-shadow: 0 0 0 0 rgba(242, 96, 12, 0); }
}

/* ---------- Run history (rail, bottom) ---------- */

.rail-history {
  display: flex; flex-direction: column; min-height: 96px;
  flex: 1; margin-top: 10px; padding-top: 8px;
  border-top: 1px solid var(--line);
}

.run-list { list-style: none; overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 2px; }

.run-item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px;
  padding: 6px 8px; border-radius: 9px;
  font-size: .78rem;
}
.run-item:hover { background: var(--card); }
.run-item .who { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-item .when { color: var(--muted); font-size: .72rem; }
.run-item .res { font-weight: 600; font-size: .72rem; text-align: right; white-space: nowrap; }
.run-item .log { grid-column: 2; text-align: right; font-size: .72rem; color: var(--orange-dark); text-decoration: none; font-weight: 600; }
.run-item .log:hover { text-decoration: underline; }

.result-ok { color: var(--success); }
.result-bad { color: var(--error); }
.result-running { color: var(--amber); }

.rail-foot { color: var(--muted); font-size: .68rem; padding: 8px 4px 0; }

/* ---------- Work area ---------- */

/* the setup row always gets its full content — never squeezed, so nothing
   in it clips or grows a scrollbar. The live row has a FIXED floor and takes
   the leftover — never sized from the log's content, so a long log scrolls
   inside instead of growing the box. When a short window can't fit both,
   this column scrolls as a whole rather than crushing either panel. */
.work {
  display: grid; grid-template-rows: max-content minmax(min(360px, 42vh), 1fr);
  gap: 16px; min-height: 0;
  overflow-y: auto;
}

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow-sm);
  padding: 16px 20px;
  display: flex; flex-direction: column; min-height: 0;
  overflow: hidden;  /* a squeezed panel clips instead of bleeding over its neighbour */
}

.panel-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.head-flag {
  width: 30px; height: auto; border-radius: 3px;
  box-shadow: 0 1px 3px rgba(31, 41, 51, .2), 0 0 0 1px rgba(31, 41, 51, .07);
}
.panel-head h2 { font-size: 1.1rem; font-weight: 600; }
.panel-head a { color: var(--orange-dark); font-size: .8rem; font-weight: 500; text-decoration: none; }
.panel-head a:hover { text-decoration: underline; }

.panel-title {
  font-size: .68rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted);
}

.notes { color: var(--muted); font-size: .82rem; margin: 6px 0 12px; }

.panel-body { overflow-y: auto; min-height: 0; }

/* ---------- Options ---------- */

/* three across: every agent's flags fit one band, no scrolling to find them */
#options-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
#options-form .field { grid-column: 1 / -1; }

.field label { display: block; font-weight: 600; font-size: .82rem; margin-bottom: 5px; }
.field .help { font-size: .74rem; color: var(--muted); margin-top: 4px; }

.field input[type="text"], .field select, #customer-select {
  width: 100%; font-family: var(--font-body); font-size: .92rem; color: var(--ink);
  background: #FFFDFB; border: 1.5px solid var(--line-strong); border-radius: 10px;
  padding: 9px 12px;
  transition: border-color .14s ease, box-shadow .14s ease;
}
.field input[type="text"]:focus, .field select:focus, #customer-select:focus {
  outline: none; border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(242, 96, 12, .13);
}

#customer-row { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
#customer-fixed code {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: .72rem;
  color: var(--orange-dark); background: var(--orange-tint); padding: 1px 5px; border-radius: 5px;
}

/* flags read as on/off at a glance, in the intake form's orange-when-active
   language rather than as bare checkboxes */
.opt-toggle {
  display: flex; align-items: center; gap: 9px; cursor: pointer;
  border: 1.5px solid var(--line); border-radius: 10px; padding: 8px 10px;
  transition: border-color .14s ease, background .14s ease;
}
.opt-toggle:hover { border-color: var(--line-strong); background: #FFFDFB; }
.opt-toggle:has(input:checked) { border-color: #F7C9A8; background: var(--orange-tint); }
.opt-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }

.switch {
  flex: 0 0 auto; width: 34px; height: 20px; border-radius: 999px;
  background: #EDE3D9; border: 1.5px solid var(--line-strong);
  position: relative; transition: background .16s ease, border-color .16s ease;
}
.switch::after {
  content: ''; position: absolute; top: 1px; left: 1px;
  width: 14px; height: 14px; border-radius: 50%; background: #fff;
  box-shadow: var(--shadow-sm); transition: transform .16s ease;
}
.opt-toggle input:checked + .switch { background: var(--orange); border-color: var(--orange); }
.opt-toggle input:checked + .switch::after { transform: translateX(14px); }
.opt-toggle input:focus-visible + .switch { box-shadow: 0 0 0 3px rgba(242, 96, 12, .2); }

.opt-toggle .toggle-text { display: flex; flex-direction: column; min-width: 0; }
.opt-toggle .toggle-label { font-weight: 600; font-size: .84rem; }
.opt-toggle .help {
  font-size: .72rem; color: var(--muted); line-height: 1.35;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- Run row ---------- */

.run-row {
  display: flex; align-items: center; justify-content: flex-end; gap: 14px; flex-wrap: wrap;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line);
}
.error { color: var(--error); font-size: .82rem; font-weight: 500; margin-right: auto; }

/* ---------- Buttons & chips ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 999px;
  font-family: var(--font-head); font-weight: 600; font-size: .92rem;
  padding: 10px 22px;
  transition: background .16s ease, border-color .16s ease, transform .16s ease, box-shadow .16s ease;
}
.btn svg { width: 17px; height: 17px; }

.btn-primary { background: var(--orange); color: #fff; box-shadow: var(--shadow-md); }
.btn-primary:hover { background: var(--orange-dark); transform: translateY(-1px); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-secondary { background: transparent; color: var(--orange-dark); border: 1.5px solid var(--orange); text-decoration: none; }
.btn-secondary:hover { background: var(--orange-soft); }
.btn-secondary:disabled { opacity: .45; cursor: not-allowed; }

.btn-danger { background: var(--error-bg); color: var(--error); border: 1.5px solid #FECACA; }
.btn-danger:hover { border-color: var(--error); background: #FEE2E2; }

.btn.small { padding: 6px 13px; font-size: .78rem; }

.chip {
  display: inline-flex; align-items: center;
  border-radius: 999px; padding: 4px 11px;
  font-size: .72rem; font-weight: 600;
  color: var(--muted); background: var(--bg); border: 1px solid var(--line-strong);
}
.chip.ok { color: var(--success); background: var(--success-bg); border-color: #BFE8D9; }
.chip.bad { color: var(--error); background: var(--error-bg); border-color: #FECACA; }
.chip.busy { color: var(--amber); background: var(--amber-bg); border-color: var(--amber-line); }

/* ---------- Live run panel ---------- */

.panel-live { min-height: 0; }
.live-head { padding-bottom: 10px; }
.run-label { font-weight: 600; font-size: .9rem; }

/* ---------- Live-run switcher (several agents at once) ---------- */

.run-tabs {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 0 0 10px;
  /* many concurrent runs must not eat the console: cap at ~2 rows, scroll */
  max-height: 76px; overflow-y: auto; flex: none;
}
.run-tab {
  display: inline-flex; align-items: center; gap: 7px;
  max-width: 210px; padding: 5px 11px;
  background: #FFFDFB; border: 1.5px solid var(--line-strong); border-radius: 999px;
  font-family: var(--font-body); font-size: .78rem; font-weight: 500; color: var(--muted);
  cursor: pointer; transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.run-tab:hover { border-color: var(--orange); color: var(--ink); }
.run-tab .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-tab .dot {
  flex: 0 0 6px; width: 6px; height: 6px; border-radius: 50%;
  background: var(--line-strong);
}
.run-tab.live .dot { background: var(--orange); animation: pulse 1.6s ease-out infinite; }
.run-tab.current {
  border-color: var(--orange); background: var(--orange-tint); color: var(--orange-dark);
  font-weight: 600;
}

/* the floor keeps the log readable on short windows / many run tabs; kept
   small enough that head + tabs + stdin always fit inside the row's 360px
   floor. The ≤900px media query replaces it with a fixed height when stacked */
.console-area { flex: 1; min-height: 120px; display: flex; }

/* idle state: same footprint as the log, but a dashed placeholder rather
   than a large empty black rectangle */
.console-empty {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 2px dashed var(--line-strong); border-radius: 12px;
  background: #FFFDFB; text-align: center; padding: 16px;
  color: var(--muted); font-size: .86rem;
}
.console-empty-art { font-size: 26px; margin-bottom: 4px; opacity: .8; }
.console-empty strong { color: var(--ink); font-weight: 600; }
.console-empty-sub { font-size: .78rem; opacity: .8; }

#terminal {
  flex: 1; min-height: 0;
  background: #15123A;
  border: 1px solid #2E2560;
  border-radius: 12px;
  padding: 12px 14px;
  overflow: auto;
  color: #E7E2F3;
  font: 12.5px/1.55 "SF Mono", ui-monospace, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}
#terminal:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(242, 96, 12, .25); }
#terminal .you { color: #FFB27A; }
#terminal .runner { color: var(--amber-line); }

.stdin-row { display: flex; gap: 8px; margin-top: 10px; }
.stdin-row input {
  flex: 1; min-width: 0;
  background: #FFFDFB; color: var(--ink);
  border: 1.5px solid var(--line-strong); border-radius: 10px;
  padding: 8px 12px;
  font: 12.5px "SF Mono", ui-monospace, Menlo, monospace;
  transition: border-color .14s ease, box-shadow .14s ease;
}
.stdin-row input:focus {
  outline: none; border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(242, 96, 12, .13);
}
.stdin-row input:disabled { opacity: .5; }

/* ---------- Narrow screens ---------- */

@media (max-width: 1080px) {
  #options-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* below this the two-column shell stops earning its keep: stack it and let
   the page scroll like a normal document */
@media (max-width: 900px), (max-height: 680px) {
  /* one column, and `display: contents` on the rail lets its parts be
     ordered around the work panels — otherwise 50 history rows sit between
     you and the Run button */
  .shell { display: flex; flex-direction: column; height: auto; gap: 12px; padding: 12px 16px; }
  .rail { display: contents; }
  .shell > .rail-label, .rail > .rail-label { order: 1; }
  .rail-list {
    order: 2; flex-direction: row; overflow-x: auto; padding-bottom: 4px;
  }
  .agent-card { flex: 0 0 auto; width: 178px; }
  .work { order: 3; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
  .rail-history { order: 4; flex: none; margin-top: 0; }
  .run-list { max-height: 220px; }
  .rail-foot { order: 5; text-align: center; }

  .panel-body { overflow: visible; }
  /* fix the height on the area, not the children — `flex: none` on them
     would collapse their width to the text */
  .console-area { height: 300px; }
}

@media (max-width: 560px) {
  #options-form { grid-template-columns: 1fr; }
  .topbar-chip { display: none; }
  .run-row .btn-primary { width: 100%; }
}

/* ---------- Signed-in user + login page ---------- */
.chip-user { font-weight: 600; color: var(--ink); }
#logout-form { margin: 0; }

.login-body { min-height: 100vh; display: grid; place-items: center; }
.login-shell { width: 100%; max-width: 400px; padding: 24px 16px; }
.login-card {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 32px 28px; box-shadow: var(--shadow-md);
}
.login-card .topbar-chip { align-self: flex-start; }
.login-logo { width: 132px; height: auto; margin-bottom: 4px; }
.login-title { font-size: 1.5rem; margin: 8px 0 0; }
.login-sub { color: var(--muted); font-size: .9rem; margin: 0 0 8px; }
.login-label { font-weight: 600; font-size: .85rem; margin-top: 6px; }
.login-input {
  font: inherit; padding: 11px 13px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: #FFFDFB; color: var(--ink);
}
.login-input:focus { outline: 2px solid var(--orange); outline-offset: 1px; border-color: var(--orange); }
.login-submit { margin-top: 14px; justify-content: center; width: 100%; }
.login-error {
  margin: 0; padding: 10px 12px; border-radius: 10px; font-size: .88rem;
  color: var(--error); background: var(--error-bg); border: 1px solid #FECACA;
}
.login-error[hidden] { display: none; }
.login-foot { text-align: center; color: var(--muted); font-size: .8rem; margin-top: 16px; }
