/*
 * Application styles. Propshaft serves this file directly — no preprocessing.
 *
 * Dark only, in the same palette as the React apps (frontend/src/styles/_tokens.scss)
 * and examples/se, so moving between the Rails pages and an app is seamless.
 */

:root {
  color-scheme: dark;              /* native inputs, scrollbars and checkboxes follow */
  --col-bg: #1e1e1e;               /* page */
  --col-chrome: #1a1a1a;           /* navbar and other frame */
  --col-surface: #252525;          /* cards, inputs, tables */
  --col-hover: #2a2a2a;
  --col-text: #e0e0e0;
  --col-muted: #888;
  --col-faint: #666;
  --col-border: #333;
  --col-border-strong: #444;
  --col-accent: #4a9eff;
  --col-accent-dark: #2f86ea;
  --col-on-accent: #0b1a2c;        /* text on an accent fill */
  --col-success: #4caf50;
  --col-success-bg: rgba(76, 175, 80, 0.14);
  --col-failure: #f44336;
  --col-failure-bg: rgba(244, 67, 54, 0.14);
  --col-warn: #ff9800;
  --col-wait: #b48cf2;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--col-bg);
  color: var(--col-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--col-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.page { padding: 2rem 1rem; }

/* ---------- Sidebar (as the Data page's, frontend/src/styles/main.scss) ---------- */

.app-body { display: flex; min-height: calc(100vh - 46px); }   /* the navbar's height */
.app-body > .page { flex: 1; min-width: 0; }
.sidebar { width: 200px; flex-shrink: 0; padding: 1rem 0; background: var(--col-surface); border-right: 1px solid var(--col-border); }
.sidebar__heading { margin: 1rem 0 0.25rem; padding: 0 0.75rem; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--col-text); }
.sidebar__heading:first-child { margin-top: 0; }
.sidebar__link { display: block; padding: 5px 0.75rem 5px 1.5rem; color: var(--col-muted); border-left: 3px solid transparent; font-size: 13px; line-height: 1.3; }
.sidebar__link:hover { color: var(--col-text); background: var(--col-hover); text-decoration: none; }
.sidebar__link--active { color: var(--col-text); border-left-color: var(--col-accent); background: var(--col-hover); }
.sidebar__link--sub { padding-left: 2.5rem; }
.sidebar__link[data-view-id] { display: flex; gap: 0.5rem; }
.sidebar__count { margin-left: auto; color: var(--col-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.sidebar__create { display: block; margin: 0.75rem 0.75rem 0 1.5rem; color: var(--col-accent); font-size: 13px; }
@media (max-width: 700px) {
  .app-body { flex-direction: column; }
  .sidebar { width: auto; border-right: 0; border-bottom: 1px solid var(--col-border); }
}

/* A React app (FrontendsController): the page is one screen high, the app fills
   the pane beside the sidebar and scrolls inside itself. On a narrow screen the
   sidebar gives way to the app's own view picker. */
.frontend-page { display: flex; flex-direction: column; height: 100vh; }
.frontend-page > .app-body { flex: 1; min-height: 0; }
.frontend-page .sidebar { overflow-y: auto; }
.frontend { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
@media (max-width: 768px) {
  .frontend-page .sidebar { display: none; }
}

/* ---------- Navbar ---------- */

#navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 1.5rem;     /* a slim bar (Miles, 2026-11-16) */
  background: var(--col-chrome);
  border-bottom: 1px solid var(--col-border);
}

.nav-brand a {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--col-text);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nav-links form { margin: 0; }

.nav-cta,
.nav-logout {
  padding: 0.2rem 0.8rem;
  border-radius: var(--radius);
  border: 1px solid var(--col-border);
  background: transparent;
  color: var(--col-accent);
  font: inherit;
  cursor: pointer;
}

.nav-cta:hover,
.nav-logout:hover { background: var(--col-hover); text-decoration: none; }

/* ---------- Flash ---------- */

#flash-ctnr {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0 1.5rem;
}

/* Room above a message only when there is one: the partial leaves whitespace inside, so :empty never matched and the
   gap sat above every page (Miles, 2026-11-16). */
#flash-ctnr:has(.flash-message:not(:empty)) { padding-top: 1rem; }

.flash-message {
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
}

.flash-message:empty { display: none; }

.flash-success {
  background: var(--col-success-bg);
  border-color: var(--col-success);
  color: var(--col-success);
}

.flash-failure {
  background: var(--col-failure-bg);
  border-color: var(--col-failure);
  color: var(--col-failure);
}

.flash-info {
  background: var(--col-surface);
  border-color: var(--col-border);
  color: var(--col-muted);
}

/* ---------- Auth forms ---------- */

#user-form-page {
  display: flex;
  justify-content: center;
  padding: 1rem;
}

.form-ctnr {
  width: 100%;
  max-width: 26rem;
  padding: 2rem;
  background: var(--col-surface);
  border: 1px solid var(--col-border);
  border-radius: var(--radius);
}

.user-form-title {
  margin: 0 0 1.5rem;
  font-size: 1.5rem;
  text-align: center;
}

.user-form-blurb {
  margin: 0 0 1.25rem;
  color: var(--col-muted);
  font-size: 0.9rem;
}

.user-form-fields {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.user-field {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 0.35rem;
}

.user-field-inline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.user-labels {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--col-muted);
}

.user-label-text {
  font-size: 0.8rem;
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
}

.user-input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--col-border);
  border-radius: var(--radius);
  background: var(--col-surface);
  color: var(--col-text);
  font: inherit;
}

