/* =========================================================================
   Envoy Work — Core Stylesheet
   Professional enterprise SaaS design system (vanilla CSS, no framework)
   ========================================================================= */

/* ---------------------------------------------------------------------- */
/* 1. Design tokens                                                       */
/* ---------------------------------------------------------------------- */
:root {
  /* Brand */
  --ev-brand-50:  #eef4ff;
  --ev-brand-100: #dbe7ff;
  --ev-brand-200: #b8d0ff;
  --ev-brand-300: #8ab0ff;
  --ev-brand-400: #5788ff;
  --ev-brand-500: #2f5eff;
  --ev-brand-600: #1e42e8;
  --ev-brand-700: #1832b8;
  --ev-brand-800: #172c8f;
  --ev-brand-900: #172a6e;

  /* Neutrals */
  --ev-gray-0:   #ffffff;
  --ev-gray-50:  #f7f8fa;
  --ev-gray-100: #eef0f4;
  --ev-gray-200: #dfe3ea;
  --ev-gray-300: #c7cdd9;
  --ev-gray-400: #a2aabb;
  --ev-gray-500: #7c8598;
  --ev-gray-600: #5c6579;
  --ev-gray-700: #444d61;
  --ev-gray-800: #2c3346;
  --ev-gray-900: #1a1f2e;
  --ev-gray-950: #11141d;

  /* Semantic */
  --ev-success-500: #17a673;
  --ev-success-600: #128a5f;
  --ev-success-bg:  #e5f8f1;
  --ev-warning-500: #e8a317;
  --ev-warning-600: #c98a0f;
  --ev-warning-bg:  #fdf3e1;
  --ev-danger-500:  #e0433a;
  --ev-danger-600:  #c22f27;
  --ev-danger-bg:   #fdeceb;
  --ev-info-500:    #2f7ff7;
  --ev-info-bg:     #eaf2ff;

  /* Surface tokens (light theme default) */
  --bg-app:        var(--ev-gray-50);
  --bg-surface:    var(--ev-gray-0);
  --bg-surface-2:  var(--ev-gray-100);
  --bg-sidebar:    #131a2e;
  --bg-topbar:     var(--ev-gray-0);
  --bg-hover:      var(--ev-gray-100);
  --bg-input:      var(--ev-gray-0);
  --bg-overlay:    rgba(17, 20, 29, 0.55);

  --text-primary:   var(--ev-gray-900);
  --text-secondary: var(--ev-gray-600);
  --text-muted:     var(--ev-gray-500);
  --text-inverse:   #ffffff;
  --text-sidebar:   #b7c0dd;
  --text-sidebar-active: #ffffff;

  --border-color:   var(--ev-gray-200);
  --border-strong:  var(--ev-gray-300);

  --brand: var(--ev-brand-500);
  --brand-strong: var(--ev-brand-600);
  --brand-soft: var(--ev-brand-50);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(17, 20, 29, 0.06), 0 1px 1px rgba(17, 20, 29, 0.04);
  --shadow-md: 0 4px 12px rgba(17, 20, 29, 0.08), 0 1px 3px rgba(17, 20, 29, 0.06);
  --shadow-lg: 0 12px 32px rgba(17, 20, 29, 0.14), 0 4px 8px rgba(17, 20, 29, 0.08);
  --shadow-focus: 0 0 0 3px rgba(47, 94, 255, 0.25);

  --sidebar-width: 264px;
  --sidebar-width-collapsed: 72px;
  --topbar-height: 60px;

  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur-fast: 120ms;
  --dur-med: 220ms;
  --dur-slow: 360ms;

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

/* Dark theme — via prefers-color-scheme or explicit [data-theme="dark"] */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-app:        var(--ev-gray-950);
    --bg-surface:    var(--ev-gray-900);
    --bg-surface-2:  var(--ev-gray-800);
    --bg-sidebar:    #0c1020;
    --bg-topbar:     var(--ev-gray-900);
    --bg-hover:      var(--ev-gray-800);
    --bg-input:      var(--ev-gray-800);
    --bg-overlay:    rgba(0, 0, 0, 0.65);

    --text-primary:   #f1f3f8;
    --text-secondary: var(--ev-gray-400);
    --text-muted:     var(--ev-gray-500);

    --border-color:   var(--ev-gray-800);
    --border-strong:  var(--ev-gray-700);

    --brand-soft: rgba(47, 94, 255, 0.14);

    --ev-success-bg: rgba(23, 166, 115, 0.15);
    --ev-warning-bg: rgba(232, 163, 23, 0.15);
    --ev-danger-bg: rgba(224, 67, 58, 0.16);
    --ev-info-bg: rgba(47, 127, 247, 0.16);
  }
}

