/* =========================================================
   FlowAI Dashboard — styles
   Light + dark themes. See DESIGN.md for the system.
   ========================================================= */

:root {
  /* Surfaces */
  --bg-page: #fafaf9;
  --bg-app: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-elev: #ffffff;
  --bg-subtle: #f6f6f5;
  --bg-hover: #f2f2f1;
  --bg-active: #f1f1ef;

  /* Text */
  --text-strong: #1b1b1a;
  --text: #3d3d3b;
  --text-muted: #9a9a96;
  --text-faint: #b9b9b4;

  /* Lines */
  --border: #ededeb;
  --border-strong: #e4e4e1;

  /* Accents */
  --green: #16a34a;
  --green-soft-bg: #e9f7ee;
  --amber: #d98a1f;
  --red: #e25555;
  --brand-ink: #161615;

  /* Radii */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;

  /* Shadow */
  --shadow-app: 0 24px 60px -22px rgba(20, 20, 18, 0.22), 0 4px 14px -6px rgba(20, 20, 18, 0.1);
  --shadow-card: 0 1px 2px rgba(20, 20, 18, 0.04);

  --sidebar-w: 256px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  --bg-page: #121212;
  --bg-app: #1a1a1a;
  --bg-sidebar: #181818;
  --bg-elev: #1f1f1f;
  --bg-subtle: #202020;
  --bg-hover: #232323;
  --bg-active: #262625;
  --text-strong: #f2f2ef;
  --text: #cfcfca;
  --text-muted: #8a8a84;
  --text-faint: #66665f;
  --border: #2a2a29;
  --border-strong: #323230;
  --green-soft-bg: #15281c;
  --brand-ink: #f2f2ef;
  --shadow-app: 0 24px 60px -22px rgba(0, 0, 0, 0.6);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg-page);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app-shell {
  height: 100vh;
  padding: 18px;
  display: flex;
}

.app {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  background: var(--bg-app);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-app);
  overflow: hidden;
  min-height: 0;
}

/* ===================== SIDEBAR ===================== */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.sidebar__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 18px 14px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand__mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: #000;
  overflow: hidden;
  flex-shrink: 0;
}
.brand__mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.brand__name { font-weight: 600; font-size: 16px; color: var(--text-strong); letter-spacing: -0.01em; }

/* Nav */
.nav { padding: 4px 12px 8px; }
.nav--scroll { overflow-y: auto; }
.nav__label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  margin: 14px 8px 8px;
  display: flex; align-items: center; gap: 6px;
}
.nav__label::before {
  content: "";
  width: 11px; height: 11px;
  border: 1.5px dashed var(--text-faint);
  border-radius: 50%;
  display: inline-block;
  opacity: .6;
}
.nav__label--mt { margin-top: 18px; }
.nav__label--flush { margin: 0; }
.nav__label--flush::before { display: none; }

.nav__item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 450;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.nav__item:hover { background: var(--bg-hover); }
.nav__item.is-active { background: var(--bg-active); color: var(--text-strong); font-weight: 500; }
.nav__icon { color: var(--text-muted); display: inline-flex; flex-shrink: 0; }
.nav__item.is-active .nav__icon { color: var(--text-strong); }
.nav__text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav__emoji { font-size: 14px; }
.nav__item--toggle { cursor: default; }

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 7px;
  line-height: 1.5;
}
.badge--soft { background: var(--bg-active); color: var(--text-muted); }
.badge--green { background: var(--green-soft-bg); color: var(--green); }

/* Theme toggle */
.theme-toggle {
  border: 1px solid var(--border-strong);
  background: var(--bg-subtle);
  width: 30px; height: 18px;
  border-radius: 20px;
  position: relative;
  cursor: pointer;
  padding: 0;
  color: var(--text-muted);
}
.theme-toggle svg { position: absolute; top: 50%; transform: translateY(-50%); }
.theme-toggle__sun { left: 4px; }
.theme-toggle__moon { right: 4px; opacity: .35; }
[data-theme="dark"] .theme-toggle__sun { opacity: .35; }
[data-theme="dark"] .theme-toggle__moon { opacity: 1; }

/* Runs */
.runs { margin-top: auto; padding: 8px 20px 6px; }
.runs__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.run {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 4px;
  text-decoration: none;
  color: var(--text);
  font-size: 12.5px;
  border-radius: 8px;
}
.run:hover { color: var(--text-strong); }
.run__dot {
  width: 22px; height: 22px;
  border-radius: 7px;
  display: grid; place-items: center;
  flex-shrink: 0;
  background: color-mix(in srgb, var(--c) 16%, transparent);
  color: var(--c);
}
.run__text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.run__star { color: var(--text-faint); flex-shrink: 0; }
.run:hover .run__star { color: var(--amber); }