.user-input:focus {
  outline: none;
  border-color: var(--col-accent);
  box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.25);
}

.uf-cb-ctnr { display: flex; align-items: center; }
.user-cb { width: 1rem; height: 1rem; margin: 0; accent-color: var(--col-accent); }

.uf-error-message {
  min-height: 1rem;
  font-size: 0.78rem;
  color: var(--col-failure);
}

.uf-error-message:empty { min-height: 0; }

.uf-error-summary {
  padding: 0.75rem 1rem;
  border: 1px solid var(--col-failure);
  border-radius: var(--radius);
  background: var(--col-failure-bg);
  color: var(--col-failure);
  font-size: 0.85rem;
}

.uf-error-summary ul { margin: 0.5rem 0 0; padding-left: 1.1rem; }

.user-inline-link { font-size: 0.8rem; }

.user-submit {
  display: inline-block;
  width: 100%;
  padding: 0.7rem 1rem;
  border: 1px solid var(--col-accent);
  border-radius: var(--radius);
  background: var(--col-accent);
  color: var(--col-on-accent);
  font: inherit;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}

.user-submit:hover,
.hover-col2:hover {
  background: var(--col-accent-dark);
  border-color: var(--col-accent-dark);
  text-decoration: none;
}

.user-submit-ghost {
  background: transparent;
  color: var(--col-accent);
}

.user-submit-ghost:hover {
  background: var(--col-hover);
  border-color: var(--col-accent);
  color: var(--col-accent);
}

.user-login-prompt-ctnr {
  text-align: center;
  font-size: 0.85rem;
  color: var(--col-muted);
}

/* ---------- Profile + home ---------- */

.user-detail-list {
  margin: 0 0 1.5rem;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.4rem 1rem;
  font-size: 0.9rem;
}

.user-detail-list dt { color: var(--col-muted); }
.user-detail-list dd { margin: 0; }

.home-hero {
  max-width: 34rem;
  margin: 0 auto;
  text-align: center;
}

.home-hero h1 { font-size: 2.25rem; margin-bottom: 0.5rem; }
.home-hero p { color: var(--col-muted); }
.home-hero .user-submit { width: auto; margin: 0 0.25rem; }

/* ---------- Tenancy: org switcher, superadmin banner ---------- */

.org-switcher { margin: 0; }

.org-switcher-select {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--col-border);
  border-radius: var(--radius);
  background: var(--col-surface);
  color: var(--col-text);
  font-size: 0.85rem;
}

.org-name {
  font-size: 0.85rem;
  color: var(--col-muted);
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--col-border);
  border-radius: var(--radius);
}

.superadmin-banner {
  padding: 0.6rem 1rem;
  background: var(--col-failure-bg);
  color: var(--col-failure);
  border-bottom: 1px solid var(--col-border);
  font-size: 0.85rem;
  text-align: center;
}

.superadmin-banner a { color: var(--col-failure); text-decoration: underline; }
.superadmin-banner form { display: inline; }
.superadmin-banner button { background: none; border: 0; padding: 0; font: inherit; color: var(--col-failure); text-decoration: underline; cursor: pointer; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Shared table styling ---------- */

.form-ctnr-wide { max-width: 68rem; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--col-border);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  font-weight: 600;
  color: var(--col-muted);
  white-space: nowrap;
}

.data-table tbody tr:hover { background: var(--col-hover); }