[data-theme="dark"] {
  --bg-app:        var(--ev-gray-950);
  --bg-surface:    var(--ev-gray-900);
  --bg-surface-2:  var(--ev-gray-800);
  --bg-sidebar:    #0c1020;
  --bg-topbar:     var(--ev-gray-900);
  --bg-hover:      var(--ev-gray-800);
  --bg-input:      var(--ev-gray-800);
  --bg-overlay:    rgba(0, 0, 0, 0.65);

  --text-primary:   #f1f3f8;
  --text-secondary: var(--ev-gray-400);
  --text-muted:     var(--ev-gray-500);

  --border-color:   var(--ev-gray-800);
  --border-strong:  var(--ev-gray-700);

  --brand-soft: rgba(47, 94, 255, 0.14);

  --ev-success-bg: rgba(23, 166, 115, 0.15);
  --ev-warning-bg: rgba(232, 163, 23, 0.15);
  --ev-danger-bg: rgba(224, 67, 58, 0.16);
  --ev-info-bg: rgba(47, 127, 247, 0.16);
}

/* ---------------------------------------------------------------------- */
/* 2. Reset & base                                                        */
/* ---------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  transition: background var(--dur-med) var(--ease), color var(--dur-med) var(--ease);
}
h1, h2, h3, h4, h5, h6 { margin: 0 0 .5em; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p { margin: 0 0 1em; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
ul, ol { margin: 0; padding: 0; list-style: none; }
button { font-family: inherit; }
img, svg { display: block; max-width: 100%; }
code, pre { font-family: var(--font-mono); }
::selection { background: var(--ev-brand-200); color: var(--ev-brand-900); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-pill); border: 2px solid var(--bg-app); }
::-webkit-scrollbar-thumb:hover { background: var(--ev-gray-400); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ---------------------------------------------------------------------- */
/* 3. App shell layout                                                    */
/* ---------------------------------------------------------------------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--topbar-height) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  height: 100vh;
  transition: grid-template-columns var(--dur-med) var(--ease);
}
.app-shell.sidebar-collapsed {
  grid-template-columns: var(--sidebar-width-collapsed) 1fr;
}

/* --- Sidebar --- */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid rgba(255,255,255,0.06);
  transition: width var(--dur-med) var(--ease);
  z-index: 30;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-height);
  padding: 0 18px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar-brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--ev-brand-400), var(--ev-brand-700));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px; flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.sidebar-brand-name {
  font-weight: 700; color: #fff; font-size: 15px; white-space: nowrap;
  overflow: hidden; opacity: 1; transition: opacity var(--dur-fast) var(--ease);
}
.app-shell.sidebar-collapsed .sidebar-brand-name,
.app-shell.sidebar-collapsed .nav-section-label,
.app-shell.sidebar-collapsed .nav-link-label,
.app-shell.sidebar-collapsed .sidebar-footer-text { opacity: 0; pointer-events: none; width: 0; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 10px;
}
.nav-section { margin-bottom: 18px; }
.nav-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(183,192,221,0.55);
  padding: 0 10px 6px;
  white-space: nowrap;
  transition: opacity var(--dur-fast) var(--ease);
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-sidebar);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  margin-bottom: 2px;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; text-decoration: none; }
.nav-link.active {
  background: linear-gradient(90deg, rgba(47,94,255,0.35), rgba(47,94,255,0.08));
  color: var(--text-sidebar-active);
  box-shadow: inset 3px 0 0 var(--ev-brand-400);
}
.nav-link-icon { width: 18px; height: 18px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.nav-link-icon svg { width: 18px; height: 18px; }
.nav-link-label { overflow: hidden; transition: opacity var(--dur-fast) var(--ease); }
.nav-link-badge {
  margin-left: auto; font-size: 11px; font-weight: 700;
  background: var(--ev-brand-500); color: #fff;
  border-radius: var(--radius-pill); padding: 1px 7px;
}

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.sidebar-footer-text { font-size: 11px; color: rgba(183,192,221,0.6); white-space: nowrap; }
.sidebar-toggle {
  background: rgba(255,255,255,0.06);
  border: none; color: #fff; width: 30px; height: 30px;
  border-radius: var(--radius-sm); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  margin-left: auto; flex-shrink: 0;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-med) var(--ease);
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.14); }
.app-shell.sidebar-collapsed .sidebar-toggle { margin-left: 0; }
.app-shell.sidebar-collapsed .sidebar-toggle svg { transform: rotate(180deg); }

