/* Switchboard admin UI — SEM Dynamics brand theme ("Brand-Forward Light"). */
:root {
  /* Brand palette */
  --green: #8ec342;
  --blue: #4e99d3;
  --red: #ed2024;
  --yellow: #fed900;
  --orange: #f79420;
  --purple: #662f90;

  /* Neutrals / surfaces */
  --ink: #141414;
  --gray: #666766;
  --white: #ffffff;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e6e8ec;
  --line-soft: #eef1f5;

  /* Roles */
  --primary: #4e99d3;
  --primary-hover: #3e86bf;
  --success: #3f8f1e; /* legible green text on white */
  --danger: #ce1b22;  /* legible red text on white */
  --warn: #b25e00;    /* legible amber text on white */

  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 20, 0.04), 0 8px 24px rgba(20, 20, 20, 0.06);

  --stripe: linear-gradient(90deg,
    var(--green) 0 16.666%, var(--blue) 0 33.333%, var(--red) 0 50%,
    var(--yellow) 0 66.666%, var(--orange) 0 83.333%, var(--purple) 0 100%);
  --blue-grad: linear-gradient(180deg, #5aa6e0 0%, #4e99d3 55%, #3e86bf 100%);

  --font-head: 'Montserrat', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { max-width: 100%; overflow-x: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-head); }

.hidden { display: none !important; }

/* Rainbow brand stripe (top of app + top of login card) */
.brand-stripe {
  display: block;
  height: 6px;
  width: 100%;
  background: var(--stripe);
}

/* ── App header ─────────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 18px;
  padding: 14px 26px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; flex-shrink: 1; }
.brand-title { min-width: 0; }
.brand-logo { height: 28px; display: block; }
.brand-divider { width: 1px; height: 30px; background: var(--border); }
.logo { display: inline-flex; align-items: center; }
.logo img { height: 22px; width: 22px; display: block; }
.brand-title { display: flex; flex-direction: column; }
.brand-title h1 { font-size: 19px; font-weight: 700; margin: 0; letter-spacing: -0.01em; line-height: 1.1; }
.brand-title .sub { color: var(--gray); font-size: 12.5px; margin-top: 2px; }

.mode-banner {
  flex: 1 1 260px;
  min-width: 0;
  text-align: center;
  background: linear-gradient(90deg, #fff9e3 0%, #fffdf6 100%);
  color: #6b5410;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 9px 14px;
  border: 1.5px solid #f4d97a;
  border-left: 6px solid var(--yellow);
  border-radius: 10px;
  text-transform: uppercase;
  font-size: 12.5px;
}

/* ── Tabs ───────────────────────────────────────────────────────────────────── */
nav#tabs {
  display: flex;
  gap: 6px;
  padding: 10px 26px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.tab {
  background: none;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--gray);
  padding: 9px 18px;
  cursor: pointer;
  border-radius: 9px 9px 0 0;
  font-family: var(--font-head);
  font-size: 13.5px;
  font-weight: 600;
}
.tab:hover { color: var(--ink); }
.tab.active {
  background: var(--bg);
  border-color: var(--border);
  color: var(--primary);
}

main { padding: 24px 26px 60px; max-width: 1200px; margin: 0 auto; }
.panel { }

h2 {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gray);
  margin: 28px 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
h2::before { content: ""; width: 26px; height: 3px; border-radius: 2px; background: var(--stripe); }

/* ── Summary cards ──────────────────────────────────────────────────────────── */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.card .num { font-family: var(--font-head); font-size: 28px; font-weight: 800; line-height: 1; }
.card .label { color: var(--gray); font-size: 12px; margin-top: 8px; }

/* ── Tables ─────────────────────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
thead th {
  font-family: var(--font-head);
  color: var(--gray);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fbfcfe; }
td strong { font-weight: 600; }

/* ── Tier badges (white text on brand colors) ───────────────────────────────── */
.badge {
  display: inline-block;
  min-width: 34px;
  text-align: center;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.03em;
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
}
.badge.P0 { background: var(--red); }
.badge.P1 { background: var(--orange); }
.badge.P2 { background: var(--blue); }
.badge.P3 { background: var(--green); }

/* ── Run statuses ───────────────────────────────────────────────────────────── */
.status-succeeded { color: var(--success); font-weight: 600; }
.status-failed, .status-dead { color: var(--danger); font-weight: 600; }
.status-queued, .status-running { color: var(--warn); font-weight: 600; }