.status-pill {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--col-bg);
  border: 1px solid var(--col-border);
}

.status-active,
.status-completed,
.status-succeeded,
.status-ready { background: var(--col-success-bg); color: var(--col-success); border-color: transparent; }

.status-failed,
.status-suspended { background: var(--col-failure-bg); color: var(--col-failure); border-color: transparent; }

.status-draft,
.status-waiting,
.status-held { background: rgba(255, 152, 0, 0.14); color: var(--col-warn); border-color: transparent; }

.status-archived { color: var(--col-faint); }

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

/* ---------- Admin: flow templates and stage types ---------- */

.admin-crumb { margin: 0 0 0.25rem; font-size: 0.85rem; }
.admin-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.admin-actions form { margin: 0; }
.admin-section { margin-top: 2rem; }
.admin-section h2 { font-size: 1.05rem; margin: 0 0 0.5rem; }
.admin-section summary { cursor: pointer; font-weight: 600; }

/* AI access (access_tokens/index): a new token's how-to-connect, and the scope ticks. */
.token-snippet { background: var(--col-surface); border: 1px solid var(--col-border); border-radius: var(--radius); padding: 0.75rem; overflow-x: auto; font-size: 0.8rem; margin: 0.25rem 0 0.75rem; white-space: pre-wrap; word-break: break-all; }
.token-scope { display: block; margin: 0.2rem 0; font-weight: 400; }
.admin-hint { font-size: 0.85rem; margin: 0 0 0.75rem; }
.admin-problems { margin-top: 1rem; padding: 0.75rem 1rem; border-radius: var(--radius); background: var(--col-failure-bg); color: var(--col-failure); font-size: 0.9rem; }
.admin-problems ul { margin: 0.4rem 0 0; padding-left: 1.2rem; }
.admin-json { background: var(--col-surface); border: 1px solid var(--col-border); border-radius: var(--radius); padding: 0.75rem; font-size: 0.8rem; overflow-x: auto; }
.admin-json-input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.85rem; }
.data-table code { font-size: 0.8rem; }

