:root {
  /* Unified "SCAD Control" design tokens (unified-portal-plan §6.6).
     fleet.css consumes ONLY these var(--*) names + local layout. */
  --bg: #0b0f14; --panel: #121821; --panel-2: #0e141c; --line: #1f2937;
  --text: #e5e7eb; --muted: #94a3b8; --accent: #38bdf8;
  --ok: #22c55e; --warn: #f59e0b; --degraded: #fb923c; --danger: #ef4444; --info: #a78bfa;
  --radius: 10px; --font-mono: ui-monospace, 'Cascadia Code', monospace;
  /* Back-compat aliases for pre-existing portal CSS/JS that referenced the
     older token names — kept so nothing has to be renamed en masse. */
  --txt: var(--text); --panel2: var(--panel-2); --accent2: #0ea5e9;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--txt);
  font: 15px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
header {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 10px 14px;
  padding: 14px 22px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  padding-left: calc(22px + env(safe-area-inset-left, 0px));
  padding-right: calc(22px + env(safe-area-inset-right, 0px));
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: rgba(11,15,20,.85); backdrop-filter: blur(8px); z-index: 5;
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: .3px; flex: 0 0 auto; white-space: nowrap; }
.brand span { color: var(--accent); }
.userbox { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; color: var(--muted); font-size: 14px; }
.userbox > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
main { max-width: 1100px; margin: 0 auto; padding: 28px 22px 60px; }
/* Fleet views are dense + wide — give them more room and let the fleet
   sections' own padding provide the gutters. */
main.viewing-fleet { max-width: 1360px; }
main.viewing-fleet #view {
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--bg);
}
.spinner { color: var(--muted); padding: 40px; text-align: center; }

.btn {
  border: 1px solid var(--line); background: var(--panel2); color: var(--txt);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; font-size: 14px; text-decoration: none;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent2); border-color: var(--accent2); }
.btn.primary:hover { background: var(--accent); }
.btn.ghost { background: transparent; }

.hero { text-align: center; padding: 60px 0; }
.hero h1 { font-size: 28px; margin: 0 0 8px; }
.hero p { color: var(--muted); margin: 0 0 24px; }

/* inline login */
.login-wrap { display: flex; justify-content: center; padding: 60px 0; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 30px 28px; box-shadow: 0 12px 40px rgba(0,0,0,.35);
}
.login-brand { font-size: 24px; font-weight: 700; text-align: center; }
.login-brand span { color: var(--accent); }
.login-sub { color: var(--muted); text-align: center; margin: 6px 0 22px; font-size: 14px; }
#loginform { display: flex; flex-direction: column; gap: 12px; }
#loginform input {
  background: var(--panel2); border: 1px solid var(--line); color: var(--txt);
  padding: 12px 14px; border-radius: 10px; font-size: 15px; width: 100%;
}
#loginform input:focus { outline: none; border-color: var(--accent); }
#loginform button { margin-top: 4px; padding: 12px; font-size: 15px; }
.login-err { color: var(--danger); font-size: 13px; min-height: 16px; text-align: center; }

.tabs {
  display: flex; gap: 6px; margin-bottom: 22px; flex-wrap: wrap;
  border-bottom: 1px solid var(--line); padding-bottom: 0;
}
.tab {
  padding: 8px 14px; border-radius: 9px 9px 0 0; cursor: pointer; color: var(--muted);
  border: 1px solid transparent; border-bottom: none; text-decoration: none;
  font-size: 14px; white-space: nowrap; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--panel); color: var(--text); border-color: var(--line); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; text-decoration: none; color: var(--txt); display: flex; flex-direction: column; gap: 10px;
  transition: transform .08s, border-color .12s;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card .title { font-size: 17px; font-weight: 650; }
