/* TraxFlow shell - shared design tokens + sidebar/header/component classes,
   ported from cloud_service's base.html + app.css so this app matches the
   same visual language. Tailwind (tailwind.min.css) handles utility classes;
   this file covers the pieces Tailwind alone can't (CSS vars, sidebar
   collapse mechanics, component "chrome"). */

:root {
  --bg-primary: #0a0f1a;
  --bg-secondary: #0d1420;
  --bg-card: #111827;
  --bg-card-darker: #0c1322;
  --bg-hover: rgba(0, 212, 255, 0.05);
  --bg-input: #0c1322;
  --bg-surface: #151d2e;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-cyan: #60a5fa;
  --border-color: rgba(55, 65, 81, 0.5);
  --border-light: rgba(55, 65, 81, 0.3);
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --radius-xl: 16px;
}
html:not(.dark) {
  --bg-primary: #f8fafc;
  --bg-secondary: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-darker: #f8fafc;
  --bg-hover: rgba(59, 130, 246, 0.06);
  --bg-input: #ffffff;
  --bg-surface: #eef2ff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-cyan: #2563eb;
  --border-color: rgba(148, 163, 184, 0.35);
  --border-light: rgba(148, 163, 184, 0.22);
}

.tf-table-header { background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%); }
.dark .tf-table-header { background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%); }

.tf-scrollbar::-webkit-scrollbar { width: 6px; }
.tf-scrollbar::-webkit-scrollbar-track { background: transparent; }
.tf-scrollbar::-webkit-scrollbar-thumb { background-color: rgba(148, 163, 184, 0.3); border-radius: 3px; }
.tf-scrollbar::-webkit-scrollbar-thumb:hover { background-color: rgba(148, 163, 184, 0.5); }

