/* ===========================================================================
   Channel Publisher — interface styles
   Bootstrap 5 handles the grid and components; this file sets the identity:
   a console for an operator working one-handed on a phone.
   =========================================================================== */

:root {
  --paper:    #EDF1F5;
  --surface:  #FFFFFF;
  --line:     #D5DDE5;
  --ink:      #16202B;
  --muted:    #5D6B7A;
  --console:  #0F1A24;
  --signal:   #0B6FA4;
  --signal-d: #08567F;
  --live:     #157F5F;
  --hold:     #B46B12;
  --stop:     #B23A38;

  --rail: 236px;
  --bar-h: 58px;
  --radius-s: 6px;
  --radius-m: 10px;
  --shadow-panel: 0 1px 2px rgba(22, 32, 43, .07), 0 8px 24px -16px rgba(22, 32, 43, .35);

  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: ui-monospace, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

html, body { height: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
a { color: var(--signal); text-decoration-thickness: 1px; text-underline-offset: 2px; }
h1, h2, h3, h4 { font-weight: 640; letter-spacing: -.011em; color: var(--ink); }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.text-muted, .muted { color: var(--muted) !important; }

:focus-visible { outline: 3px solid rgba(11, 111, 164, .45); outline-offset: 2px; border-radius: 4px; }

/* ----------------------------------------------------------------- shell -- */
.shell { display: flex; min-height: 100dvh; }

.rail {
  width: var(--rail);
  flex: 0 0 var(--rail);
  background: var(--console);
  color: #C9D6E2;
  position: sticky; top: 0; height: 100dvh;
  display: flex; flex-direction: column;
  padding: 18px 12px calc(14px + env(safe-area-inset-bottom, 0px));
}
.rail-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; color: #fff; }
.rail-brand .mark {
  width: 32px; height: 32px; border-radius: 8px; background: var(--signal);
  display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 15px;
}
.rail-brand .name { font-weight: 640; font-size: .98rem; line-height: 1.15; }
.rail-brand .sub { font-size: .72rem; color: #7E93A6; }

.rail-nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.rail-nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--radius-s);
  color: #C9D6E2; text-decoration: none; font-size: .92rem;
}
.rail-nav a .ic { width: 20px; text-align: center; font-size: 1rem; }
.rail-nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.rail-nav a.active { background: var(--signal); color: #fff; font-weight: 560; }
.rail-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255,255,255,.1); font-size: .8rem; }
.rail-foot .who { color: #fff; font-weight: 560; }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--bar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px; position: sticky; top: 0; z-index: 30;
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar .page-title { font-weight: 640; font-size: 1.02rem; margin: 0; }
.topbar .spacer { flex: 1; }

.content { padding: 18px 16px 100px; }
@media (min-width: 992px) { .content { padding: 22px 26px 40px; max-width: 1360px; } }

/* --------------------------------------------------------- mobile navbar -- */
.tabbar { display: none; }
@media (max-width: 991.98px) {
  .rail { display: none; }
  .tabbar {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    background: var(--console);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -6px 18px rgba(15, 26, 36, .22);
  }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    color: #94A8BA; text-decoration: none; font-size: .66rem; padding: 5px 2px; border-radius: 8px;
  }
  .tabbar a .ic { font-size: 1.12rem; }
  .tabbar a.active { color: #fff; background: rgba(255,255,255,.1); }
}

/* --------------------------------------------------------------- panels -- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-panel);
}
.panel + .panel { margin-top: 16px; }
.panel-head {
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.panel-head h2, .panel-head h3 { margin: 0; }
.panel-body { padding: 16px; }

/* Stat tiles: the number leads, the label supports it. */
.stat-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 768px) { .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .stat-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m);
  padding: 14px 14px 12px; border-top: 3px solid var(--signal);
}
.stat.ok   { border-top-color: var(--live); }
.stat.fail { border-top-color: var(--stop); }
.stat.hold { border-top-color: var(--hold); }
.stat .v { font-family: var(--font-num); font-size: 1.85rem; font-weight: 600; line-height: 1.1; }
.stat .k { color: var(--muted); font-size: .8rem; }