/* ── Toolbars / form controls ───────────────────────────────────────────────── */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }

input, select {
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--ink);
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: var(--font-body);
  outline: none;
  transition: 0.15s;
}
input::placeholder { color: #a6acb6; }
input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(78, 153, 211, 0.2);
}

button {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 14px;
  background: var(--primary);
  border: 1.5px solid var(--primary);
  color: #fff;
  border-radius: 9px;
  padding: 9px 16px;
  cursor: pointer;
  transition: 0.15s;
}
button:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.ghost {
  background: var(--surface);
  color: var(--ink);
  border: 1.5px solid var(--border);
}
button.ghost:hover { background: var(--surface); border-color: #d3d8e0; }

/* Enable/disable toggle (rendered as a <button> by app.js) */
.toggle {
  min-width: 92px;
  background: var(--surface);
  color: var(--gray);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 12.5px;
}
.toggle:hover { background: var(--surface); border-color: #d3d8e0; }
.toggle.on {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}
.toggle.on:hover { background: #7fb838; border-color: #7fb838; }
.toggle:disabled { opacity: 0.6; }

/* ── Integrations chips ─────────────────────────────────────────────────────── */
.chips { display: flex; gap: 12px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 15px;
  box-shadow: var(--shadow);
  font-weight: 500;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: #c2c7d0; }
.dot.configured { background: var(--green); box-shadow: 0 0 0 3px rgba(142, 195, 66, 0.22); }
.chip .mode {
  font-family: var(--font-head);
  color: var(--warn);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Action-log details ─────────────────────────────────────────────────────── */
details pre {
  background: #f7f9fb;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  font-size: 12px;
  max-height: 320px;
}
summary { cursor: pointer; color: var(--primary); font-weight: 600; font-family: var(--font-head); }

.muted { color: var(--gray); }

/* ── Toast ──────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--surface);
  border: 1.5px solid var(--primary);
  color: var(--ink);
  padding: 12px 18px;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(20, 20, 20, 0.14);
  max-width: 420px;
}
.toast.error { border-color: var(--red); color: var(--danger); }

/* ── Login screen ───────────────────────────────────────────────────────────── */
#login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(1100px 460px at 50% -180px, #ffffff 0%, rgba(255, 255, 255, 0) 62%),
    var(--bg);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 10px 40px rgba(20, 20, 20, 0.10);
  overflow: hidden;
}
.login-body { padding: 36px 38px 30px; }
.login-logo { height: 32px; display: block; margin-bottom: 22px; }
.login-brand { display: flex; align-items: center; gap: 11px; }
.login-brand .logo img { height: 26px; width: 26px; }
.login-brand h1 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.login-sub {
  color: var(--gray);
  margin: 6px 0 24px;
  font-size: 14px;
  letter-spacing: 0.01em;
}

#login-form { display: flex; flex-direction: column; gap: 14px; }
#login-form input { width: 100%; height: 46px; background: #fbfcfd; }
#login-form button {
  width: 100%;
  height: 48px;
  background: var(--blue-grad);
  border: none;
  color: #fff;
  font-size: 14.5px;
  box-shadow: 0 2px 4px rgba(62, 134, 191, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  margin-top: 4px;
}
#login-form button:hover { background: var(--primary-hover); }

.login-error { color: var(--danger); font-size: 13px; text-align: center; min-height: 1em; font-weight: 600; }

/* ── Theme-aware logo swap (white wordmark in dark) ──────────────────────────── */
.logo-dark { display: none; }
html[data-theme="dark"] .logo-light { display: none; }
html[data-theme="dark"] .logo-dark { display: block; }

/* ── Account menu (works in both themes via variables) ───────────────────────── */
.account { position: relative; margin-left: auto; }

.account-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  color: var(--ink);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px 5px 6px;
}
.account-trigger:hover { background: var(--surface); border-color: var(--primary); }
.account-trigger .caret { color: var(--gray); font-size: 11px; line-height: 1; }

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--blue-grad);
  color: #fff;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.account-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 258px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px;
  z-index: 50;
}

.account-head { display: flex; flex-direction: column; gap: 2px; padding: 4px 6px 10px; }
.account-head-label {
  font-family: var(--font-head);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gray);
}
.account-email { font-weight: 600; color: var(--ink); font-size: 13.5px; word-break: break-all; }

.account-section { padding: 8px 6px 4px; }
.account-section-label {
  display: block;
  font-family: var(--font-head);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gray);
  margin-bottom: 8px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}