/* --- Topbar --- */
.topbar {
  grid-area: topbar;
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 14px;
  z-index: 20;
}
.hamburger {
  display: none;
  background: transparent; border: none; cursor: pointer;
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  color: var(--text-primary); align-items: center; justify-content: center;
}
.hamburger:hover { background: var(--bg-hover); }

.topbar-title { font-weight: 600; font-size: 16px; margin-right: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.tenant-selector {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: var(--radius-md);
  border: 1px solid var(--border-color); background: var(--bg-surface-2);
  cursor: pointer; font-size: 13px; font-weight: 500;
  transition: border-color var(--dur-fast) var(--ease);
  max-width: 220px;
}
.tenant-selector:hover { border-color: var(--border-strong); }
.tenant-selector .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); flex-shrink: 0; }
.tenant-selector span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
  position: relative;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn .dot-badge {
  position: absolute; top: 6px; right: 6px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ev-danger-500); border: 2px solid var(--bg-topbar);
}

.user-menu { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 4px 8px 4px 4px; border-radius: var(--radius-md); }
.user-menu:hover { background: var(--bg-hover); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--ev-brand-400), var(--ev-brand-600));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.user-menu-info { line-height: 1.25; display: none; }
.user-menu-name { font-size: 13px; font-weight: 600; }
.user-menu-role { font-size: 11.5px; color: var(--text-muted); }
@media (min-width: 900px) { .user-menu-info { display: block; } }