/* ── App Header ── */
.tf-app-header {
  height: 56px; background: #ffffff; color: #334155;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1rem; flex-shrink: 0; z-index: 50;
  border-bottom: 1px solid #e2e8f0;
}
.dark .tf-app-header { background: #0f172a; color: #cbd5e1; border-bottom-color: #1e293b; }

/* ── Sidebar ── */
.tf-sidebar {
  width: 56px;
  transition: width 280ms cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden; position: relative;
  background: #030d6a; border-right: none;
}
.tf-sidebar.is-expanded { width: 240px; overflow: visible; }
.dark .tf-sidebar { background: #0f172a; border-right: 1px solid #1e293b; }
.tf-sidebar-header {
  display: grid; grid-template-columns: 1fr; grid-template-rows: 1fr;
  align-items: center; justify-content: center; position: relative;
  height: 56px; padding: 0 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.dark .tf-sidebar-header { border-bottom-color: rgba(255, 255, 255, 0.06); }

.tf-sidebar-logo-icon, .tf-sidebar-logo-full {
  grid-area: 1 / 1; display: flex; transition: opacity 200ms ease 80ms;
}
.tf-sidebar-logo-icon { opacity: 1; }
.tf-sidebar-logo-full { opacity: 0; pointer-events: none; }
.tf-sidebar.is-expanded .tf-sidebar-logo-icon { opacity: 0; pointer-events: none; }
.tf-sidebar.is-expanded .tf-sidebar-logo-full { opacity: 1; pointer-events: auto; }

.tf-nav-link {
  justify-content: center; gap: 0;
  transition: gap 280ms cubic-bezier(0.4, 0, 0.2, 1), justify-content 280ms cubic-bezier(0.4, 0, 0.2, 1);
}
.tf-sidebar.is-expanded .tf-nav-link { justify-content: flex-start; gap: 0.75rem; }

.tf-sidebar-label {
  opacity: 0; max-width: 0; overflow: hidden; white-space: nowrap;
  transition: opacity 180ms ease, max-width 280ms cubic-bezier(0.4, 0, 0.2, 1);
}
.tf-sidebar.is-expanded .tf-sidebar-label { opacity: 1; max-width: 200px; }

.tf-submenu {
  max-height: 0; opacity: 0; overflow: hidden;
  transition: max-height 250ms cubic-bezier(0.4, 0, 0.2, 1), opacity 200ms ease;
}
.tf-submenu.is-open { max-height: 200px; opacity: 1; }

.tf-app-shell input, .tf-app-shell select, .tf-app-shell textarea {
  background: var(--bg-input) !important;
  color: var(--text-primary) !important;
  border-color: var(--border-color) !important;
}
.tf-app-shell input::placeholder, .tf-app-shell textarea::placeholder { color: var(--text-muted) !important; }
.tf-app-shell select option { background: #0f172a; color: #e5e7eb; }

@media (max-width: 767px) {
  .tf-sidebar {
    position: fixed !important; top: 0; left: 0; bottom: 0;
    width: 240px !important; transform: translateX(-100%);
    transition: transform 280ms cubic-bezier(0.4, 0, 0.2, 1) !important;
    z-index: 100; overflow: hidden !important;
  }
  .tf-sidebar.is-mobile-open { transform: translateX(0); overflow: visible !important; }
  .tf-sidebar.is-mobile-open .tf-sidebar-label { opacity: 1; max-width: 200px; }
  .tf-sidebar.is-mobile-open .tf-nav-link { justify-content: flex-start; gap: 0.75rem; }
  .tf-sidebar.is-mobile-open .tf-sidebar-logo-icon { opacity: 0; pointer-events: none; }
  .tf-sidebar.is-mobile-open .tf-sidebar-logo-full { opacity: 1; pointer-events: auto; }
}

#mobileBackdrop {
  display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5);
  z-index: 99; opacity: 0; transition: opacity 280ms ease;
}
#mobileBackdrop.is-visible { display: block; opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .tf-sidebar, .tf-sidebar-label, .tf-sidebar-logo-icon, .tf-sidebar-logo-full,
  .tf-submenu, .tf-nav-link, #mobileBackdrop { transition: none !important; }
}

/* ── Stat card / section / chip component system ── */
.tf-stat-card {
  position: relative; display: flex; flex-direction: column; gap: 0.125rem;
  padding: 1.125rem 1.25rem; background: #ffffff; border: 1px solid #e2e8f0;
  border-left: 3px solid #2563eb; border-radius: 0.625rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1), box-shadow 200ms cubic-bezier(0.4, 0, 0.2, 1), border-color 200ms ease;
}
.dark .tf-stat-card { background: #1e293b; border-color: #334155; }
.tf-stat-card:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(15, 23, 42, 0.07); }
.dark .tf-stat-card:hover { box-shadow: 0 6px 18px rgba(2, 6, 23, 0.5); }
.tf-stat-card--blue   { border-left-color: #2563eb; }
.tf-stat-card--orange { border-left-color: #f97316; }
.tf-stat-card--green  { border-left-color: #16a34a; }
.tf-stat-card--violet { border-left-color: #7c3aed; }
.tf-stat-card--cyan   { border-left-color: #0891b2; }
.tf-stat-card--red    { border-left-color: #dc2626; }
.tf-stat-card--slate  { border-left-color: #64748b; }

.tf-stat-card__label { font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: #64748b; }
.dark .tf-stat-card__label { color: #94a3b8; }
.tf-stat-card__value {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 800; font-size: 1.875rem; line-height: 1.05; letter-spacing: -0.02em;
  color: #0f172a; font-variant-numeric: tabular-nums; margin-top: 0.375rem;
}
.dark .tf-stat-card__value { color: #f1f5f9; }
.tf-stat-card__value--accent { color: #2563eb; }
.dark .tf-stat-card__value--accent { color: #60a5fa; }
.tf-stat-card__caption { font-size: 0.75rem; line-height: 1.4; color: #64748b; margin-top: 0.25rem; }
.dark .tf-stat-card__caption { color: #94a3b8; }
.tf-stat-card__trend { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.75rem; font-weight: 600; margin-top: 0.25rem; font-variant-numeric: tabular-nums; }
.tf-stat-card__trend--up   { color: #16a34a; }
.tf-stat-card__trend--down { color: #dc2626; }

.tf-section {
  background: #ffffff; border: 1px solid #e2e8f0; border-radius: 0.625rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04); overflow: hidden; transition: box-shadow 200ms ease;
}
.dark .tf-section { background: #1e293b; border-color: #334155; }
.tf-section:hover { box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06); }
.dark .tf-section:hover { box-shadow: 0 6px 18px rgba(2, 6, 23, 0.45); }
.tf-section__head {
  padding: 0.875rem 1.125rem; border-bottom: 1px solid #e2e8f0;
  background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 100%);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem;
}
.dark .tf-section__head { border-bottom-color: #334155; background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%); }
.tf-section__title { font-size: 0.9375rem; font-weight: 700; letter-spacing: -0.01em; color: #0f172a; line-height: 1.25; }
.dark .tf-section__title { color: #f1f5f9; }
.tf-section__sub { font-size: 0.75rem; line-height: 1.5; color: #64748b; margin-top: 0.1875rem; }
.dark .tf-section__sub { color: #94a3b8; }
.tf-section__eyebrow { display: inline-block; font-size: 0.625rem; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: #2563eb; margin-bottom: 0.4375rem; }
.dark .tf-section__eyebrow { color: #60a5fa; }
.tf-section__body { padding: 1.125rem 1.25rem; }
.tf-section__body--flush { padding: 0; }

.tf-chip {
  display: inline-flex; align-items: center; gap: 0.375rem; height: 1.75rem; padding: 0 0.6875rem;
  border-radius: 9999px; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.01em;
  background: #f1f5f9; color: #475569; border: 1px solid transparent;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease;
}
.dark .tf-chip { background: #1e293b; color: #cbd5e1; }
.tf-chip--active { background: #eff6ff; color: #2563eb; border-color: rgba(37, 99, 235, 0.25); }
.dark .tf-chip--active { background: rgba(96, 165, 250, 0.14); color: #93c5fd; border-color: rgba(96, 165, 250, 0.4); }
.tf-chip__count { font-variant-numeric: tabular-nums; font-size: 0.6875rem; padding: 0.0625rem 0.375rem; border-radius: 9999px; background: rgba(37, 99, 235, 0.12); color: inherit; }

@keyframes tf-fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.tf-stagger > * { animation: tf-fade-up 360ms cubic-bezier(0.4, 0, 0.2, 1) both; }
.tf-stagger > *:nth-child(1) { animation-delay: 0ms; }
.tf-stagger > *:nth-child(2) { animation-delay: 60ms; }
.tf-stagger > *:nth-child(3) { animation-delay: 120ms; }
.tf-stagger > *:nth-child(4) { animation-delay: 180ms; }
.tf-stagger > *:nth-child(5) { animation-delay: 240ms; }
.tf-stagger > *:nth-child(6) { animation-delay: 300ms; }
.tf-stagger > *:nth-child(7) { animation-delay: 360ms; }
.tf-stagger > *:nth-child(8) { animation-delay: 420ms; }
@media (prefers-reduced-motion: reduce) { .tf-stagger > * { animation: none; } }

/* ── Buttons / badges / tables (page-level components, new for this app) ── */
.tf-btn {
  display: inline-flex; align-items: center; gap: 0.375rem; font-size: 0.8125rem; font-weight: 600;
  padding: 0.5rem 0.875rem; border-radius: 0.5rem; border: 1px solid transparent;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease, opacity 160ms ease;
  cursor: pointer; line-height: 1.2;
}
.tf-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.tf-btn--primary { background: #2563eb; color: #fff; }
.tf-btn--primary:hover:not(:disabled) { background: #1d4ed8; }
.tf-btn--secondary { background: #f1f5f9; color: #334155; border-color: #e2e8f0; }
.dark .tf-btn--secondary { background: #1e293b; color: #cbd5e1; border-color: #334155; }
.tf-btn--secondary:hover:not(:disabled) { background: #e2e8f0; }
.dark .tf-btn--secondary:hover:not(:disabled) { background: #334155; }
.tf-btn--success { background: #16a34a; color: #fff; }
.tf-btn--success:hover:not(:disabled) { background: #15803d; }
.tf-btn--danger { background: #dc2626; color: #fff; }
.tf-btn--danger:hover:not(:disabled) { background: #b91c1c; }
.tf-btn--sm { padding: 0.3125rem 0.625rem; font-size: 0.75rem; }

.tf-badge {
  display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.6875rem; font-weight: 700;
  letter-spacing: 0.02em; padding: 0.1875rem 0.5625rem; border-radius: 9999px; text-transform: capitalize;
}
.tf-badge--slate  { background: #f1f5f9; color: #475569; }
.tf-badge--blue   { background: #eff6ff; color: #2563eb; }
.tf-badge--green  { background: #f0fdf4; color: #16a34a; }
.tf-badge--orange { background: #fff7ed; color: #ea580c; }
.tf-badge--red    { background: #fef2f2; color: #dc2626; }
.tf-badge--violet { background: #f5f3ff; color: #7c3aed; }
.dark .tf-badge--slate  { background: #1e293b; color: #94a3b8; }
.dark .tf-badge--blue   { background: rgba(96, 165, 250, 0.14); color: #93c5fd; }
.dark .tf-badge--green  { background: rgba(74, 222, 128, 0.14); color: #86efac; }
.dark .tf-badge--orange { background: rgba(251, 146, 60, 0.14); color: #fdba74; }
.dark .tf-badge--red    { background: rgba(248, 113, 113, 0.14); color: #fca5a5; }
.dark .tf-badge--violet { background: rgba(167, 139, 250, 0.14); color: #c4b5fd; }

.tf-table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.tf-table th {
  text-align: left; font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: #64748b; padding: 0.625rem 1rem; border-bottom: 1px solid #e2e8f0;
}
.dark .tf-table th { color: #94a3b8; border-bottom-color: #334155; }
.tf-table td { padding: 0.75rem 1rem; border-bottom: 1px solid #f1f5f9; color: #0f172a; }
.dark .tf-table td { border-bottom-color: #1e293b; color: #e2e8f0; }
.tf-table tbody tr:hover { background: #f8fafc; }
.dark .tf-table tbody tr:hover { background: rgba(255,255,255,0.02); }
.tf-table tbody tr:last-child td { border-bottom: none; }

.tf-field-label { display: block; font-size: 0.75rem; font-weight: 600; color: #475569; margin-bottom: 0.3125rem; }
.dark .tf-field-label { color: #94a3b8; }
.tf-input {
  width: 100%; padding: 0.5rem 0.75rem; font-size: 0.8125rem; border-radius: 0.5rem;
  border: 1px solid #e2e8f0; background: #fff; color: #0f172a;
}
.dark .tf-input { background: #0f172a; border-color: #334155; color: #f1f5f9; }
.tf-input:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
