/* The operator console's stylesheet — everything index.html used to
 * carry in its <style> block, in a file of its own. */
  :root {
    color-scheme: light;
    --bg: #F6F7FA; --surface: #FFFFFF; --surface-2: #F1F3F8;
    --hover: rgba(28,36,48,.05);
    --text: #1C2430; --text-2: #66707E; --border: #E6E9F0;
    --line-soft: #F0F2F7;
    --primary: #3B6FE0; --on-primary: #fff;
    --accent: #2C55B0;
    --selected: #EDF2FE; --selected-text: #2C55B0;
    --danger: #C6493D; --ok: #1E8E5A; --warn: #A56A00;
    /* The activity chart's two series. Validated as a pair (CVD ΔE and
     * contrast) against BOTH surfaces, which is why the same hexes serve
     * light and dark — do not swap in the status greens here, those are
     * reserved for state. */
    --chart-out: #3B6FE0; --chart-in: #2E9E8F;
    --danger-soft: #FBECEA; --ok-soft: #E7F5EE; --warn-soft: #F6EFDF;
    --chip: #F1F3F8;
    --shadow: 0 1px 2px rgba(28,36,48,.05);
    --pop: 0 8px 28px rgba(28,36,48,.16);
  }
  :root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #12161C; --surface: #1A202A; --surface-2: #222A36;
    --hover: rgba(231,236,244,.06);
    --text: #E7ECF4; --text-2: #97A1AE; --border: #2A323E;
    --line-soft: #222A36;
    --primary: #4C79E0; --on-primary: #fff;
    --accent: #8FB0F5;
    --selected: rgba(143,176,245,.16); --selected-text: #AFC7F8;
    --danger: #E8867C; --ok: #59C08A; --warn: #E0B45A;
    --danger-soft: rgba(232,134,124,.14); --ok-soft: rgba(89,192,138,.14);
    --warn-soft: rgba(224,180,90,.14);
    --chip: #222A36;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    --pop: 0 8px 28px rgba(0,0,0,.5);
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      color-scheme: dark;
      --bg: #12161C; --surface: #1A202A; --surface-2: #222A36;
      --hover: rgba(231,236,244,.06);
      --text: #E7ECF4; --text-2: #97A1AE; --border: #2A323E;
      --line-soft: #222A36;
      --primary: #4C79E0; --on-primary: #fff;
      --accent: #8FB0F5;
      --selected: rgba(143,176,245,.16); --selected-text: #AFC7F8;
      --danger: #E8867C; --ok: #59C08A; --warn: #E0B45A;
      --danger-soft: rgba(232,134,124,.14); --ok-soft: rgba(89,192,138,.14);
      --warn-soft: rgba(224,180,90,.14);
      --chip: #222A36;
      --shadow: 0 1px 2px rgba(0,0,0,.3);
      --pop: 0 8px 28px rgba(0,0,0,.5);
    }
  }

  * { box-sizing: border-box; }
  html, body { height: 100%; }
  body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui,
                 "Instrument Sans", Arial, sans-serif;
    font-size: 14px; color: var(--text); background: var(--bg);
    -webkit-font-smoothing: antialiased;
  }
  button, input, textarea, select { font: inherit; color: inherit; }
  svg { width: 24px; height: 24px; fill: currentColor; display: block; flex: none; }
  .hidden { display: none !important; }
  code, .mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px;
  }
  .num, td { font-variant-numeric: tabular-nums; }
  :focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

  /* ---------- the key gate ---------- */
  #gate { min-height: 100%; display: grid; place-items: center;
          padding: 24px; background: var(--bg); }
  .card {
    width: 100%; max-width: 420px; background: var(--surface);
    border: 1px solid var(--border); border-radius: 18px; padding: 40px;
    box-shadow: var(--shadow);
  }
  .card h1 { margin: 0 0 8px; font-size: 22px; font-weight: 700;
             letter-spacing: -.01em; }
  .card h1::before {
    content: "Y"; display: inline-grid; place-items: center;
    width: 34px; height: 34px; margin-right: 12px; border-radius: 10px;
    background: var(--primary); color: var(--on-primary);
    font-size: 16px; font-weight: 700; vertical-align: -8px;
  }
  .card p.sub { margin: 0 0 28px; color: var(--text-2); }

  .field { position: relative; margin-bottom: 20px; }
  .field input, .field select, .field textarea {
    width: 100%; padding: 13px 15px; background: transparent;
    border: 1px solid var(--border); border-radius: 10px; outline: none;
  }
  .field textarea { min-height: 74px; resize: vertical; }
  .field input:focus, .field select:focus, .field textarea:focus {
    border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary);
  }
  .field label {
    position: absolute; left: 8px; top: -8px; padding: 0 6px;
    font-size: 12px; color: var(--text-2); background: var(--surface);
    border-radius: 6px;
  }
  .field .hint {
    display: block; margin: 6px 2px 0; font-size: 12px;
    color: var(--text-2); line-height: 1.45;
  }
  .field input:disabled { color: var(--text-2); }

  .btn {
    display: inline-flex; align-items: center; gap: 8px;
    height: 36px; padding: 0 20px; border: 0; border-radius: 999px;
    background: var(--primary); color: var(--on-primary);
    font-size: 13.5px; font-weight: 600; cursor: pointer;
  }
  .btn:hover:not(:disabled) { filter: brightness(1.08); box-shadow: var(--shadow); }
  .btn:disabled { opacity: .5; cursor: default; }
  .btn.text { background: transparent; color: var(--accent); padding: 0 12px; }
  .btn.outline { background: var(--surface); color: var(--accent);
                 border: 1px solid var(--border); }
  .btn.danger { background: transparent; color: var(--danger);
                border: 1px solid var(--border); }
  .btn.text:hover:not(:disabled), .btn.outline:hover:not(:disabled),
  .btn.danger:hover:not(:disabled) {
    background: var(--hover); box-shadow: none; filter: none;
  }
  .btn.small { height: 30px; padding: 0 14px; font-size: 12.5px; }

  /* Filter/search controls — one pill language everywhere. */
  .control {
    height: 32px; padding: 0 12px; border: 1px solid var(--border);
    border-radius: 999px; background: var(--surface); font-size: 13px;
  }
  .control:focus { outline: none; border-color: var(--primary);
                   box-shadow: inset 0 0 0 1px var(--primary); }
  .control::placeholder { color: var(--text-2); }

  .notice {
    margin: 0 0 20px; padding: 12px 16px; border-radius: 12px;
    background: var(--danger-soft); color: var(--danger); font-size: 13px;
  }
  .notice.ok { background: var(--ok-soft); color: var(--ok); }
  .notice:empty { display: none; }

  /* ---------- shell ---------- */
  #app { height: 100%; display: flex; flex-direction: column; }
  header.bar {
    height: 60px; flex: none; display: flex; align-items: center; gap: 8px;
    padding: 0 20px; border-bottom: 1px solid var(--border);
    background: var(--surface);
  }
  .brand {
    display: flex; align-items: center; gap: 11px;
    font-size: 15.5px; font-weight: 600; color: var(--text);
  }
  .brand .mark {
    display: grid; place-items: center; width: 30px; height: 30px;
    border-radius: 9px; background: var(--primary); color: var(--on-primary);
    font-size: 14px; font-weight: 700;
  }
  .brand span.word { color: var(--text-2); font-weight: 500; }
  .bar .spacer { flex: 1; }
  .icon-btn {
    display: grid; place-items: center; width: 38px; height: 38px;
    border: 0; border-radius: 50%; background: transparent;
    color: var(--text-2); cursor: pointer;
  }
  .icon-btn:hover { background: var(--hover); }
  .icon-btn svg { width: 20px; height: 20px; }
  #who {
    background: var(--chip); border-radius: 999px; padding: 5px 12px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 40vw;
  }

  .body { flex: 1; display: flex; min-height: 0; }
  nav.rail {
    width: 216px; flex: none; padding: 14px 12px;
    border-right: 1px solid var(--border); background: var(--surface);
    display: flex; flex-direction: column; gap: 2px;
  }
  nav.rail button {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 12px; border: 0; border-radius: 10px;
    background: transparent; color: var(--text-2);
    font-size: 13.5px; font-weight: 500; cursor: pointer; text-align: left;
  }
  nav.rail button .pill {
    display: grid; place-items: center; width: 20px; height: 20px;
    border-radius: 0; flex: none;
  }
  nav.rail svg { width: 17px; height: 17px; }
  nav.rail button:hover { background: var(--hover); color: var(--text); }
  nav.rail button[aria-selected="true"] {
    background: var(--selected); color: var(--selected-text); font-weight: 600;
  }

  main { flex: 1; overflow-y: auto; min-width: 0; }
  .inner { max-width: 1120px; margin: 0 auto; padding: 26px 28px 64px; }
  .head {
    display: flex; align-items: center; gap: 12px; margin-bottom: 18px;
    flex-wrap: wrap;
  }
  .head h2 { font-size: 20px; font-weight: 700; letter-spacing: -.01em; margin: 0; }
  .head .count {
    color: var(--text-2); font-size: 12px; font-weight: 600;
    background: var(--chip); border-radius: 999px; padding: 4px 10px;
  }
  .head .count:empty { display: none; }
  .head .grow { flex: 1; }

  .lede {
    margin: -6px 0 20px; color: var(--text-2); font-size: 13px;
    line-height: 1.55; max-width: 72ch;
  }
  .lede b { color: var(--text); font-weight: 600; }

  /* ---------- tables ---------- */
  .panel {
    border: 1px solid var(--border); border-radius: 14px;
    background: var(--surface); overflow: hidden; box-shadow: var(--shadow);
  }
  table { width: 100%; border-collapse: collapse; }
  th, td {
    text-align: left; padding: 12px 16px; font-size: 13.5px;
    border-bottom: 1px solid var(--line-soft); vertical-align: middle;
  }
  th {
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .08em; color: var(--text-2); background: var(--surface);
    border-bottom: 1px solid var(--border);
  }
  tbody tr:last-child td { border-bottom: 0; }
  tbody tr:hover { background: var(--hover); }
  td.right, th.right { text-align: right; white-space: nowrap; }
  td .sub { display: block; color: var(--text-2); font-size: 12px; margin-top: 2px; }
  /* A long URL in a cell is shown by its start, the rest on hover — one
   * webhook address must not decide the width of the whole table. */
  td .sub.clip {
    max-width: 24ch; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* Anything that can scroll sideways says so: a shadow on the edge that
   * has more, painted by the container itself, so a table wider than a
   * phone is never mistaken for a table with three columns. */
  .scroll {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    background:
      linear-gradient(to right, var(--surface) 30%, transparent) 0 0 / 40px 100%,
      linear-gradient(to left, var(--surface) 30%, transparent) 100% 0 / 40px 100%,
      radial-gradient(farthest-side at 0 50%,
        color-mix(in srgb, var(--text) 22%, transparent), transparent) 0 0 / 12px 100%,
      radial-gradient(farthest-side at 100% 50%,
        color-mix(in srgb, var(--text) 22%, transparent), transparent) 100% 0 / 12px 100%;
    background-repeat: no-repeat;
    background-attachment: local, local, scroll, scroll;
  }
  .scroll th { background: transparent; }
  /* A cell holding several buttons: one row where there is room, a
   * two-column block on a phone, never one button per line. */
  .acts { display: inline-flex; flex-wrap: wrap; justify-content: flex-end;
          gap: 4px 6px; vertical-align: middle; }
  /* Facts a hidden column carried, repeated under the row's name on a
   * phone (admin.js writes them; nothing shows them anywhere else). Named
   * with td as well, so it outranks the td .sub rule above — the facts
   * are a .sub too. Shown from the first breakpoint on, where the first
   * columns step aside. */
  .phone-only, td .phone-only { display: none; }
  @media (min-width: 641px) { td .tag { white-space: nowrap; } }
  /* Columns that step aside on a phone: c-opt below 640px, c-opt2 below
   * 480px. Marked on the header cell; the body cells inherit the mark
   * (see the column observer in admin.js). What steps aside is never an
   * action or a name — those stay, whatever the width. */
  @media (max-width: 640px) {
    .c-opt { display: none; }
    th, td { padding: 10px 12px; }
    td.right { white-space: normal; }
    td.right .btn { margin: 2px 0 2px 6px; }
    td.right .acts .btn { margin: 0; }
    .acts { display: grid; grid-template-columns: repeat(2, max-content);
            justify-content: end; }
    .acts.stack { grid-template-columns: max-content; }
    td.wrap-any, td .wrap-any { overflow-wrap: anywhere; }
    .phone-only, td .phone-only { display: block; }
  }
  @media (max-width: 480px) {
    .c-opt2 { display: none; }
  }

  .tag {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px; border-radius: 999px;
    background: var(--chip); font-size: 12px; font-weight: 600;
  }
  .tag.on { color: var(--ok); background: var(--ok-soft); }
  .tag.off { color: var(--text-2); }
  .tag.warn { color: var(--warn); background: var(--warn-soft); }
  tr.logrow:hover td { background: var(--hover); }
  tr.logdetail td { background: var(--surface-2); font-size: 12.5px;
                    padding: 12px 16px 14px; }
  tr.logdetail td > div { margin: 2px 0; }
  .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

  .empty { padding: 48px 24px; text-align: center; color: var(--text-2); }
  .empty svg { width: 44px; height: 44px; margin: 0 auto 14px; opacity: .5; }

  /* ---------- in place, never in a popup ----------
   * Nothing in this console edits or asks in a dialog: forms sit in the
   * page, and a destructive button asks on the spot (armed). */
  .dsub { margin: 0 0 20px; color: var(--text-2); font-size: 13px; }
  .btn.armed, .btn.outline.armed, .btn.text.armed, .btn.danger.armed {
    background: var(--danger); color: #fff; border-color: var(--danger); }
  /* A hint that is a paragraph of its own, not under a field. */
  p.hint { color: var(--text-2); font-size: 13px; line-height: 1.5; }
  fieldset {
    border: 0; border-top: 1px solid var(--border);
    margin: 24px 0 0; padding: 20px 0 0;
  }
  legend {
    padding: 0 8px 0 0; font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .08em; color: var(--text-2);
  }

  .toast {
    position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
    background: #1C2430; color: #fff; padding: 12px 20px;
    border-radius: 999px; font-size: 13px; box-shadow: var(--pop);
    z-index: 10; max-width: 80vw;
  }

  /* ---------- overview ---------- */
  .tiles {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(146px, 1fr));
    gap: 12px; margin: 0 0 26px;
  }
  .tile {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow);
  }
  .tile .v { font-size: 24px; font-weight: 700; letter-spacing: -.01em;
             font-variant-numeric: tabular-nums; }
  .tile .l { font-size: 11px; font-weight: 600; letter-spacing: .08em;
             text-transform: uppercase; color: var(--text-2); margin-top: 2px; }
  .tile.bad .v { color: var(--danger); }
  .tile.warm .v { color: var(--warn); }
  .head h3 { font-size: 15px; font-weight: 700; margin: 0; }
  .pulse { color: var(--text-2); font-size: 12.5px; margin-top: 20px; }

  /* ---------- tenant detail ---------- */
  .cards2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .card2 {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 10px; min-width: 0;
  }
  .card2 h3 { font-size: 14px; font-weight: 700; margin: 0; }
  .kv { display: grid; grid-template-columns: 128px 1fr auto;
        gap: 7px 12px; align-items: center; }
  .kv .k2 { font-size: 11px; font-weight: 600; letter-spacing: .07em;
            text-transform: uppercase; color: var(--text-2); }
  .kv .v2 { font-size: 13px; overflow-wrap: anywhere; min-width: 0; }
  @media (max-width: 640px) {
    .kv { grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; }
    .kv .k2 { grid-column: 1 / -1; margin-top: 8px; }
    .kv .k2:first-child { margin-top: 0; }
  }
  .chips { display: flex; flex-wrap: wrap; gap: 8px; }
  .chips .chip2 {
    background: var(--chip); border-radius: 999px; padding: 5px 12px;
    font-size: 13px; font-variant-numeric: tabular-nums;
  }
  #td-tags { display: inline-flex; gap: 6px; }
  .subtabs { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 18px; }
  .subtabs button {
    border: 0; background: transparent; padding: 7px 14px;
    border-radius: 999px; font-size: 13px; font-weight: 600;
    color: var(--text-2); cursor: pointer; white-space: nowrap;
  }
  .subtabs button:hover { background: var(--hover); color: var(--text); }
  .subtabs button[aria-selected="true"] {
    background: var(--selected); color: var(--selected-text);
  }
  .card2.wide { grid-column: 1 / -1; }
  .card2.danger { border-color: var(--danger); }
  .card2 .savebar { display: flex; justify-content: flex-end; margin-top: auto; }
  .card2 .field { margin-bottom: 14px; }
  .card2 .field:last-of-type { margin-bottom: 4px; }
  @media (max-width: 900px) { .cards2 { grid-template-columns: 1fr; } }

  @media (max-width: 820px) {
    nav.rail {
      display: grid; grid-template-columns: repeat(auto-fit, minmax(68px, 1fr));
      gap: 2px; width: 100%; height: auto; padding: 8px 10px;
      border-right: 0; border-bottom: 1px solid var(--border);
    }
    nav.rail button {
      flex-direction: column; justify-content: center; gap: 4px;
      padding: 8px 4px; font-size: 11.5px; text-align: center;
      white-space: nowrap;
    }
    .body { flex-direction: column; }
    .inner { padding: 20px 14px 48px; }
    header.bar { padding: 0 14px; }
    #shared-warning { margin: 10px 14px 0 !important; }
  }
  @media (max-width: 480px) {
    .brand .word { display: none; }
    .head .control { flex: 1 1 160px; min-width: 140px; width: auto !important; }
  }

  /* ---------- the activity chart & health card (Overview) ---------- */
  .chart-key { font-size: 12px; color: var(--text-2);
               display: inline-flex; align-items: center; gap: 6px; }
  .chart-key i { width: 10px; height: 10px; border-radius: 3px;
                 display: inline-block; }
  #ov-chart svg { display: block; width: 100%; height: auto; }
  #ov-chart text { font: 11px ui-sans-serif, system-ui, sans-serif;
                   fill: var(--text-2); }
  #ov-chart .grid { stroke: var(--line-soft); }
  .chart-tip { position: absolute; pointer-events: none; z-index: 5;
               background: var(--surface); border: 1px solid var(--border);
               border-radius: 10px; padding: 7px 10px; font-size: 12px;
               color: var(--text); box-shadow: var(--shadow);
               white-space: nowrap; }
  .chart-tip b { display: block; margin-bottom: 2px; }
  .chart-tip i { width: 8px; height: 8px; border-radius: 2px;
                 display: inline-block; margin-right: 5px; }
  #ov-health .hrow { display: flex; align-items: center; gap: 10px;
                     padding: 8px 0; font-size: 13px;
                     border-bottom: 1px solid var(--line-soft); }
  #ov-health .hrow:last-child { border-bottom: 0; }
  #ov-health .hrow .l { color: var(--text); }
  #ov-health .hrow .d { color: var(--text-2); font-size: 12px; }