/* --- Main content --- */
.main-content {
  grid-area: main;
  overflow-y: auto;
  padding: 24px 28px 60px;
  background: var(--bg-app);
}
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 22px; flex-wrap: wrap;
}
.page-header h1 { margin: 0 0 4px; }
.page-subtitle { color: var(--text-secondary); font-size: 13.5px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.content-grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------------- */
/* 4. Cards                                                               */
/* ---------------------------------------------------------------------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-clickable { cursor: pointer; }
.card-clickable:hover { transform: translateY(-1px); }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border-color);
  gap: 10px;
}
.card-header h3 { margin: 0; }
.card-body { padding: 18px; }
.card-body.no-pad { padding: 0; }
.card-footer {
  padding: 12px 18px; border-top: 1px solid var(--border-color);
  display: flex; gap: 8px; justify-content: flex-end;
}

/* Metric card */
.metric-card { padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.metric-card-top { display: flex; align-items: center; justify-content: space-between; }
.metric-icon {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: var(--brand-soft); color: var(--brand);
  display: flex; align-items: center; justify-content: center;
}
.metric-icon svg { width: 18px; height: 18px; }
.metric-label { font-size: 12.5px; color: var(--text-secondary); font-weight: 500; }
.metric-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.metric-trend { font-size: 12.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.metric-trend.up { color: var(--ev-success-600); }
.metric-trend.down { color: var(--ev-danger-600); }
.metric-trend.flat { color: var(--text-muted); }

/* Empty / loading */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 48px 20px; color: var(--text-secondary); gap: 6px;
}
.empty-state svg { width: 44px; height: 44px; color: var(--text-muted); margin-bottom: 8px; }
.empty-state-title { font-weight: 600; color: var(--text-primary); font-size: 14.5px; }

.skeleton {
  background: linear-gradient(90deg, var(--bg-surface-2) 25%, var(--bg-hover) 37%, var(--bg-surface-2) 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.skeleton-row { height: 14px; margin-bottom: 10px; }
.skeleton-block { height: 90px; }

/* ---------------------------------------------------------------------- */
/* 5. Buttons                                                             */
/* ---------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 16px; font-size: 13.5px; font-weight: 600;
  border-radius: var(--radius-md); border: 1px solid transparent;
  cursor: pointer; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: var(--brand-strong); }
.btn-secondary { background: var(--bg-surface-2); color: var(--text-primary); border-color: var(--border-color); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--border-strong); }
.btn-danger { background: var(--ev-danger-500); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--ev-danger-600); }
.btn-success { background: var(--ev-success-500); color: #fff; }
.btn-success:hover:not(:disabled) { background: var(--ev-success-600); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-lg { padding: 11px 20px; font-size: 14.5px; }
.btn-icon { padding: 8px; }
.btn-block { width: 100%; }

/* ---------------------------------------------------------------------- */
/* 6. Forms                                                               */
/* ---------------------------------------------------------------------- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-primary); }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 5px; }
.form-row { display: flex; gap: 14px; }
.form-row > * { flex: 1; }

.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: var(--shadow-focus);
}
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.textarea { resize: vertical; min-height: 90px; }
.select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%237c8598'/></svg>"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 30px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.checkbox-row input { width: 16px; height: 16px; accent-color: var(--brand); }

.search-input-wrap { position: relative; }
.search-input-wrap svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-muted); }
.search-input-wrap .input { padding-left: 34px; }

/* ---------------------------------------------------------------------- */
/* 7. Tables                                                              */
/* ---------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table thead th {
  text-align: left; font-weight: 600; color: var(--text-secondary);
  font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  padding: 11px 16px; background: var(--bg-surface-2);
  border-bottom: 1px solid var(--border-color); white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
.data-table thead th.sortable { cursor: pointer; user-select: none; }
.data-table thead th.sortable:hover { color: var(--text-primary); }
.data-table thead th .sort-arrow { margin-left: 4px; font-size: 10px; opacity: .6; }
.data-table tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border-color); vertical-align: middle; }
.data-table tbody tr { transition: background var(--dur-fast) var(--ease); }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr.clickable { cursor: pointer; }
.table-cell-muted { color: var(--text-muted); }
.table-cell-mono { font-family: var(--font-mono); font-size: 12.5px; }

.pagination { display: flex; align-items: center; gap: 6px; justify-content: flex-end; padding: 12px 16px; }
.pagination-info { margin-right: auto; font-size: 12.5px; color: var(--text-muted); }
.page-btn {
  min-width: 30px; height: 30px; padding: 0 8px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-color);
  background: var(--bg-surface); color: var(--text-secondary);
  cursor: pointer; font-size: 12.5px; font-weight: 600;
  transition: all var(--dur-fast) var(--ease);
}
.page-btn:hover:not(:disabled) { background: var(--bg-hover); }
.page-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------------------------------------------------------------------- */
/* 8. Badges & status                                                     */
/* ---------------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: var(--radius-pill);
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  line-height: 1.6; white-space: nowrap;
}
.badge-neutral { background: var(--bg-surface-2); color: var(--text-secondary); }
.badge-brand { background: var(--brand-soft); color: var(--brand-strong); }
.badge-success { background: var(--ev-success-bg); color: var(--ev-success-600); }
.badge-warning { background: var(--ev-warning-bg); color: var(--ev-warning-600); }
.badge-danger { background: var(--ev-danger-bg); color: var(--ev-danger-600); }
.badge-info { background: var(--ev-info-bg); color: var(--ev-info-500); }
.badge-dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.status-indicator { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 500; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 0 3px transparent; }
.status-dot.status-active, .status-dot.status-running, .status-dot.status-ok { background: var(--ev-success-500); }
.status-dot.status-pending, .status-dot.status-in_progress, .status-dot.status-due_soon { background: var(--ev-warning-500); }
.status-dot.status-failed, .status-dot.status-error, .status-dot.status-overdue, .status-dot.status-rejected { background: var(--ev-danger-500); }
.status-dot.status-inactive, .status-dot.status-draft, .status-dot.status-archived { background: var(--ev-gray-400); }
.status-dot.pulse { animation: status-pulse 1.6s ease infinite; }
@keyframes status-pulse { 0% { box-shadow: 0 0 0 0 rgba(23,166,115,0.35); } 70% { box-shadow: 0 0 0 6px rgba(23,166,115,0); } 100% { box-shadow: 0 0 0 0 rgba(23,166,115,0); } }

/* SLA indicators */
.sla-indicator { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; padding: 3px 9px; border-radius: var(--radius-pill); }
.sla-overdue { background: var(--ev-danger-bg); color: var(--ev-danger-600); }
.sla-due_soon { background: var(--ev-warning-bg); color: var(--ev-warning-600); }
.sla-ok { background: var(--ev-success-bg); color: var(--ev-success-600); }
.sla-indicator svg { width: 13px; height: 13px; }

/* Confidence bar */
.confidence-bar-wrap { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.confidence-bar-track { flex: 1; height: 6px; border-radius: var(--radius-pill); background: var(--bg-surface-2); overflow: hidden; }
.confidence-bar-fill { height: 100%; border-radius: var(--radius-pill); transition: width var(--dur-slow) var(--ease); }
.confidence-bar-fill.low { background: var(--ev-danger-500); }
.confidence-bar-fill.mid { background: var(--ev-warning-500); }
.confidence-bar-fill.high { background: var(--ev-success-500); }
.confidence-bar-label { font-size: 12px; font-weight: 700; min-width: 32px; text-align: right; }

/* Progress bar */
.progress-bar-track { width: 100%; height: 8px; border-radius: var(--radius-pill); background: var(--bg-surface-2); overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--brand); border-radius: var(--radius-pill); transition: width var(--dur-slow) var(--ease); }

/* ---------------------------------------------------------------------- */
/* 9. Tabs                                                                */
/* ---------------------------------------------------------------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border-color); margin-bottom: 18px; overflow-x: auto; }
.tab-btn {
  padding: 10px 16px; font-size: 13.5px; font-weight: 600; color: var(--text-secondary);
  background: transparent; border: none; cursor: pointer; position: relative; white-space: nowrap;
  transition: color var(--dur-fast) var(--ease);
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--brand); }
.tab-btn.active::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: var(--brand); border-radius: var(--radius-pill);
}

/* ---------------------------------------------------------------------- */
/* 10. Modals                                                             */
/* ---------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: var(--bg-overlay);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
  animation: fade-in var(--dur-fast) var(--ease);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 560px;
  max-height: 88vh; display: flex; flex-direction: column; overflow: hidden;
  animation: modal-in var(--dur-med) var(--ease);
}
.modal.modal-lg { max-width: 800px; }
.modal.modal-sm { max-width: 400px; }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border-color); }
.modal-header h3 { margin: 0; }
.modal-close { background: transparent; border: none; cursor: pointer; color: var(--text-muted); width: 30px; height: 30px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; }
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border-color); display: flex; gap: 8px; justify-content: flex-end; }

/* ---------------------------------------------------------------------- */
/* 11. Dropdowns                                                          */
/* ---------------------------------------------------------------------- */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; top: calc(100% + 6px); right: 0; min-width: 200px;
  background: var(--bg-surface); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  z-index: 50; padding: 6px; display: none;
  animation: dropdown-in var(--dur-fast) var(--ease);
}
.dropdown-menu.open { display: block; }
@keyframes dropdown-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.dropdown-menu.align-left { right: auto; left: 0; }
.dropdown-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px;
  border-radius: var(--radius-sm); font-size: 13px; cursor: pointer; color: var(--text-primary);
}
.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-item svg { width: 15px; height: 15px; color: var(--text-secondary); }
.dropdown-item.danger { color: var(--ev-danger-500); }
.dropdown-divider { height: 1px; background: var(--border-color); margin: 6px 4px; }
.dropdown-label { font-size: 11px; text-transform: uppercase; color: var(--text-muted); padding: 6px 10px 2px; letter-spacing: .05em; }

/* ---------------------------------------------------------------------- */
/* 12. Toasts                                                             */
/* ---------------------------------------------------------------------- */
.toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px; max-width: 360px;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--bg-surface); border: 1px solid var(--border-color);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  padding: 13px 14px; font-size: 13px; color: var(--text-primary);
  animation: toast-in var(--dur-med) var(--ease);
}
.toast.toast-leaving { animation: toast-out var(--dur-fast) var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(20px); } }
.toast-success { border-left-color: var(--ev-success-500); }
.toast-warning { border-left-color: var(--ev-warning-500); }
.toast-error { border-left-color: var(--ev-danger-500); }
.toast-icon { flex-shrink: 0; width: 18px; height: 18px; margin-top: 1px; }
.toast-icon svg { width: 18px; height: 18px; }
.toast.toast-success .toast-icon { color: var(--ev-success-500); }
.toast.toast-warning .toast-icon { color: var(--ev-warning-500); }
.toast.toast-error .toast-icon { color: var(--ev-danger-500); }
.toast.toast-info .toast-icon { color: var(--brand); }
.toast-content { flex: 1; }
.toast-title { font-weight: 700; margin-bottom: 2px; }
.toast-close { background: transparent; border: none; color: var(--text-muted); cursor: pointer; flex-shrink: 0; }