.seg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--gray);
  border-radius: 7px;
  padding: 7px 4px;
  font-family: var(--font-head);
  font-size: 12px;
  font-weight: 600;
}
.seg svg { width: 14px; height: 14px; }
.seg:hover { background: var(--surface); color: var(--ink); border-color: var(--border); }
.seg.active {
  background: var(--surface);
  color: var(--primary);
  border-color: var(--border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.account-divider { height: 1px; background: var(--border); margin: 8px 4px; }

.account-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink);
  border-radius: 8px;
  padding: 9px 8px;
  font-family: var(--font-head);
  font-size: 13.5px;
  font-weight: 600;
  text-align: left;
}
.account-item svg { width: 15px; height: 15px; color: var(--gray); }
.account-item:hover { background: var(--bg); color: var(--danger); border-color: transparent; }
.account-item:hover svg { color: var(--danger); }

/* Smooth theme swap on the main surfaces (not everything). */
body, header, nav#tabs, .card, table, thead th, td, .chip, .mode-banner,
.account-trigger, .avatar, .account-menu, .segmented, .login-card, details pre {
  transition: background-color .15s, color .15s, border-color .15s;
}

/* ── Dark theme ("Dark Cockpit") ─────────────────────────────────────────────── */
html[data-theme="dark"] {
  --ink: #E7E9EE;
  --gray: #9AA1AC;
  --white: #ffffff;
  --bg: #16181D;
  --surface: #1E2127;
  --border: #2A2F3A;
  --line-soft: #262B33;

  --primary: #5AA9E0;
  --primary-hover: #74B7E7;
  --success: #7FCF5A;
  --danger: #FF6B6B;
  --warn: #F0B429;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.45);
}

/* Surfaces that hardcode light colors in the base sheet */
html[data-theme="dark"] thead th { background: #23272F; }
html[data-theme="dark"] tbody tr:hover { background: #242A34; }
html[data-theme="dark"] details pre { background: #171A20; }

html[data-theme="dark"] input,
html[data-theme="dark"] select { background: #171A20; }
html[data-theme="dark"] input::placeholder { color: #6B727D; }
html[data-theme="dark"] #login-form input { background: #171A20; }

html[data-theme="dark"] button.ghost:hover { border-color: #3A4150; }
html[data-theme="dark"] .toggle:hover { border-color: #3A4150; }
html[data-theme="dark"] .dot { background: #3A4150; }

html[data-theme="dark"] .mode-banner {
  background: linear-gradient(90deg, #2A2410 0%, #22200F 100%);
  color: #F3D98C;
  border-color: #5C4A1A;
  border-left-color: var(--yellow);
}

html[data-theme="dark"] .toast { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); }
html[data-theme="dark"] .login-card { box-shadow: 0 10px 40px rgba(0, 0, 0, 0.55); }
html[data-theme="dark"] #login-view {
  background:
    radial-gradient(1100px 460px at 50% -180px, #1E2127 0%, rgba(30, 33, 39, 0) 62%),
    var(--bg);
}

/* ── Table containers scroll horizontally instead of breaking the page ───────── */
#recent-runs, #runs-table, #automations-table, #clients-table {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Responsive / mobile ─────────────────────────────────────────────────────── */
@media (max-width: 820px) {
  header { padding: 12px 16px; gap: 12px; }
  /* DRY-RUN banner drops to its own full-width row under the brand + account */
  .mode-banner { order: 3; flex-basis: 100%; text-align: center; }

  nav#tabs {
    padding: 8px 12px 0;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  nav#tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; white-space: nowrap; padding: 9px 14px; }

  main { padding: 18px 16px 56px; }

  /* keep table columns readable by scrolling rather than crushing */
  #recent-runs table, #runs-table table, #automations-table table { min-width: 600px; }
  #clients-table table { min-width: 640px; }
}

@media (max-width: 540px) {
  /* collapse the wide wordmark; keep the dot-mark + "Switchboard" as the brand */
  .brand-logo, .brand-divider { display: none !important; }
  .brand-title h1 { font-size: 17px; }
  .brand-title .sub { font-size: 11.5px; }
  .card .num { font-size: 24px; }
  main { padding: 16px 12px 52px; }

  .account-menu { min-width: 0; width: calc(100vw - 24px); max-width: 320px; }

  /* stack toolbar / client-form controls full width */
  .toolbar > * { width: 100%; }

  .toast { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}
