/* ── Oxygen font (self-hosted, matches machinedge.io) ──────────────────── */
@font-face {
  font-family: 'Oxygen';
  font-style:  normal;
  font-weight: 300;
  font-display: swap;
  src: url('../fonts/Oxygen-Light.ttf') format('truetype');
}
@font-face {
  font-family: 'Oxygen';
  font-style:  normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/Oxygen-Regular.ttf') format('truetype');
}
@font-face {
  font-family: 'Oxygen';
  font-style:  normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/Oxygen-Bold.ttf') format('truetype');
}

/* ── Design tokens (aligned with admin_ui / machinedge.io brand) ──────── */
:root {
  --bg:        #091421;
  --bg2:       #132236;
  --bg3:       #0f1d30;
  --border:    rgba(255,255,255,0.16);
  --teal:      #2ecc71;
  --teal-dim:  #3ddf82;
  --blue:      #4a9abb;
  --text:      #f7fbff;
  --text-dim:  #a7b5c7;
  --text-mute: #7a8a9e;
  --danger:    #e07060;
  --success:   #2ecc71;
  --radius:    0.75rem;
  --radius-sm: 0.5rem;
  --font:      'Oxygen', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --rail-w:    84px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Login overlay (same vocabulary as admin_ui) ───────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 30% 20%, rgba(46,204,113,0.08), transparent 60%),
              var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 45px rgba(0,0,0,0.35);
}

.login-logo {
  display: block;
  max-width: 180px;
  margin: 0 auto 0.75rem;
}

.login-subtitle {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.95rem;
  margin-bottom: 1.75rem;
}

.field { margin-bottom: 1rem; }
.field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}
.field input {
  width: 100%;
  padding: 0.65rem 0.9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s ease;
}
.field input:focus { border-color: var(--teal); }

/* Password input with show/hide toggle. */
.password-wrap {
  position: relative;
}
.password-wrap input {
  padding-right: 2.4rem;   /* leave room for the eye icon */
}
.password-toggle {
  position: absolute;
  top: 50%;
  right: 0.55rem;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--text-mute);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color 0.12s ease, background 0.12s ease;
}
.password-toggle:hover {
  color: var(--text);
  background: rgba(255,255,255,0.04);
}
.password-toggle:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
}
.password-toggle svg {
  width: 18px;
  height: 18px;
  display: block;
}

.error-msg {
  margin-top: 1rem;
  padding: 0.6rem 0.75rem;
  background: rgba(224,112,96,0.12);
  border: 1px solid rgba(224,112,96,0.35);
  color: var(--danger);
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}
.error-msg.ok {
  background: rgba(46,204,113,0.12);
  border-color: rgba(46,204,113,0.35);
  color: var(--teal);
}

.form-switch {
  margin-top: 1.25rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.form-switch a {
  color: var(--teal);
  text-decoration: none;
  font-weight: 600;
  margin-left: 0.25rem;
}
.form-switch a:hover { color: var(--teal-dim); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary {
  background: var(--teal);
  color: #0b1a2d;
}
.btn-primary:hover:not(:disabled) { background: var(--teal-dim); }
.btn-full { width: 100%; margin-top: 0.5rem; padding: 0.75rem; font-size: 1rem; }

/* ── Shell layout ───────────────────────────────────────────────────────── */
:root {
  --subrail-w: 240px;
}

.shell {
  display: grid;
  /* Middle column = subrail. Default width 0 so the iframe gets full width
     on views that don't need it (Flows, Settings). Toggled open by the
     .subrail-open class below. `overflow: hidden` on the subrail clips its
     content when the track collapses. */
  grid-template-columns: var(--rail-w) 0 1fr;
  grid-template-rows: 1fr;
  height: 100vh;
  transition: grid-template-columns 0.15s ease;
}
.shell.subrail-open {
  grid-template-columns: var(--rail-w) var(--subrail-w) 1fr;
}

/* Left rail */
.rail {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 0.75rem 0.5rem;
  overflow: hidden;
}

.rail-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 0 0.75rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.rail-logo {
  width: 100%;
  max-width: 64px;
  height: auto;
  display: block;
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.rail-btn {
  all: unset;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.65rem 0.3rem;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  text-align: center;
}
.rail-btn:hover {
  background: var(--bg3);
  color: var(--text);
}
.rail-btn.active {
  background: rgba(46,204,113,0.14);
  color: var(--teal);
}
.rail-btn:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.rail-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  line-height: 0;
}
.rail-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}
.rail-label {
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.rail-spacer { flex: 1 1 auto; }

.rail-footer {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.rail-user {
  display: block;
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-mute);
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 0.25rem;
}

.rail-signout { color: var(--text-mute); }
.rail-signout:hover { color: var(--danger); }

/* ── Subrail (secondary sidebar, shown for Assistants view) ─────────────── */
.subrail {
  background: var(--bg3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
.shell.subrail-open .subrail {
  border-right: 1px solid var(--border);
}

.subrail-header {
  padding: 0.85rem 1rem 0.65rem;
  border-bottom: 1px solid var(--border);
}
.subrail-title {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-mute);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.subrail-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.subrail-empty {
  padding: 1rem;
  color: var(--text-mute);
  font-size: 0.85rem;
  text-align: center;
}

.ws-group {
  margin-bottom: 0.25rem;
}

.ws-header {
  all: unset;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.45rem 0.85rem;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.12s ease, color 0.12s ease;
}
.ws-header:hover {
  background: rgba(255,255,255,0.03);
  color: var(--text);
}
.ws-header.active {
  color: var(--text);
}
.ws-header .ws-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  color: var(--text-mute);
  flex: 0 0 auto;
}
.ws-header .ws-icon svg { width: 100%; height: 100%; display: block; }
.ws-header .ws-caret {
  width: 12px;
  height: 12px;
  color: var(--text-mute);
  transition: transform 0.15s ease;
  flex: 0 0 auto;
}
.ws-header[aria-expanded="false"] .ws-caret {
  transform: rotate(-90deg);
}
.ws-header .ws-name {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ws-children {
  display: flex;
  flex-direction: column;
}
.ws-children.collapsed { display: none; }

.asst-item {
  all: unset;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.9rem 0.4rem 2.35rem;
  color: var(--text-dim);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.asst-item:hover {
  background: rgba(255,255,255,0.03);
  color: var(--text);
}
.asst-item.active {
  background: rgba(46,204,113,0.12);
  color: var(--text);
  border-left: 2px solid var(--teal);
  padding-left: calc(2.35rem - 2px);
}
.asst-item .asst-name {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.asst-item .asst-meta {
  font-size: 0.72rem;
  color: var(--text-mute);
}

.asst-empty {
  padding: 0.4rem 0.9rem 0.6rem 2.35rem;
  font-size: 0.78rem;
  color: var(--text-mute);
  font-style: italic;
}

/* ── Pane (iframe host) ─────────────────────────────────────────────────── */
.pane {
  position: relative;
  background: var(--bg);
  overflow: hidden;
}

#pane-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--bg);
  display: block;
}

.pane-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.pane-loading.visible {
  opacity: 1;
  pointer-events: auto;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