/* ---------------------------------------------------------------------- */
/* 13. Timeline                                                           */
/* ---------------------------------------------------------------------- */
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ''; position: absolute; left: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--border-color); }
.timeline-item { position: relative; padding-bottom: 20px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot {
  position: absolute; left: -26px; top: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--bg-surface); border: 3px solid var(--brand); z-index: 1;
}
.timeline-dot.success { border-color: var(--ev-success-500); }
.timeline-dot.warning { border-color: var(--ev-warning-500); }
.timeline-dot.danger { border-color: var(--ev-danger-500); }
.timeline-time { font-size: 11.5px; color: var(--text-muted); margin-bottom: 2px; }
.timeline-title { font-weight: 600; font-size: 13.5px; }
.timeline-desc { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }

/* ---------------------------------------------------------------------- */
/* 14. Step graph (method visualization)                                  */
/* ---------------------------------------------------------------------- */
.step-graph { display: flex; flex-direction: column; gap: 0; }
.step-node {
  display: flex; align-items: flex-start; gap: 14px; position: relative; padding-bottom: 22px;
}
.step-node:last-child { padding-bottom: 0; }
.step-node::before {
  content: ''; position: absolute; left: 17px; top: 36px; bottom: 0; width: 2px;
  background: var(--border-color);
}
.step-node:last-child::before { display: none; }
.step-node-index {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: var(--brand-soft); color: var(--brand-strong);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13.5px;
  border: 2px solid var(--bg-surface); box-shadow: 0 0 0 1px var(--border-color);
  z-index: 1;
}
.step-node.done .step-node-index { background: var(--ev-success-bg); color: var(--ev-success-600); }
.step-node.failed .step-node-index { background: var(--ev-danger-bg); color: var(--ev-danger-600); }
.step-node-body { flex: 1; background: var(--bg-surface-2); border-radius: var(--radius-md); padding: 12px 14px; border: 1px solid var(--border-color); }
.step-node-title { font-weight: 600; font-size: 13.5px; margin-bottom: 3px; }
.step-node-meta { font-size: 12px; color: var(--text-muted); display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------------------------------------------------------------------- */
/* 15. JSON schema viewer                                                 */
/* ---------------------------------------------------------------------- */
.schema-viewer { font-family: var(--font-mono); font-size: 12.5px; background: var(--bg-surface-2); border-radius: var(--radius-md); border: 1px solid var(--border-color); padding: 12px 14px; overflow-x: auto; }
.schema-key { color: var(--ev-brand-600); font-weight: 600; }
.schema-type { color: var(--ev-success-600); }
.schema-required::after { content: '*'; color: var(--ev-danger-500); margin-left: 2px; }
.schema-node { padding-left: 16px; border-left: 1px dashed var(--border-strong); margin-left: 4px; }
.schema-desc { color: var(--text-muted); font-family: var(--font-sans); font-size: 12px; margin-left: 6px; }

/* ---------------------------------------------------------------------- */
/* 16. Login / tenant picker                                              */
/* ---------------------------------------------------------------------- */
.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 20%, var(--ev-brand-900) 0%, var(--ev-gray-950) 55%);
  padding: 20px;
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--bg-surface);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 32px;
}
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; justify-content: center; }
.auth-logo .sidebar-brand-mark { width: 40px; height: 40px; font-size: 17px; }
.auth-title { text-align: center; font-size: 20px; margin-bottom: 4px; }
.auth-subtitle { text-align: center; color: var(--text-secondary); font-size: 13.5px; margin-bottom: 24px; }
.tenant-list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.tenant-option {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border: 1px solid var(--border-color); border-radius: var(--radius-md);
  cursor: pointer; transition: all var(--dur-fast) var(--ease);
}
.tenant-option:hover { border-color: var(--brand); background: var(--brand-soft); }