/* Usage */
.usage {
  margin: 6px 16px 16px;
  padding: 14px;
  border-radius: var(--r-md);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
}
.usage__title { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; color: var(--text-strong); }
.usage__title svg { color: var(--amber); }
.usage__sub { margin: 4px 0 10px; font-size: 11.5px; color: var(--text-muted); }
.usage__bar { height: 6px; border-radius: 6px; background: var(--bg-active); overflow: hidden; }
.usage__bar span { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, #f5b942, var(--amber)); }

/* Shared icon button */
.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-strong); }
.icon-btn--xs { width: 22px; height: 22px; border-radius: 7px; background: var(--bg-subtle); }
.icon-btn--ai { border: 1px solid var(--border-strong); }
.icon-btn--round { border: 1px solid var(--border-strong); border-radius: 50%; width: 30px; height: 30px; }

/* ===================== MAIN ===================== */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar__left { display: flex; align-items: center; gap: 14px; }
.crumb { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; color: var(--text-strong); }
.crumb svg { color: var(--text-muted); }

.topbar__right { display: flex; align-items: center; gap: 12px; }
.search {
  display: flex; align-items: center; gap: 9px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 0 12px;
  height: 38px;
  width: 290px;
  color: var(--text-muted);
}
.search input {
  border: none; background: transparent; outline: none;
  font-family: inherit; font-size: 13px; color: var(--text);
  flex: 1;
}
.search input::placeholder { color: var(--text-muted); }
.search kbd {
  font-size: 11px; font-family: inherit; color: var(--text-muted);
  background: var(--bg-app); border: 1px solid var(--border-strong);
  border-radius: 6px; padding: 2px 6px;
}
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  color: #fff; font-size: 12px; font-weight: 600;
  display: grid; place-items: center;
}

/* Content */
.content { padding: 26px 28px 30px; overflow-y: auto; min-height: 0; }

.welcome { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.welcome__title { margin: 0; font-size: 25px; font-weight: 600; letter-spacing: -0.02em; color: var(--text-strong); }
.welcome__sub { margin: 6px 0 0; font-size: 14px; color: var(--text-muted); }
.welcome__actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.pill-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 14px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--bg-app);
  color: var(--text); font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer;
}
.pill-btn svg { color: var(--text-muted); }
.pill-btn:hover { background: var(--bg-hover); }

.btn-primary {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border-radius: 11px; border: none;
  background: var(--brand-ink); color: #fff;
  font-family: inherit; font-size: 13px; font-weight: 550;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,.18);
}
[data-theme="dark"] .btn-primary { color: #161615; }
.btn-primary:hover { opacity: .9; }

/* Stat cards */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stats--summary { grid-template-columns: repeat(5, 1fr); }
.stat {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 7px;
  box-shadow: var(--shadow-card);
}
.stat__box {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 15px 16px 16px;
}
.stat__head { display: flex; align-items: center; gap: 9px; margin-bottom: 13px; }
.stat__icon {
  width: 26px; height: 26px; border-radius: 8px;
  background: var(--bg-elev); border: 1px solid var(--border-strong);
  display: grid; place-items: center; color: var(--text-muted);
}
.stat__label { font-size: 13px; color: var(--text-muted); font-weight: 450; }
.stat__value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; color: var(--text-strong); line-height: 1; }
.stat__foot { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; padding: 11px 10px 6px; }
.stat__foot > span:not(.trend-pct) { color: var(--text-muted); font-weight: 450; }
.stat__foot.up { color: var(--green); }
.stat__foot.down { color: var(--red); }

/* Panel / table */
.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  margin-bottom: 24px;
  overflow: hidden;
}
.panel__head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 12px; }
.panel__title { margin: 0; font-size: 16px; font-weight: 600; color: var(--text-strong); letter-spacing: -0.01em; }
.panel__link { font-size: 13px; font-weight: 500; color: var(--text-muted); text-decoration: none; }
.panel__link:hover { color: var(--text-strong); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table thead th {
  text-align: left; padding: 10px 16px;
  font-size: 12px; font-weight: 500; color: var(--text-muted);
  background: var(--bg-subtle);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table thead th:first-child { padding-left: 20px; }
.table tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}
.table tbody td:first-child { padding-left: 20px; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--bg-subtle); }
.ta-r { text-align: right; }
.t-mono { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.t-strong { color: var(--text-strong); font-weight: 500; }

/* Workflow name cell with colored icon */
.wf { display: inline-flex; align-items: center; gap: 10px; }
.wf__ic {
  width: 24px; height: 24px; border-radius: 7px;
  display: grid; place-items: center; flex-shrink: 0;
  background: color-mix(in srgb, var(--c) 15%, transparent);
  color: var(--c);
}

/* Success % — color tiers (also applied dynamically in app.js) */
.success { font-weight: 600; }
.t-good { color: var(--green); font-weight: 600; }
.t-warn { color: var(--amber); font-weight: 600; }
.t-bad  { color: var(--red); font-weight: 600; }
.t-time { color: var(--text-muted); }
.t-time::before {
  content: "";
  display: inline-block; width: 12px; height: 12px;
  margin-right: 6px; vertical-align: -2px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E") center/contain no-repeat;
  opacity: .7;
}
.status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; color: var(--green);
  background: var(--green-soft-bg);
  padding: 4px 9px; border-radius: 7px;
  border: 1px solid color-mix(in srgb, var(--green) 22%, var(--border-strong));
}
.status::before { content: ""; width: 5px; height: 5px; border-radius: 2px; background: var(--green); }
.link { color: var(--text-muted); text-decoration: none; font-weight: 500; margin-left: 14px; }
.link:first-child { margin-left: 0; }
.link:hover { color: var(--text-strong); }

