/* Graxeon Flow — base styles.
   Variable names and the topbar/modal/tabs/settings/form components below
   are ported verbatim from explorer/static/style.css so the shared profile
   modal (static/js/profile.js) and theme system (light/dark + accent
   override) behave identically across Explorer, Studio, and Flow. */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg:           #0f0f17;
  --surface:      #1a1a28;
  --surface-2:    #22223a;
  --border:       #2e2e4a;
  --text:         #e0e0f0;
  --text-muted:   #9898b8;
  --accent:       #1d9e75;
  --accent-hover: #17845f;
  --error:        #e05c5c;
  --radius:       10px;
  --font:         -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --icon-border:  #fff;
}

[data-theme="light"] {
  --bg:           #f4f4f8;
  --surface:      #ffffff;
  --surface-2:    #ebebf2;
  --border:       #d0d0e0;
  --text:         #1a1a2e;
  --text-muted:   #6060a0;
  --icon-border:  #000;
}

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

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

/* ── Topbar ─────────────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 24px;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-title { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; flex-shrink: 0; }
.app-title:hover { text-decoration: none; }
.app-title h1 { font-size: 1rem; font-weight: 600; color: var(--text); margin: 0; }
.app-title p  { font-size: 0.78rem; color: var(--text-muted); margin: 1px 0 0; }
.app-title-icon { width: 30px; height: 30px; flex-shrink: 0; }

/* Desktop: the collapsible group (nav + cross-links + username) flexes to
   fill the space between the brand and the always-visible gear/avatar.
   Below the mobile breakpoint it becomes a dropdown panel — see the
   "Topbar — mobile" block at the end of this file. */
.topbar__menu { flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 20px; min-width: 0; }
.topbar__actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.topbar-menu-toggle { display: none; }
.hamburger-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  flex-shrink: 0;
}
.hamburger-btn:hover { background: var(--surface-2); }
.hamburger-btn svg { width: 22px; height: 22px; }

.topbar__nav { display: flex; gap: 4px; }
.topbar__nav a {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}
.topbar__nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.topbar__nav a.active { color: var(--accent); background: var(--surface-2); }

.topbar__right { display: flex; align-items: center; gap: 14px; }
.topbar__user { font-size: 0.85rem; color: var(--text-muted); cursor: pointer; }
.topbar__user:hover { color: var(--text); }

.settings-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  flex-shrink: 0;
}
.settings-btn:hover { color: var(--text); background: var(--surface-2); }
.settings-btn svg { width: 18px; height: 18px; }

/* ── User avatar ─────────────────────────────────────────────────────────────── */

.user-avatar-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.user-avatar { width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; }
.user-avatar--initials {
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
}
.user-avatar--img { object-fit: cover; display: block; }

/* ── Layout ─────────────────────────────────────────────────────────────────── */

.main { max-width: 960px; margin: 0 auto; padding: 28px 24px 60px; }

h1 { font-size: 1.35rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.subtitle { color: var(--text-muted); margin: 0 0 20px; font-size: 0.9rem; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
  text-decoration: none;
}
.btn:hover { border-color: var(--text-muted); text-decoration: none; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--ghost { background: transparent; }
.btn--sm { padding: 5px 12px; font-size: 0.8rem; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 16px;
}
.back-link:hover { color: var(--text); text-decoration: none; }
.back-link svg { width: 15px; height: 15px; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
}
.card-list { display: flex; flex-direction: column; gap: 10px; }
.card-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.card-row__title { font-weight: 600; }
.card-row__meta { color: var(--text-muted); font-size: 0.85rem; }

.empty-state { color: var(--text-muted); padding: 30px 0; text-align: center; }

/* ── Dashboard ──────────────────────────────────────────────────────────────── */

.chart-legend { display: flex; gap: 16px; margin-bottom: 10px; }
.chart-legend__item { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--text-muted); }
.chart-legend__swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }

.chart { display: block; width: 100%; height: 160px; }

.chart-axis {
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-top: 6px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
@media (max-width: 720px) {
  .dashboard-grid { grid-template-columns: 1fr; }
}
.dashboard-grid .card { margin-bottom: 0; }

.dash-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  padding: 6px 0;
  font-size: 0.85rem;
}
.dash-row:hover { color: var(--accent); text-decoration: none; }
.dash-row__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-row__meta { color: var(--text-muted); font-size: 0.78rem; flex-shrink: 0; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.badge--success { color: var(--accent); border-color: var(--accent); }
.badge--failed   { color: var(--error); border-color: var(--error); }
.badge--partial  { color: #c99a3a; border-color: #c99a3a; }
.badge--enabled  { color: var(--accent); border-color: var(--accent); }
.badge--disabled { color: var(--text-muted); }

/* ── Forms (page-level, e.g. login/new-flow — not the profile modal's .form) ─── */

form.stacked { display: flex; flex-direction: column; gap: 14px; max-width: 520px; }
form.stacked label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 4px; }
form.stacked input[type=text], form.stacked input[type=number], form.stacked input[type=url],
form.stacked input[type=password], form.stacked input[type=email], form.stacked select {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
}
form.stacked input:focus, form.stacked select:focus { border-color: var(--accent); outline: none; }
.field-hint { color: var(--text-muted); font-size: 0.8rem; margin-top: 4px; }

.mapping-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; margin-bottom: 8px; }
.mapping-row__arrow { color: var(--text-muted); }

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 500; }

code, pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 0.85em;
}
pre { padding: 10px; overflow-x: auto; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; border: 1px solid var(--error); color: var(--error); }

.login-shell { max-width: 360px; margin: 80px auto; }

/* ── Modal ──────────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 480px;
  max-width: 100%;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title { font-weight: 600; font-size: 1rem; color: var(--text); }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
  border-radius: 4px;
}
.modal-close:hover { color: var(--text); background: var(--surface-2); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 10px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Tabs ───────────────────────────────────────────────────────────────────── */

.tabs { display: flex; border-bottom: 1px solid var(--border); padding: 0 24px; flex-shrink: 0; }
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 12px 16px;
  font-size: 0.875rem;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn--active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.tab-panel[hidden] { display: none; }

.tab-body, .modal-body {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.tab-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

/* ── Profile & settings rows — matches Studio's settings-tab-body layout:
   spacing between rows/section-labels comes from .tab-body's own `gap`
   above, not per-row borders. ─────────────────────────────────────────────── */

.settings-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.settings-input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  color: var(--text);
  font-size: 0.82rem;
  outline: none;
  font-family: inherit;
  flex-shrink: 0;
  min-width: 220px;
}
.settings-input:focus { border-color: var(--accent); }

.save-msg { font-size: 0.82rem; }
.save-msg--ok    { color: var(--accent); }
.save-msg--error { color: var(--error); }

.settings-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.settings-row-label { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; padding-top: 2px; }
.settings-row-title { font-size: 13px; color: var(--text); font-weight: 500; }
.settings-row-hint  { font-size: 11px; color: var(--text-muted); }

.settings-theme-options { display: flex; gap: 6px; flex-shrink: 0; }
.settings-theme-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  user-select: none;
  min-width: 60px;
  transition: border-color 0.1s;
}
.settings-theme-card input[type=radio] { display: none; }
.settings-theme-card:hover { border-color: var(--text-muted); }
.settings-theme-card.active { border-color: var(--accent); background: var(--surface-2); }
.settings-theme-icon { font-size: 18px; line-height: 1; }
.settings-theme-label { font-size: 11px; color: var(--text-muted); }
.settings-theme-card.active .settings-theme-label { color: var(--accent); font-weight: 500; }

.settings-accent-row { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.settings-color-input {
  width: 40px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
  outline: none;
  flex-shrink: 0;
}
.settings-color-input:hover { border-color: var(--text-muted); }
.settings-color-value { font-size: 11px; color: var(--text-muted); font-family: 'Consolas', 'Monaco', monospace; }

/* ── Mobile ─────────────────────────────────────────────────────────────────── */

@media (max-width: 760px) {
  /* Topbar: collapse nav + cross-links + username behind the hamburger
     toggle (a hidden checkbox + label, no JS — see templates/base.html).
     The gear and avatar stay on the primary row since they're used every
     visit; everything else drops into a dropdown panel below the bar. */
  .topbar { gap: 10px; padding: 0 14px; }
  .app-title p { display: none; }
  .hamburger-btn { display: flex; }

  .topbar__menu {
    display: none;
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 18px 18px;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
  }
  #topbarMenuToggle:checked ~ #topbarMenu { display: flex; }

  .topbar__menu .topbar__nav { flex-direction: column; gap: 2px; }
  .topbar__menu .topbar__nav a { padding: 10px 12px; }
  .topbar__menu .topbar__right { flex-direction: column; align-items: stretch; gap: 8px; }
  .topbar__menu .topbar__right .btn { width: 100%; }
  .topbar__menu .topbar__user { padding: 8px 12px; }

  .main { padding: 20px 14px 40px; }

  /* Profile modal: a fixed-width label + 220px input can't sit side by side
     on a phone-width modal — stack each settings-row instead. */
  .modal-overlay { padding: 10px; }
  .modal { width: 100%; max-height: 88vh; }
  .settings-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .settings-input, .settings-theme-options, .settings-accent-row { width: 100%; min-width: 0; }
  .settings-theme-options { justify-content: space-between; }

  /* Field mapping: two selects + an arrow don't need the arrow once stacked. */
  .mapping-row { grid-template-columns: 1fr; gap: 4px; }
  .mapping-row__arrow { display: none; }

  /* Run history / field mapping tables — scroll instead of squeezing columns. */
  table { display: block; overflow-x: auto; white-space: nowrap; }

  .login-shell { margin: 40px auto; }
}
