:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-subtle: #64748b;
  --brand: #0f172a;
  --indigo-50: #eef2ff;
  --indigo-100: #e0e7ff;
  --indigo-500: #6366f1;
  --indigo-600: #4f46e5;
  --indigo-700: #4338ca;
  --accent: #4f46e5;
  --accent-bg: #eef2ff;
  --critical: #b91c1c;
  --critical-bg: #fef2f2;
  --high: #b45309;
  --high-bg: #fffbeb;
  --medium: #4338ca;
  --medium-bg: #eef2ff;
  --low: #475569;
  --low-bg: #f1f5f9;
  --success: #047857;
  --success-bg: #ecfdf5;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: ui-sans-serif, system-ui, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

.app-shell {
  display: flex;
  min-height: 100vh;
  background: var(--bg);
}

.sidebar {
  width: 244px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid rgba(203, 213, 225, 0.85);
  display: flex;
  flex-direction: column;
}

.brand-bar {
  height: 60px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
}

.brand-logo-wrap {
  border-radius: 6px;
  background: #ffffff;
  padding: 2px 6px;
  display: inline-flex;
  align-items: center;
}

.brand-logo-img {
  height: 28px;
  width: auto;
  max-width: 135px;
  object-fit: contain;
  display: block;
}

.brand-tag {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--indigo-600);
  background: var(--indigo-50);
  border: 1px solid var(--indigo-100);
  border-radius: 999px;
  padding: 1px 7px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.nav-group-title {
  margin-bottom: 6px;
  padding: 0 12px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 8px;
  color: #475569;
  font-weight: 500;
  font-size: 13px;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-link:hover {
  background: #f1f5f9;
  color: #0f172a;
  text-decoration: none;
}

.nav-link.active {
  background: #0f172a;
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}

.sidebar-footer {
  border-top: 1px solid #f1f5f9;
  padding: 14px 16px;
  font-size: 12px;
  color: var(--text-subtle);
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: #0f172a;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.main-area {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.topbar {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar-search {
  max-width: 380px;
  flex: 1;
}

.topbar-search input {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  font-size: 13px;
  width: 100%;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mobile-menu-btn {
  display: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 5px 9px;
  cursor: pointer;
}

.content {
  padding: 22px 24px 40px;
  max-width: 1380px;
  width: 100%;
}

.page-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.page-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text);
}

.flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13px;
  border: 1px solid transparent;
}
.flash-success { background: var(--success-bg); color: var(--success); border-color: #a7f3d0; }
.flash-error { background: var(--critical-bg); color: var(--critical); border-color: #fecaca; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid rgba(203, 213, 225, 0.85);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-subtle);
  font-weight: 600;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 4px;
  letter-spacing: -0.02em;
  color: var(--text);
}

.stat-note {
  font-size: 12px;
  color: var(--text-subtle);
  margin-top: 4px;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-subtle);
  font-weight: 600;
  background: var(--surface-muted);
}

tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-muted); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}

.badge-critical { background: #fee2e2; color: #991b1b; }
.badge-high, .badge-warning, .badge-pending_verification, .badge-pending_approval, .badge-queued, .badge-running, .badge-paused, .badge-onboarding { background: #fef3c7; color: #92400e; }
.badge-medium, .badge-active, .badge-linked_ready { background: #e0e7ff; color: #3730a3; }
.badge-low, .badge-informational, .badge-completed, .badge-on_hold { background: #f1f5f9; color: #334155; }
.badge-success, .badge-verified, .badge-approved, .badge-applied, .badge-retainer, .badge-synced { background: #d1fae5; color: #065f46; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: #1e293b;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.btn:hover { background: #f1f5f9; text-decoration: none; }
.btn-primary { background: #0f172a; border-color: #0f172a; color: #ffffff; }
.btn-primary:hover { background: #1e293b; color: #ffffff; }
.btn-danger { background: #dc2626; border-color: #dc2626; color: #ffffff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.form-grid { display: grid; gap: 12px; }
.form-row { display: flex; flex-direction: column; gap: 4px; }
label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }

input[type="text"], input[type="email"], input[type="password"], input[type="url"], input[type="number"], input[type="date"], input[type="search"], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--indigo-500);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

.inline-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 16px;
}

.empty-state {
  padding: 28px 18px;
  text-align: center;
  color: var(--text-subtle);
  background: var(--surface-muted);
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
}

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.muted { color: var(--text-subtle); }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #f8fafc;
}
.auth-box {
  width: 100%;
  max-width: 390px;
}
.auth-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid rgba(203, 213, 225, 0.85);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

/* Global Dark Mode matching Studio Nexa CRM (html.dark) */
html.dark { color-scheme: dark; }
html.dark body,
html.dark .app-shell,
html.dark .auth-wrap {
  background: #0b1120 !important;
  color: #e2e8f0 !important;
}
html.dark .sidebar,
html.dark .topbar,
html.dark .card,
html.dark .auth-card {
  background: #0f172a !important;
  border-color: #1e293b !important;
  color: #e2e8f0 !important;
}
html.dark .card-header,
html.dark .brand-bar,
html.dark .sidebar-footer,
html.dark th,
html.dark td {
  border-color: #1e293b !important;
}
html.dark th,
html.dark .empty-state {
  background: #162032 !important;
  color: #94a3b8 !important;
}
html.dark tbody tr:hover { background: #162032 !important; }
html.dark .page-title,
html.dark .card-title,
html.dark .stat-value,
html.dark strong { color: #f8fafc !important; }
html.dark .muted,
html.dark .stat-label,
html.dark .stat-note,
html.dark label { color: #94a3b8 !important; }
html.dark .nav-link { color: #cbd5e1 !important; }
html.dark .nav-link:hover { background: #1e293b !important; color: #ffffff !important; }
html.dark .nav-link.active { background: #4f46e5 !important; color: #ffffff !important; }
html.dark .btn {
  background: #1e293b !important;
  border-color: #334155 !important;
  color: #e2e8f0 !important;
}
html.dark .btn:hover { background: #334155 !important; }
html.dark .btn-primary {
  background: #6366f1 !important;
  border-color: #6366f1 !important;
  color: #ffffff !important;
}
html.dark .btn-primary:hover { background: #4f46e5 !important; }
html.dark input,
html.dark select,
html.dark textarea {
  background: #0b1120 !important;
  border-color: #334155 !important;
  color: #f8fafc !important;
}
html.dark a { color: #a5b4fc; }
html.dark .brand-tag { background: rgba(99, 102, 241, 0.2); border-color: rgba(99, 102, 241, 0.4); color: #a5b4fc; }

@media (max-width: 960px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu-btn { display: inline-flex; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .app-shell { display: block; }
  .content { padding: 0; max-width: 100%; }
  .card { border: 1px solid #cbd5e1; break-inside: avoid; box-shadow: none; }
}