.flow-diagram-scroll { overflow-x: auto; background: var(--col-chrome); border: 1px solid var(--col-border); border-radius: var(--radius); padding: 0.5rem; }
.flow-diagram { display: block; margin: 0 auto; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.flow-node { fill: var(--col-surface); stroke: #555; stroke-width: 1.2; }
.flow-node--entry, .flow-node--exit { fill: #1a2a3a; stroke: var(--col-accent); }
.flow-node--flow { fill: #261f33; stroke: var(--col-wait); stroke-width: 1.6; }
.flow-node--manual { stroke-dasharray: 5 3; stroke: var(--col-warn); }
a:hover .flow-node--flow { fill: #31283f; }
.flow-node__title { font-size: 13px; font-weight: 600; fill: var(--col-text); }
.flow-node__sub { font-size: 11px; fill: var(--col-muted); font-family: ui-monospace, Menlo, Consolas, monospace; }
.flow-node__note { font-size: 11px; fill: #aaa; }
.flow-badge { fill: var(--col-bg); stroke: var(--col-border); }
.flow-badge__text { font-size: 10px; fill: var(--col-muted); }
.flow-edge { fill: none; stroke: #6b7380; stroke-width: 1.4; }
.flow-edge--back { stroke-dasharray: 6 4; stroke: var(--col-warn); }
.flow-arrow { fill: #6b7380; }
.flow-edge__label-bg { fill: var(--col-chrome); stroke: var(--col-border-strong); }
.flow-edge__label { font-size: 11px; fill: #bbb; font-family: ui-monospace, Menlo, Consolas, monospace; }
.flow-edge--when { stroke-dasharray: 2 4; }
.flow-edge__label--when { fill: var(--col-wait); }
.flow-stub { stroke: var(--col-faint); stroke-width: 1.2; stroke-dasharray: 3 3; }
.flow-stub__end { fill: none; stroke: var(--col-faint); }
.flow-stub__label { font-size: 10px; fill: var(--col-muted); font-family: ui-monospace, Menlo, Consolas, monospace; }

/* Admin › NAS: roots, the file search and the pending uploads. */
.nas-roots td, .nas-files td { vertical-align: middle; }
.nas-root-path { display: block; font-size: 0.78rem; color: var(--col-muted); }
.nas-root-meta { display: block; font-size: 0.78rem; color: var(--col-muted); margin-top: 0.15rem; }
.nas-form { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.nas-form .user-input { width: auto; padding: 0.35rem 0.5rem; font-size: 0.85rem; }
.nas-form label { display: flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; white-space: nowrap; }
.nas-btn { width: auto; padding: 0.35rem 0.75rem; font-size: 0.85rem; font-weight: 500; }
/* Admin › Workers */
.workers-layout { display: grid; grid-template-columns: minmax(0, 1fr) 22rem; gap: 1.5rem; align-items: start; }
@media (max-width: 1100px) { .workers-layout { grid-template-columns: 1fr; } }
.workers-panel h3 { margin: 1rem 0 0.4rem; font-size: 0.95rem; }
.workers-table tr.is-selected td { background: rgba(255, 255, 255, 0.06); }
.workers-name { font-weight: 600; }
.workers-actions { margin: 0.5rem 0 1rem; }
.workers-policy { gap: 0.5rem 1rem; flex-direction: column; align-items: flex-start; }
.user-input-short { width: 4.5rem !important; }
.workers-table .is-dead td, .workers-instances td { color: inherit; }
.workers-table tr.is-dead td { color: var(--muted, #888); }
.nas-search { margin: 0 0 0.75rem; }
.nas-count { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin: 0 0 0.75rem; font-size: 0.9rem; }
.nas-count .nas-btn:disabled { opacity: 0.45; cursor: default; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nas-state { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.75rem; border: 1px solid var(--col-border); color: var(--col-muted); }
.nas-state.is-up { color: var(--col-on-accent); background: var(--col-accent); border-color: var(--col-accent); }
.nas-state.is-pending { color: var(--col-accent); border-color: var(--col-accent); }
.nas-state.is-failed, .nas-failed { color: #b42318; }
.nas-send .nas-path { min-width: 24rem; }
.nas-changes summary { font-size: 1.05rem; font-weight: 600; cursor: pointer; margin: 2rem 0 0.5rem; }
.admin-section.left h2 { text-align: left; }

/* ---------- No borders: tones (Miles, 2026-11-16) ----------
   "get rid of the borders where possible… just different background colours". The frame (navbar, sidebar, and the
   Data page's search bar and Selected panel) is the sidebar's grey; the page is the dark between it; a control is a
   shade lighter than what it sits on. Borders go transparent rather than away, so nothing moves by a pixel. */
:root { --col-frame: var(--col-surface); --col-control: #303030; --col-control-hover: #3a3a3a; }
#navbar { background: var(--col-frame); border-bottom-color: transparent; }
.sidebar, .sidebar__link { border-color: transparent; }
.sidebar__link--active { background: var(--col-bg); }
.nav-cta, .nav-logout, .org-switcher-select, .org-name, .user-input, .form-ctnr, .token-snippet, .admin-json,
.flow-diagram-scroll, .superadmin-banner, .status-pill, .nas-state, .data-table td, .flash-message, .uf-error-summary,
.user-submit, .user-submit-ghost { border-color: transparent; }
.nav-cta, .nav-logout, .org-name, .org-switcher-select { background: var(--col-control); }
.nav-cta:hover, .nav-logout:hover { background: var(--col-control-hover); }
.user-input { background: var(--col-control); }
.user-input:focus { border-color: transparent; background: var(--col-control-hover); outline: none; }
.data-table tbody tr:nth-child(even) td { background: #ffffff05; }
.flash-info { background: var(--col-surface); }

/* ---------- Hiding the header and the sidebar (Miles, 2026-11-16) ----------
   The two buttons at the foot of the window (chrome_controller.js); the choice is kept in this browser and set on
   <html> before the page draws (layouts/application.html.erb), so a hidden bar never flashes in. */
html.no-navbar #navbar, html.no-sidebar .sidebar { display: none; }
html.no-navbar .app-body { min-height: 100vh; }
.chrome-toggles { position: fixed; left: 6px; bottom: 6px; z-index: 50; display: flex; gap: 4px; opacity: 0.45; transition: opacity 0.15s; }
.chrome-toggles:hover, .chrome-toggles:focus-within { opacity: 1; }
.chrome-toggles button { width: 24px; height: 22px; padding: 0; border: 0; border-radius: 4px; background: var(--col-control); color: var(--col-muted); font-size: 12px; line-height: 22px; cursor: pointer; }
.chrome-toggles button:hover { background: var(--col-control-hover); color: var(--col-text); }
.chrome-toggles button[aria-pressed="false"] { color: var(--col-accent); }
