/* =========================================================
   FlowPilot AI — Design tokens, base styles, application shell
   ========================================================= */
:root {
  /* Core palette */
  --fp-sidebar: #172536;
  --fp-sidebar-2: #1b2b3f;
  --fp-header: #1E293B;
  --fp-bg: #F8FAFC;
  --fp-card: #FFFFFF;
  --fp-primary: #1677FF;
  --fp-primary-600: #0E63DB;
  --fp-success: #00A65A;
  --fp-success-600: #008C4C;
  --fp-ai-green: #16A34A;
  --fp-warning: #F59E0B;
  --fp-warning-600: #D98806;
  --fp-purple: #7C3AED;
  --fp-purple-600: #6A2BD6;
  --fp-danger: #EF4444;
  --fp-danger-600: #DC2626;
  --fp-text: #0F172A;
  --fp-text-2: #64748B;
  --fp-text-3: #94A3B8;
  --fp-border: #E2E8F0;
  --fp-border-2: #CBD5E1;

  /* Tints */
  --fp-primary-50: #EEF5FF;
  --fp-primary-100: #DCEBFF;
  --fp-success-50: #E8F7F0;
  --fp-success-100: #CDEFDF;
  --fp-warning-50: #FFF7E8;
  --fp-warning-100: #FDEBC8;
  --fp-purple-50: #F4EEFF;
  --fp-purple-100: #E6DAFE;
  --fp-danger-50: #FEF0F0;
  --fp-danger-100: #FDDCDC;
  --fp-slate-50: #F1F5F9;
  --fp-slate-100: #E9EEF4;

  /* Shape & depth */
  --fp-radius-sm: 6px;
  --fp-radius: 8px;
  --fp-radius-lg: 12px;
  --fp-shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --fp-shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
  --fp-shadow-md: 0 6px 16px rgba(15, 23, 42, .08);
  --fp-shadow-lg: 0 20px 48px rgba(15, 23, 42, .18);
  --fp-focus: 0 0 0 3px rgba(22, 119, 255, .35);

  /* Layout */
  --fp-sidebar-w: 248px;
  --fp-sidebar-w-collapsed: 72px;
  --fp-header-h: 64px;
  --fp-gutter: 24px;

  --fp-font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  --fp-mono: "Cascadia Mono", "Consolas", "SFMono-Regular", Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--fp-font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--fp-text);
  background: var(--fp-bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5 { margin: 0; color: var(--fp-text); line-height: 1.3; font-weight: 600; }
h1 { font-size: 22px; letter-spacing: -.01em; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
h4 { font-size: 14px; }
p { margin: 0 0 8px; }
a { color: var(--fp-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
small, .text-sm { font-size: 12.5px; }
.text-xs { font-size: 11.5px; }
.muted { color: var(--fp-text-2); }
.faint { color: var(--fp-text-3); }
.strong { font-weight: 600; }
.mono { font-family: var(--fp-mono); font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
:focus-visible { outline: none; box-shadow: var(--fp-focus); border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
hr { border: 0; border-top: 1px solid var(--fp-border); margin: 16px 0; }

/* Icons */
.ic { width: 18px; height: 18px; flex: 0 0 auto; display: inline-block; vertical-align: middle; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ic-sm { width: 15px; height: 15px; }
.ic-xs { width: 13px; height: 13px; }
.ic-lg { width: 22px; height: 22px; }
.ic-xl { width: 28px; height: 28px; }

/* ---------------- Application shell ---------------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40;
  width: var(--fp-sidebar-w);
  background: var(--fp-sidebar);
  color: #fff;
  display: flex; flex-direction: column;
  transition: width .2s ease, transform .25s ease;
}
.sidebar-brand {
  height: var(--fp-header-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 18px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  flex: 0 0 auto;
}
.sidebar-brand a { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; }
.sidebar-brand .brand-icon { width: 34px; height: 34px; object-fit: contain; flex: 0 0 auto; }
.sidebar-brand .brand-word { height: 27px; width: auto; object-fit: contain; }
.sidebar-nav { flex: 1 1 auto; overflow-y: auto; padding: 14px 12px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7F93AD; padding: 10px 12px 6px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; margin-bottom: 2px;
  border-radius: var(--fp-radius);
  color: #fff; font-weight: 500; font-size: 14px;
  text-decoration: none; position: relative;
  transition: background .15s ease, color .15s ease;
}
.nav-item .ic { color: #B4C3D6; }
.nav-item:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.nav-item:hover .ic { color: #fff; }
.nav-item.active { background: var(--fp-primary); color: #fff; box-shadow: 0 4px 12px rgba(22,119,255,.35); }
.nav-item.active .ic { color: #fff; }
.nav-item .nav-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
  background: var(--fp-warning); color: var(--fp-text);
}
.nav-badge.blue { background: rgba(255,255,255,.16); color: #fff; }
.nav-item.active .nav-badge { background: #fff; color: var(--fp-primary); }
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.06); }
.demo-pill {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: rgba(124,58,237,.16); border: 1px solid rgba(124,58,237,.35);
  border-radius: var(--fp-radius); font-size: 12px; color: #E6DAFE;
}
.demo-pill .ic { color: #C4B5FD; }
.demo-pill b { color: #fff; display: block; font-size: 12.5px; }
.collapse-btn {
  margin-top: 8px; width: 100%; display: flex; align-items: center; gap: 12px;
  background: transparent; border: 0; color: #B4C3D6; padding: 9px 12px; border-radius: var(--fp-radius);
  font: inherit; cursor: pointer;
}
.collapse-btn:hover { background: rgba(255,255,255,.07); color: #fff; }

/* Collapsed sidebar (desktop) */
body.sb-collapsed .sidebar { width: var(--fp-sidebar-w-collapsed); }
body.sb-collapsed .sidebar .brand-word,
body.sb-collapsed .sidebar .nav-text,
body.sb-collapsed .sidebar .nav-label,
body.sb-collapsed .sidebar .demo-pill .demo-text,
body.sb-collapsed .sidebar .collapse-btn .nav-text { display: none; }
body.sb-collapsed .sidebar-brand { padding: 0; justify-content: center; }
body.sb-collapsed .nav-item, body.sb-collapsed .collapse-btn { justify-content: center; padding: 10px; }
body.sb-collapsed .nav-item .nav-badge { position: absolute; top: 2px; right: 4px; min-width: 16px; height: 16px; font-size: 10px; padding: 0 4px; }
body.sb-collapsed .demo-pill { justify-content: center; padding: 10px; }
body.sb-collapsed .collapse-btn .ic { transform: rotate(180deg); }
body.sb-collapsed .main { margin-left: var(--fp-sidebar-w-collapsed); }
/* tooltip for collapsed items */
body.sb-collapsed .sidebar [data-tip]:hover::after {
  content: attr(data-tip); position: absolute; left: calc(100% + 12px); top: 50%; transform: translateY(-50%);
  background: var(--fp-text); color: #fff; font-size: 12px; font-weight: 500; padding: 5px 10px; border-radius: 6px;
  white-space: nowrap; box-shadow: var(--fp-shadow-md); pointer-events: none; z-index: 60;
}
body.sb-collapsed .sidebar [data-tip] { position: relative; }

.main { flex: 1; min-width: 0; margin-left: var(--fp-sidebar-w); display: flex; flex-direction: column; transition: margin-left .2s ease; }

/* Top header */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--fp-header-h);
  background: var(--fp-header);
  color: #fff;
  display: flex; align-items: center; gap: 16px;
  padding: 0 var(--fp-gutter);
  box-shadow: 0 1px 0 rgba(0,0,0,.2);
}
.topbar .icon-btn { color: #CBD5E1; }
.topbar .icon-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.topbar .mobile-menu-btn { display: none; }
.crumbs { display: flex; flex-direction: column; min-width: 0; }
.crumbs .crumb-path { font-size: 12px; color: #94A3B8; display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; }
.crumbs .crumb-path a { color: #94A3B8; }
.crumbs .crumb-path a:hover { color: #fff; }
.crumbs .crumb-path .ic { width: 12px; height: 12px; }
.crumbs .crumb-title { font-size: 15px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-search { position: relative; flex: 1; max-width: 440px; margin-left: auto; }
.top-search input {
  width: 100%; height: 38px; border-radius: var(--fp-radius);
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.1);
  color: #fff; padding: 0 12px 0 38px; font: inherit; font-size: 13.5px;
}
.top-search input::placeholder { color: #94A3B8; }
.top-search input:focus { outline: none; background: rgba(255,255,255,.12); border-color: var(--fp-primary); box-shadow: var(--fp-focus); }
.top-search > .ic { position: absolute; left: 12px; top: 10px; color: #94A3B8; }
.top-search kbd { position: absolute; right: 10px; top: 9px; font: 11px var(--fp-font); color: #94A3B8; border: 1px solid rgba(255,255,255,.15); border-radius: 4px; padding: 1px 5px; }
.search-results {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  background: #fff; color: var(--fp-text); border-radius: var(--fp-radius-lg); box-shadow: var(--fp-shadow-lg);
  border: 1px solid var(--fp-border); max-height: 420px; overflow-y: auto; padding: 6px; display: none;
}
.search-results.open { display: block; }
.search-results .sr-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--fp-text-2); padding: 8px 10px 4px; font-weight: 600; }
.search-results a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--fp-text); }
.search-results a:hover, .search-results a.kb { background: var(--fp-primary-50); text-decoration: none; }
.search-results a .ic { color: var(--fp-text-2); }
.search-results .sr-empty { padding: 18px; text-align: center; color: var(--fp-text-2); }
.top-actions { display: flex; align-items: center; gap: 6px; }
.approval-chip {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px;
  border-radius: 17px; background: rgba(245,158,11,.16); color: #FCD34D; font-weight: 600; font-size: 12.5px;
  border: 1px solid rgba(245,158,11,.35); white-space: nowrap;
}
.approval-chip:hover { background: rgba(245,158,11,.26); text-decoration: none; color: #FDE68A; }
.dot-badge { position: absolute; top: 6px; right: 6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--fp-danger); color: #fff; font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; border: 2px solid var(--fp-header); }
.user-btn {
  display: flex; align-items: center; gap: 10px; background: transparent; border: 0; color: #fff; cursor: pointer;
  padding: 4px 8px 4px 4px; border-radius: 22px; font: inherit;
}
.user-btn:hover { background: rgba(255,255,255,.08); }
.user-btn .u-name { font-weight: 600; font-size: 13px; line-height: 1.2; text-align: left; }
.user-btn .u-role { font-size: 11.5px; color: #94A3B8; text-align: left; }

.content { padding: var(--fp-gutter); flex: 1; width: 100%; max-width: 1600px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .ph-sub { color: var(--fp-text-2); margin-top: 4px; }
.page-head .ph-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-head .back-link { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--fp-text-2); margin-bottom: 6px; }
.page-head .back-link:hover { color: var(--fp-primary); }
.app-foot { padding: 14px var(--fp-gutter) 24px; color: var(--fp-text-3); font-size: 12px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* Sidebar overlay (mobile) */
.sb-overlay { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 35; }