/* ---------------------------------------------------------------------- */
/* 17. Misc utilities                                                     */
/* ---------------------------------------------------------------------- */
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--ev-success-600); }
.text-danger { color: var(--ev-danger-600); }
.text-warning { color: var(--ev-warning-600); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
.w-full { width: 100%; }
.divider { height: 1px; background: var(--border-color); margin: 16px 0; }
.spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border-color); border-top-color: var(--brand);
  animation: spin .7s linear infinite;
}

.loading-overlay {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 300;
  background: transparent; overflow: hidden; opacity: 0; transition: opacity var(--dur-fast) var(--ease);
}
.loading-overlay.active { opacity: 1; }
.loading-overlay-bar {
  position: absolute; height: 100%; width: 40%;
  background: linear-gradient(90deg, var(--ev-brand-400), var(--ev-brand-600));
  animation: loading-bar 1.1s ease-in-out infinite;
}
@keyframes loading-bar { 0% { left: -40%; } 100% { left: 100%; } }

/* ---------------------------------------------------------------------- */
/* 18. Responsive                                                        */
/* ---------------------------------------------------------------------- */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas: "topbar" "main";
  }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-width);
    transform: translateX(-100%); box-shadow: var(--shadow-lg);
  }
  .app-shell.sidebar-open .sidebar { transform: translateX(0); }
  .app-shell.sidebar-open::after {
    content: ''; position: fixed; inset: 0; background: var(--bg-overlay); z-index: 25;
  }
  .app-shell.sidebar-collapsed .sidebar { width: var(--sidebar-width); }
  .app-shell.sidebar-collapsed .nav-link-label,
  .app-shell.sidebar-collapsed .sidebar-brand-name,
  .app-shell.sidebar-collapsed .nav-section-label { opacity: 1; pointer-events: auto; width: auto; }
  .hamburger { display: flex; }
  .main-content { padding: 18px 16px 50px; }
  .tenant-selector span { display: none; }
}