/* Templates */
.templates__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.templates__nav { display: flex; gap: 8px; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.tcard {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 12px;
  box-shadow: var(--shadow-card);
  transition: transform .15s ease, box-shadow .15s ease;
}
.tcard:hover { transform: translateY(-2px); box-shadow: 0 10px 24px -14px rgba(20,20,18,.25); }
.tcard__thumb {
  position: relative;
  height: 118px;
  border-radius: 12px;
  background: radial-gradient(120% 120% at 50% 0%, var(--bg-subtle), var(--bg-active));
  border: 1px solid var(--border);
  display: grid; place-items: center;
  overflow: hidden;
  margin-bottom: 12px;
}
.tchip {
  position: absolute; top: 10px; right: 10px;
  font-size: 11px; font-weight: 600;
  padding: 2px 9px; border-radius: 20px;
  background: var(--bg-app); border: 1px solid var(--border-strong);
}
.tchip--active { color: var(--green); }
.tchip--paused { color: var(--amber); }

/* isometric grey 3D-ish shapes */
.iso { width: 64px; height: 64px; filter: drop-shadow(0 8px 10px rgba(40,40,38,.18)); }
.iso--doc { background:
  linear-gradient(135deg, #d9d9d6, #b9b9b4);
  border-radius: 8px; transform: rotate(-8deg);
  box-shadow: 6px 6px 0 -1px #cacac6, 12px 12px 0 -2px #d6d6d2; }
.iso--bars {
  background: repeating-linear-gradient(90deg, #c4c4c0 0 10px, transparent 10px 18px);
  height: 56px; width: 70px; transform: skewY(-8deg);
  border-radius: 4px; }
.iso--stack {
  width: 70px; height: 56px;
  background: linear-gradient(135deg, #cfcfca, #aeaea9);
  border-radius: 8px; transform: rotate(6deg);
  box-shadow: -6px 6px 0 -1px #c2c2be, -12px 12px 0 -2px #d2d2ce; }
.iso--cube {
  width: 58px; height: 58px;
  background: linear-gradient(135deg, #c9c9c5, #a6a6a1);
  transform: rotate(45deg) scale(.82);
  border-radius: 10px;
  box-shadow: inset 0 0 0 6px rgba(255,255,255,.25); }
[data-theme="dark"] .iso--doc,
[data-theme="dark"] .iso--stack,
[data-theme="dark"] .iso--cube { filter: drop-shadow(0 8px 10px rgba(0,0,0,.4)) brightness(.55); }
[data-theme="dark"] .iso--bars { filter: brightness(.5); }

.tcard__title { margin: 0 0 4px; font-size: 14px; font-weight: 600; color: var(--text-strong); }
.tcard__meta { margin: 0 0 12px; font-size: 12px; color: var(--text-muted); }
.tcard__meta .dot { margin: 0 5px; }
.tcard__foot { display: flex; align-items: center; justify-content: space-between; }
.apps { display: flex; }
.apps i {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 9px; font-weight: 700; font-style: normal; color: #fff;
  background: var(--c);
  border: 2px solid var(--bg-elev);
  margin-left: -7px;
}
.apps i:first-child { margin-left: 0; }
.tcard__runs { font-size: 12px; color: var(--text-muted); font-weight: 500; }

/* Scrollbars */
.nav--scroll::-webkit-scrollbar, .content::-webkit-scrollbar, .table-wrap::-webkit-scrollbar { width: 8px; height: 8px; }
.nav--scroll::-webkit-scrollbar-thumb, .content::-webkit-scrollbar-thumb, .table-wrap::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }

/* Responsive */
@media (max-width: 1100px) {
  .stats, .cards { grid-template-columns: repeat(2, 1fr); }
  .stats--summary { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .search { width: 180px; }
  .stats, .cards, .stats--summary { grid-template-columns: 1fr; }
}