/* --------------------------------------------------------- action tiles -- */
.action-bar {
  position: sticky; top: var(--bar-h); z-index: 25;
  background: var(--console);
  padding: 10px;
  display: grid; gap: 8px;
  grid-template-columns: repeat(4, 1fr) 1.6fr;
  align-items: stretch;
}
@media (max-width: 575.98px) {
  .action-bar { grid-template-columns: repeat(4, 1fr); }
  .action-bar .shot-btn { grid-column: 1 / -1; }
}
.act-btn {
  border: 0; border-radius: var(--radius-s); background: #1D2C3A; color: #fff;
  min-height: 62px; padding: 6px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  transition: transform .08s ease, background .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.act-btn .n { font-family: var(--font-num); font-size: 1.5rem; font-weight: 600; line-height: 1; }
.act-btn .d { font-family: var(--font-num); font-size: .72rem; color: #9DB2C4; }
.act-btn:hover:not(:disabled) { background: #26394B; }
.act-btn:active:not(:disabled) { transform: scale(.97); }
.act-btn:disabled { opacity: .45; cursor: not-allowed; }
.act-btn.busy { background: var(--signal-d); }
.act-btn.done { background: var(--live); }
.act-btn.error { background: var(--stop); }
.shot-btn {
  border: 0; border-radius: var(--radius-s); background: var(--signal); color: #fff;
  min-height: 62px; font-weight: 620; font-size: 1rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  -webkit-tap-highlight-color: transparent;
}
.shot-btn:hover { background: var(--signal-d); }
.shot-btn:active { transform: scale(.99); }

/* ------------------------------------------------------------ workspace -- */
.workspace-wrap { background: var(--console); padding: 0 10px 10px; }
.workspace-frame {
  position: relative; background: #fff; border-radius: var(--radius-s); overflow: hidden;
  height: calc(100dvh - var(--bar-h) - 92px);
  min-height: 320px;
}
@media (max-width: 991.98px) {
  .workspace-frame { height: calc(100dvh - var(--bar-h) - 210px); }
}
.workspace-frame iframe { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
.frame-notice {
  position: absolute; inset: 0; display: none; place-items: center; text-align: center;
  padding: 24px; background: #F7F9FB;
}
.frame-notice.show { display: grid; }
.frame-notice .inner { max-width: 440px; }

.workspace-meta {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 8px 10px; background: var(--console); color: #9DB2C4; font-size: .8rem;
}
.workspace-meta .url { font-family: var(--font-num); color: #C9D6E2; word-break: break-all; }

/* --------------------------------------------------------------- tables -- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.grid { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.grid th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: .76rem;
  padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #F7F9FB;
}
table.grid td { padding: 10px 12px; border-bottom: 1px solid #E8EDF2; vertical-align: top; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid td.num, table.grid td .num { font-family: var(--font-num); }
.msg-cell { max-width: 380px; white-space: pre-wrap; word-break: break-word; font-size: .82rem; color: #33424F; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 560;
  background: #E7EDF3; color: #35485B;
}
.pill.ok   { background: #DFF1E9; color: #0E6449; }
.pill.fail { background: #FBE6E5; color: #8E2C2A; }
.pill.hold { background: #FBEEDC; color: #8A5210; }
.pill.dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* --------------------------------------------------------------- forms --- */
.form-label { font-weight: 560; font-size: .86rem; margin-bottom: 4px; }
.form-control, .form-select {
  border: 1px solid var(--line); border-radius: var(--radius-s); padding: 9px 11px;
  font-size: 16px; /* keeps Android from zooming on focus */
  background: #fff; color: var(--ink);
}
.form-control:focus, .form-select:focus {
  border-color: var(--signal); box-shadow: 0 0 0 3px rgba(11, 111, 164, .16);
}
textarea.form-control { line-height: 1.5; }
textarea.tpl { font-family: var(--font-num); font-size: 14px; min-height: 190px; }
.form-hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }

.btn { border-radius: var(--radius-s); font-weight: 560; padding: 9px 16px; }
.btn-primary { background: var(--signal); border-color: var(--signal); }
.btn-primary:hover, .btn-primary:focus { background: var(--signal-d); border-color: var(--signal-d); }
.btn-outline-secondary { border-color: var(--line); color: var(--ink); }
.btn-lg-touch { min-height: 48px; font-size: 1rem; }

.var-chip {
  font-family: var(--font-num); font-size: .78rem; border: 1px dashed var(--line);
  background: #F5F8FA; border-radius: 5px; padding: 3px 7px; cursor: pointer; color: var(--signal-d);
}
.var-chip:hover { background: #EAF2F7; border-style: solid; }

.preview-box {
  background: #F5F8FA; border: 1px solid var(--line); border-radius: var(--radius-s);
  padding: 12px; white-space: pre-wrap; word-break: break-word; font-size: .9rem; min-height: 90px;
}

/* --------------------------------------------------------------- toasts -- */
.toast-stack {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(80px + env(safe-area-inset-bottom, 0px)); z-index: 1080;
  display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100vw - 24px));
}
@media (min-width: 992px) { .toast-stack { bottom: 24px; left: auto; right: 24px; transform: none; } }
.toast-item {
  background: var(--console); color: #fff; border-radius: var(--radius-s);
  padding: 12px 14px; font-size: .9rem; display: flex; gap: 10px; align-items: flex-start;
  box-shadow: 0 10px 30px -10px rgba(15, 26, 36, .6);
}
.toast-item.ok   { background: var(--live); }
.toast-item.fail { background: var(--stop); }
.toast-item.warn { background: var(--hold); }

/* ---------------------------------------------------------- screenshot --- */
.shot-preview {
  background: #0F1A24; border-radius: var(--radius-s); padding: 8px;
  display: grid; place-items: center; min-height: 180px;
}
.shot-preview img { max-width: 100%; max-height: 46dvh; border-radius: 4px; display: block; }
.mode-toggle { display: flex; gap: 6px; flex-wrap: wrap; }
.mode-toggle .btn { flex: 1 1 auto; }

.login-page {
  min-height: 100dvh; display: grid; place-items: center;
  background: radial-gradient(circle at 20% 10%, #1B2D3D 0%, var(--console) 60%);
  padding: 24px 16px;
}
.login-card { width: min(410px, 100%); background: var(--surface); border-radius: 12px; padding: 26px 24px; }
.login-card .mark {
  width: 44px; height: 44px; border-radius: 10px; background: var(--signal); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 20px; margin-bottom: 14px;
}

.empty {
  text-align: center; padding: 38px 18px; color: var(--muted);
}
.empty .big { font-size: 1.6rem; margin-bottom: 6px; }

.spinner-inline {
  width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff; border-radius: 50%; display: inline-block;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