.card .meta { display: flex; align-items: center; justify-content: space-between; margin-top: auto; }
.badge { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--panel2); color: var(--muted); border: 1px solid var(--line); }
.badge.admin { color: #ffd6a0; border-color: #5a4326; }
.badge.user_admin { color: #cdb4ff; border-color: #43396b; }
.badge.user { color: #a9d6ff; border-color: #2b4a6b; }
.go { color: var(--accent); font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 50px; }

/* Launchpad: organizations are companies; their events are compact projects. */
.launchpad { display: flex; flex-direction: column; gap: 24px; }
.company-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px; align-items: start;
}
.company-panel {
  min-width: 0; overflow: hidden; background: var(--panel);
  border: 1px solid var(--line); border-radius: calc(var(--radius) + 2px);
}
.company-header {
  position: static; z-index: auto; padding: 16px 18px; border: 0;
  border-bottom: 1px solid var(--line); background: var(--panel2);
  display: flex; flex-wrap: nowrap; align-items: center; justify-content: space-between; gap: 16px;
}
.company-kicker {
  margin-bottom: 2px; color: var(--accent); font-size: 10px; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase;
}
.company-header h2 { margin: 0; font-size: 17px; line-height: 1.3; }
.project-count {
  flex: 0 0 auto; color: var(--muted); font-size: 12px; white-space: nowrap;
}
.company-projects { display: flex; flex-direction: column; }
.company-project {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center;
  gap: 12px; padding: 13px 18px; color: var(--text); text-decoration: none;
  border-bottom: 1px solid var(--line); transition: background .12s ease;
}
.company-project:last-child { border-bottom: 0; }
.company-project:hover { background: rgba(56, 189, 248, .055); }
.company-project .title { min-width: 0; font-size: 14px; font-weight: 650; line-height: 1.35; }
.company-project .meta { display: flex; align-items: center; gap: 12px; }
.company-project .go { white-space: nowrap; }
.company-project:focus-visible, .card:focus-visible {
  outline: 2px solid var(--accent); outline-offset: -2px;
}
.section-title {
  margin: 2px 0 -10px; color: var(--muted); font-size: 13px; font-weight: 650;
  letter-spacing: .04em; text-transform: uppercase;
}

/* admin */
.admin-wrap { display: grid; grid-template-columns: 280px 1fr; gap: 18px; }
.userlist { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; max-height: 70vh; overflow-y: auto; }
.userlist .u { padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; align-items: center; gap: 10px; }
.userlist .u-main { flex: 1 1 auto; min-width: 0; }
.userlist .user-delete { flex: 0 0 auto; border: 1px solid var(--line); background: transparent; color: var(--danger); border-radius: 7px; padding: 4px 7px; font-size: 12px; cursor: pointer; }
.userlist .user-delete:hover { border-color: var(--danger); }
.userlist .u:hover { background: var(--panel2); }
.userlist .u.sel { background: var(--panel2); border-left: 3px solid var(--accent); }
.userlist .u .e { font-size: 13px; }
.userlist .u .s { font-size: 12px; color: var(--muted); }
.search { width: 100%; padding: 10px 14px; border: 0; border-bottom: 1px solid var(--line); background: var(--panel2); color: var(--txt); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.panel h3 { margin: 0 0 4px; }
.panel .sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.access-actions { margin: -6px 0 14px; }
table.access { width: 100%; border-collapse: collapse; }
table.access td { padding: 9px 6px; border-bottom: 1px solid var(--line); }
table.access td.ev { font-weight: 550; }
select {
  background: var(--panel2); color: var(--txt); border: 1px solid var(--line);
  padding: 6px 10px; border-radius: 8px; font-size: 14px;
}
.appadmin-pill { font-size: 12px; color: #ffd6a0; }

/* manage events */
.manage-wrap { display: flex; flex-direction: column; gap: 16px; }
.manage-wrap .sub { color: var(--muted); font-size: 13px; }
.addev { display: flex; gap: 10px; flex-wrap: wrap; }
.addev input {
  background: var(--panel2); border: 1px solid var(--line); color: var(--txt);
  padding: 9px 12px; border-radius: 9px; font-size: 14px; flex: 1; min-width: 140px;
}
.addev input:focus { outline: none; border-color: var(--accent); }
.addev button { flex: 0 0 auto; }
table.evtable { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.evtable td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.evtable tr:last-child td { border-bottom: 0; }
table.evtable .evlabel { font-weight: 600; }
table.evtable .evurl a { color: var(--accent); text-decoration: none; font-size: 13px; }
table.evtable .evslug { color: var(--muted); font-size: 13px; font-family: ui-monospace, monospace; }
table.evtable .evact { text-align: right; white-space: nowrap; }
table.evtable .evact .btn { padding: 6px 10px; font-size: 13px; margin-left: 6px; }
table.evtable input {
  background: var(--panel2); border: 1px solid var(--line); color: var(--txt);
  padding: 7px 10px; border-radius: 8px; font-size: 14px; width: 100%;
}
table.evtable input:focus { outline: none; border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
@media (max-width: 720px) { .addev { flex-direction: column; } table.evtable .evurl { display: none; } }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel2); border: 1px solid var(--line); color: var(--txt);
  padding: 10px 18px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: var(--danger); }
.pull-refresh {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translate(-50%, calc(-120% + var(--pull-refresh-y, 0px)));
  z-index: 30;
  pointer-events: none;
  border: 1px solid var(--line);
  background: rgba(18, 24, 33, .94);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  opacity: 0;
  transition: transform .18s ease, opacity .18s ease, color .18s ease, border-color .18s ease;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .3);
}
.pull-refresh.pulling,
.pull-refresh.refreshing { opacity: 1; }
.pull-refresh.ready,
.pull-refresh.refreshing { color: var(--accent); border-color: var(--accent); }
@media (max-width: 720px) { .admin-wrap { grid-template-columns: 1fr; } }

/* ---- Mobile / narrow viewports ---- */
@media (max-width: 600px) {
  header {
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    padding-left: calc(14px + env(safe-area-inset-left, 0px));
    padding-right: calc(14px + env(safe-area-inset-right, 0px));
  }
  .brand { font-size: 17px; }
  /* Userbox drops to its own full-width row beneath the brand so the name +
     pill + buttons never collide with the logo. */
  .userbox { width: 100%; font-size: 13px; gap: 8px; }
  .userbox > span:first-child { flex: 1 1 auto; white-space: nowrap; }   /* name: take the row, ellipsize */
  .userbox .btn { padding: 7px 12px; font-size: 13px; }

  main {
    padding: 18px 14px 48px;
    padding-left: calc(14px + env(safe-area-inset-left, 0px));
    padding-right: calc(14px + env(safe-area-inset-right, 0px));
    padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
  }

  /* Tabs scroll horizontally instead of wrapping/squeezing. */
  .tabs { gap: 6px; margin-bottom: 18px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; white-space: nowrap; }

  /* One event card per row for comfortable tap targets. */
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .card { padding: 16px; }
  .launchpad { gap: 20px; }
  .company-grid { grid-template-columns: 1fr; gap: 12px; }
  .company-header { padding: 14px 16px; }
  .company-project { padding: 14px 16px; }
  .company-project .meta { gap: 9px; }

  .hero { padding: 40px 0; }
  .login-wrap { padding: 32px 0; }
}

/* ---- Add user form (Manage access) ---- */
.btn.block { display: block; width: 100%; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 11px 14px; }
.err { color: var(--danger); }
.sub.err { color: var(--danger); }
.adduser { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.adduser label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.adduser input, .adduser select, .adduser textarea {
  background: var(--panel2); border: 1px solid var(--line); color: var(--txt);
  padding: 9px 11px; border-radius: 8px; font-size: 14px;
}
.adduser textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }
.adduser input[type=file] { padding: 6px; color: var(--muted); }
.adduser input:focus, .adduser select:focus, .adduser textarea:focus { outline: none; border-color: var(--accent); }
.adduser .grant-row { display: flex; gap: 8px; }
.adduser .grant-row select { flex: 1 1 auto; }
#adduser-result .created { font-size: 14px; margin-bottom: 10px; }
.pwbox { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.pwbox .sub { margin-bottom: 8px; }
.pwrow { display: flex; align-items: center; gap: 10px; }
.pwrow code {
  flex: 1 1 auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; letter-spacing: 0.5px;
  word-break: break-all;
}

/* ---- Org layer additions ---- */
.orgadmin-pill { font-size: 12px; color: #a9d6ff; }
.checkline { display: flex !important; flex-direction: row !important; align-items: center; gap: 8px; font-size: 14px !important; color: var(--txt) !important; }
.checkline input { width: auto !important; padding: 0 !important; }
table.evtable .evorg { color: var(--muted); font-size: 13px; }
.org-admins-panel { margin-top: 18px; }
.s { color: var(--muted); font-size: 12px; }
table.evtable tr.archived { opacity: 0.55; }

/* ---- Forgot password (login card) ---- */
.btn.link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 8px 0; font-size: 13px; width: 100%; text-align: center; }
.forgotform { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.forgotform input {
  background: var(--panel2); border: 1px solid var(--line); color: var(--txt);
  padding: 10px 12px; border-radius: 9px; font-size: 14px; width: 100%;
}

/* ---- My account tab ---- */
.account-wrap { max-width: 420px; }
.account-wrap h4 { margin: 22px 0 10px; font-size: 14px; color: var(--muted); }
.namefrm, .pwfrm { display: flex; flex-direction: column; gap: 10px; }
.namefrm { flex-direction: row; }
.namefrm input, .pwfrm input {
  background: var(--panel2); border: 1px solid var(--line); color: var(--txt);
  padding: 9px 12px; border-radius: 8px; font-size: 14px; flex: 1 1 auto;
}

/* ---- Break-glass login link ---- */
.bg-link { color: var(--muted); font-size: 12px; margin-top: 4px; }
.bg-link:hover { color: var(--accent); }

/* ---- Events tab: unified registry (§6.4) ---- */
/* Grid form used by the add-event row and the inline edit form. */
.regform {
  display: grid; gap: 12px 14px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px;
}
.regform label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.regform input, .regform select {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 9px 11px; border-radius: 8px; font-size: 14px; width: 100%;
}
.regform input:focus, .regform select:focus { outline: none; border-color: var(--accent); }
.regform input:disabled { opacity: .6; }
.regform .checkline { align-self: center; margin-top: 18px; }
.regform > button[type=submit] { align-self: end; }
.regform.editev { margin: 0; border-radius: 0; border-left: 0; border-right: 0; }
.editev-actions { display: flex; gap: 8px; align-items: end; grid-column: 1 / -1; }

table.regtable thead th {
  text-align: left; padding: 10px 12px; font-size: 11px; letter-spacing: .04em;
  text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
table.regtable .evlabel .evslug { margin-top: 2px; font-size: 12px; }
table.regtable .evbranch { font-size: 12px; color: var(--muted); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.regtable .evmon { text-align: center; }
.mono { font-family: var(--font-mono); }

.envbadge {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  border: 1px solid currentColor; text-transform: uppercase; letter-spacing: .03em;
}
.envbadge.production { color: var(--ok); }
.envbadge.test { color: var(--muted); }
.envbadge.other { color: var(--warn); }

/* inline monitor toggle in the registry table */
.mon-toggle { justify-content: center; }
.mon-toggle input { width: 16px !important; height: 16px; accent-color: var(--accent); cursor: pointer; }

@media (max-width: 720px) {
  .regform { grid-template-columns: 1fr; }
  table.regtable .evbranch, table.regtable thead th:nth-child(5),
  table.regtable td:nth-child(5) { display: none; }
}

/* ---- Welcome / set-password page (invite + reset) ---- */
.welcome-wrap { display: flex; justify-content: center; padding: 60px 0; }
.welcome-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 30px 28px; box-shadow: 0 12px 40px rgba(0,0,0,.35);
}
.welcome-card form { display: flex; flex-direction: column; gap: 12px; }
.welcome-card input {
  background: var(--panel2); border: 1px solid var(--line); color: var(--txt);
  padding: 12px 14px; border-radius: 10px; font-size: 15px; width: 100%;
}
.welcome-card input:focus { outline: none; border-color: var(--accent); }
.welcome-card button { margin-top: 4px; padding: 12px; font-size: 15px; }
.welcome-hint { color: var(--muted); font-size: 12px; margin: 0 0 4px; }

/* Mobile app shell: show all portal tabs without side-scrolling. */
@media (max-width: 600px) {
  main.viewing-fleet #view {
    overflow: visible;
  }

  .tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    overflow: visible;
    border-bottom: 0;
    padding-bottom: 4px;
  }

  .tab {
    min-width: 0;
    margin-bottom: 0;
    padding: 7px 5px;
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 12px;
    line-height: 1.15;
    text-align: center;
    white-space: normal;
  }

  .tab.active {
    border-color: var(--line);
  }
}

