@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #F1F5F9;
  --surface: #FFFFFF;
  --surface2: #F8FAFC;
  --border: #E2E8F0;
  --border-hover: #CBD5E1;
  --accent: #2563EB;
  --accent-hover: #1D4ED8;
  --accent2: #D97706;
  --accent3: #059669;
  --accent4: #DC2626;
  --text: #0F172A;
  --muted: #64748B;
  --sidebar-w: 240px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.06), 0 1px 3px rgba(15,23,42,0.08);
  --shadow: 0 1px 3px rgba(15,23,42,0.06), 0 4px 8px rgba(15,23,42,0.06);
  --shadow-md: 0 4px 6px rgba(15,23,42,0.07), 0 10px 15px rgba(15,23,42,0.07);
}

html[data-theme="light"] { color-scheme: light; }

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0F172A;
  --surface: #172033;
  --surface2: #202B3F;
  --border: #334155;
  --border-hover: #475569;
  --accent: #60A5FA;
  --accent-hover: #3B82F6;
  --accent2: #F59E0B;
  --accent3: #34D399;
  --accent4: #F87171;
  --text: #E5E7EB;
  --muted: #94A3B8;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.28), 0 1px 3px rgba(0,0,0,0.34);
  --shadow: 0 1px 3px rgba(0,0,0,0.28), 0 4px 8px rgba(0,0,0,0.32);
  --shadow-md: 0 10px 30px rgba(0,0,0,0.42);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 100;
  transition: width 0.2s ease;
  overflow: hidden;
}

.sidebar-logo {
  padding: 16px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  min-width: 0;
}

.sidebar-brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  object-fit: contain;
  border: 1px solid var(--border);
  background: #fff;
  padding: 3px;
  flex-shrink: 0;
}

.sidebar-logo-text {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

.sidebar-logo h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.sidebar-logo p {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 2px;
  font-weight: 500;
  white-space: nowrap;
}

.sidebar-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.12s;
  line-height: 1;
  padding: 0;
}
.sidebar-toggle:hover { color: var(--text); background: var(--surface2); border-color: var(--border-hover); }

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-label {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 16px 4px;
  font-weight: 600;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.12s;
  border-left: 3px solid transparent;
  text-decoration: none;
  border-radius: 0;
  margin: 1px 0;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface2);
  text-decoration: none;
}

.nav-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: #EFF6FF;
  font-weight: 600;
}

.nav-link .icon {
  font-size: 0;
  width: 18px;
  height: 18px;
  text-align: center;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}
.nav-link .icon::before {
  content: '';
  width: 16px;
  height: 16px;
  display: block;
  flex-shrink: 0;
  background: currentColor;
  -webkit-mask: var(--sidebar-fallback-icon) center / 16px 16px no-repeat;
  mask: var(--sidebar-fallback-icon) center / 16px 16px no-repeat;
}
.nav-link .icon:has(.menu-svg)::before { display: none; }
.menu-svg { width: 16px; height: 16px; display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav-link .nav-text { white-space: nowrap; overflow: hidden; }

:root {
  --sidebar-fallback-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 6h16M4 12h16M4 18h16' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
  flex-shrink: 0;
  overflow: hidden;
  white-space: nowrap;
}

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

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.user-info .name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-info .role-badge {
  font-size: 11px;
  color: var(--muted);
  text-transform: capitalize;
  font-weight: 500;
}

.logout-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  margin-top: 8px;
  padding: 0;
  font-family: inherit;
  transition: color 0.12s;
  font-weight: 500;
}
.logout-btn:hover { color: var(--accent4); }

/* ── Sidebar collapsed state ─────────────────────────────────────────── */
.sidebar.collapsed {
  width: 52px;
}

.sidebar.collapsed .sidebar-logo-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .user-info,
.sidebar.collapsed .logout-btn {
  display: none;
}

.sidebar.collapsed .sidebar-brand-logo {
  width: 30px;
  height: 30px;
  border-radius: 6px;
}

.sidebar.collapsed .sidebar-logo {
  justify-content: center;
  padding: 14px 0;
}

.sidebar.collapsed .nav-link {
  justify-content: center;
  padding: 9px 0;
  border-left-color: transparent;
}

.sidebar.collapsed .nav-link.active {
  border-left-color: var(--accent);
}

.sidebar.collapsed .sidebar-footer {
  padding: 12px 0;
  display: flex;
  justify-content: center;
}

.sidebar.collapsed .user-chip {
  justify-content: center;
}

/* ── Main Content ────────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.2s ease;
  overflow-x: hidden;
  min-width: 0;
}

body.sidebar-collapsed .main {
  margin-left: 52px;
}

.topbar {
  height: 56px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 12px;
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar h1 {
  font-size: 16px;
  font-weight: 700;
  flex: 1;
  color: var(--text);
  letter-spacing: -0.01em;
}

.page-content {
  padding: 28px;
  flex: 1;
}

/* ── Cards ───────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 12px;
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* ── Stats Row ───────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

.stat-num {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  font-weight: 500;
}

/* ── Table ───────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead {
  background: var(--surface2);
}

.data-table th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.data-table td {
  padding: 11px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #F8FAFC; }

/* ── Badges ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-digits   { background: #EFF6FF; color: #2563EB; border: 1px solid #BFDBFE; }
.badge-customer { background: #FFFBEB; color: #B45309; border: 1px solid #FDE68A; }
.badge-partner  { background: #ECFDF5; color: #065F46; border: 1px solid #A7F3D0; }
.badge-erp      { background: #F5F3FF; color: #5B21B6; border: 1px solid #DDD6FE; }

.badge-active    { background: #ECFDF5; color: #065F46; border: 1px solid #A7F3D0; }
.badge-completed { background: #EFF6FF; color: #1D4ED8; border: 1px solid #BFDBFE; }
.badge-hold      { background: #FFFBEB; color: #92400E; border: 1px solid #FDE68A; }
.badge-inactive  { background: #F1F5F9; color: #64748B; border: 1px solid #CBD5E1; }

.badge-impl   { background: #EFF6FF; color: #1D4ED8; border: 1px solid #BFDBFE; }
.badge-slr    { background: #FFFBEB; color: #92400E; border: 1px solid #FDE68A; }
.badge-integ  { background: #ECFDF5; color: #065F46; border: 1px solid #A7F3D0; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 7px;
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  border: none;
  transition: all 0.12s;
  font-weight: 500;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 2px rgba(37,99,235,0.3);
}
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 2px 4px rgba(37,99,235,0.35); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}
.btn-ghost:hover { border-color: var(--border-hover); color: var(--text); background: var(--surface2); }

.btn-danger {
  background: transparent;
  border: 1px solid #FECACA;
  color: var(--accent4);
}
.btn-danger:hover { background: #FEF2F2; border-color: var(--accent4); }

.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ── Forms ───────────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-grid.cols-1 { grid-template-columns: 1fr; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field.span-2 { grid-column: span 2; }

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0;
}

.logo-upload-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
}

.logo-preview {
  width: 58px;
  height: 58px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

.logo-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 5px;
}

.logo-upload-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.entity-name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.entity-logo-thumb {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
}

.entity-logo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 3px;
}

.branding-panel {
  max-width: 680px;
}

.branding-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  margin-bottom: 18px;
}

.branding-preview-logo {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.branding-preview-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 6px;
}

.field input,
.field select,
.field textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.08);
}

.field input::placeholder,
.field textarea::placeholder { color: #94A3B8; }

.field textarea { min-height: 80px; resize: vertical; }

.field select option { background: var(--surface); }

/* ── Modal ───────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.12s;
}
.modal-close:hover { color: var(--text); background: var(--surface2); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── Login Page ──────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo h1 {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.login-logo p {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
  font-weight: 400;
}

.login-form { display: flex; flex-direction: column; gap: 14px; }

.error-msg {
  background: #FEF2F2;
  border: 1px solid #FECACA;
  color: var(--accent4);
  border-radius: 7px;
  padding: 10px 14px;
  font-size: 13px;
  display: none;
}

.error-msg.show { display: block; }

/* ── Toast ───────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--text);
  border-radius: 8px;
  padding: 11px 16px;
  font-size: 13px;
  color: #fff;
  font-weight: 500;
  z-index: 999;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s;
  pointer-events: none;
  box-shadow: var(--shadow-md);
}

#toast.show { opacity: 1; transform: translateY(0); }
#toast.success { background: #064E3B; }
#toast.error   { background: #7F1D1D; }

/* ── Empty State ─────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
  font-size: 13px;
}

.empty-icon { font-size: 2.5rem; margin-bottom: 12px; }

/* ── Filters row ─────────────────────────────────────────────────────── */
.filters-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.filters-row select,
.filters-row input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  padding: 7px 11px;
  outline: none;
  transition: border-color 0.15s;
  min-width: 140px;
}
.filters-row select:focus,
.filters-row input:focus { border-color: var(--accent); }

/* ── Invite link box ─────────────────────────────────────────────────── */
.invite-result {
  margin-top: 14px;
  padding: 12px 14px;
  background: #ECFDF5;
  border: 1px solid #A7F3D0;
  border-radius: 8px;
}
.invite-result .invite-label {
  font-size: 11px;
  color: #065F46;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 5px;
}
.invite-result .invite-link {
  font-size: 12px;
  word-break: break-all;
  color: #065F46;
}

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .page-content { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: span 1; }
  .topbar { padding: 0 16px; }
}

/* ── Misc utilities ──────────────────────────────────────────────────── */
.text-muted    { color: var(--muted); }
.text-accent   { color: var(--accent); }
.flex          { display: flex; }
.gap-2         { gap: 8px; }
.items-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-4          { margin-top: 16px; }
.mb-4          { margin-bottom: 16px; }
.grid-2        { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.fw-500        { font-weight: 500; }
.fw-600        { font-weight: 600; }

.loading {
  text-align: center;
  padding: 32px;
  color: var(--muted);
  font-size: 13px;
}

.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Section divider ─────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

/* ── Action icon buttons ─────────────────────────────────────────────── */
.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 8px;
  font-family: inherit;
  transition: all 0.12s;
  font-weight: 500;
}
.icon-btn:hover { border-color: var(--border-hover); color: var(--text); background: var(--surface2); }
.icon-btn.danger { color: var(--accent4); border-color: #FECACA; }
.icon-btn.danger:hover { background: #FEF2F2; }

/* ── DevExtreme overrides ─────────────────────────────────────────────── */

/* Apply Inter to text-bearing DX elements ONLY — never override .dx-icon
   which uses the embedded 'DXIcons' icon font. */
.dx-widget { font-family: 'Inter', -apple-system, sans-serif; }

.dx-texteditor-input,
.dx-placeholder::before,
.dx-list-item-content,
.dx-datagrid td,
.dx-datagrid th,
.dx-toolbar-label,
.dx-toolbar-item-content,
.dx-pager,
.dx-popup-title .dx-toolbar-label,
.dx-overlay-content,
.dx-button-text,
.dx-checkbox-text,
.dx-tag-content {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
}

/* DataGrid */
.dx-datagrid {
  background: transparent;
  color: var(--text);
  font-size: 13px;
}

.dx-datagrid-headers .dx-datagrid-table .dx-row > td {
  background: #F8FAFC;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
}

.dx-datagrid-rowsview .dx-row > td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

.dx-datagrid-rowsview .dx-row:last-child > td { border-bottom: none; }
.dx-datagrid-rowsview .dx-row:hover > td { background: #F8FAFC !important; }
.dx-datagrid-rowsview .dx-selection.dx-row > td,
.dx-datagrid-rowsview .dx-selection.dx-row:hover > td {
  background: #EFF6FF !important;
  color: var(--text);
}

.dx-datagrid-borders > .dx-datagrid-headers,
.dx-datagrid-borders > .dx-datagrid-rowsview,
.dx-datagrid-borders > .dx-datagrid-total-footer {
  border-left: none;
  border-right: none;
}

.dx-datagrid-borders > .dx-datagrid-headers { border-top: none; }
.dx-datagrid-borders > .dx-datagrid-total-footer { border-bottom: none; }
.dx-datagrid .dx-column-lines > td { border-right: none; }

.dx-pager {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

.dx-pager .dx-page-size.dx-selection,
.dx-pager .dx-page.dx-selection {
  background: var(--accent);
  color: #fff;
  border-radius: 5px;
}

/* Search panel */
.dx-datagrid-search-panel.dx-texteditor {
  border-radius: 7px;
}

/* Text editors (TextBox, SelectBox, TextArea, DateBox) */
.dx-texteditor.dx-editor-outlined {
  border-radius: 7px;
  border-color: var(--border);
  background: var(--surface);
}

.dx-texteditor.dx-editor-outlined.dx-state-hover {
  border-color: var(--border-hover);
}

.dx-texteditor.dx-editor-outlined.dx-state-focused {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.08);
}

/* Force-hide DX floating label (labelMode:'hidden' alone is insufficient in 24.x) */
.dx-texteditor .dx-label,
.dx-texteditor .dx-label-span,
.dx-texteditor-label,
.dx-texteditor.dx-editor-outlined .dx-label,
.dx-texteditor.dx-editor-outlined .dx-texteditor-label {
  display: none !important;
  height: 0 !important;
  overflow: hidden !important;
}

/* Ensure input sits flush with no top-padding reserved for hidden label */
.dx-texteditor.dx-editor-outlined .dx-texteditor-input-container {
  padding-top: 0 !important;
}

.dx-texteditor-input {
  font-size: 13px !important;
  color: var(--text) !important;
  padding: 8px 12px !important;
}

/* Prevent search icon from overlapping typed text */
.dx-searchbox .dx-texteditor-input {
  padding-left: 32px !important;
}

.dx-texteditor-input::placeholder {
  color: #94A3B8;
  opacity: 1;
}

/* Hide DX's custom placeholder overlay — the native <input placeholder> attribute is sufficient */
.dx-placeholder { display: none !important; }

/* SelectBox dropdown */
.dx-overlay-content .dx-list-item {
  font-size: 13px;
  color: var(--text);
}

.dx-overlay-content .dx-list-item.dx-state-hover {
  background: #EFF6FF;
}

.dx-overlay-content .dx-list-item.dx-list-item-selected {
  background: #EFF6FF;
  color: var(--accent);
}

/* Header filter popup */
.dx-header-filter-menu .dx-popup-content { font-size: 13px; }

/* Toolbar */
.dx-toolbar { padding: 10px 0; background: transparent; }
.dx-toolbar-items-container { background: transparent; }
.dx-datagrid-header-panel { border-bottom: 1px solid var(--border); background: var(--surface); padding: 0 14px; }

/* DataGrid no-data */
.dx-datagrid-nodata {
  font-size: 13px;
  color: var(--muted);
  padding: 40px 0;
}

/* Fix card overflow for DataGrid */
.card.grid-card { padding: 0; overflow: hidden; }
.card.grid-card .dx-datagrid-header-panel { border-radius: 10px 10px 0 0; padding: 10px 14px; }

/* Members inner DataGrid (inside modal) */
.members-grid .dx-datagrid-headers .dx-datagrid-table .dx-row > td {
  padding: 8px 12px;
}
.members-grid .dx-datagrid-rowsview .dx-row > td {
  padding: 8px 12px;
}

/* ── Icon action buttons (shared across all grids) ────────────────────────── */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 6px;
  border: 1px solid var(--border); background: transparent;
  color: var(--muted); cursor: pointer; transition: all 0.15s;
  flex-shrink: 0; text-decoration: none; vertical-align: middle;
}
.icon-btn:hover            { background: var(--surface2); color: var(--accent);  border-color: var(--accent);  }
.icon-btn-primary          { color: var(--accent); border-color: var(--accent); background: #eff6ff; }
.icon-btn-primary:hover    { background: var(--accent); color: #fff; }
.icon-btn-danger:hover     { color: #dc2626; border-color: #fca5a5; background: #fef2f2; }
.icon-btn-warning:hover    { color: #d97706; border-color: #fcd34d; background: #fffbeb; }
.icon-btn-success:hover    { color: #059669; border-color: #6ee7b7; background: #ecfdf5; }
.icon-btn-group            { display: flex; gap: 4px; justify-content: flex-end; align-items: center; }

/* ── Notification Bell ───────────────────────────────────────────────────── */
.notif-bell-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.notif-bell-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
  position: relative;
}
.notif-bell-btn:hover { background: var(--surface2); color: var(--accent); border-color: var(--accent); }

.notif-badge {
  position: absolute;
  top: -5px; right: -5px;
  background: #DC2626;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px; height: 16px;
  border-radius: 8px;
  padding: 0 3px;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
  border: 2px solid var(--surface);
}
.notif-badge.hidden { display: none; }

/* Notification dropdown panel */
.notif-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  z-index: 999;
  overflow: hidden;
  display: none;
}
.notif-panel.open { display: block; }

.notif-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 600;
}
.notif-panel-header button {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font-size: 12px; font-family: inherit; padding: 0;
}
.notif-panel-header button:hover { text-decoration: underline; }

.notif-list {
  max-height: 360px;
  overflow-y: auto;
}

.notif-item {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--surface2); }
.notif-item.unread { background: #EFF6FF; }
.notif-item.unread:hover { background: #DBEAFE; }

.notif-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0; margin-top: 5px;
}
.notif-item:not(.unread) .notif-dot { background: transparent; }

.notif-item-body { flex: 1; min-width: 0; }
.notif-item-title { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 2px; line-height: 1.3; }
.notif-item-msg   { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notif-item-time  { font-size: 10px; color: #94A3B8; margin-top: 3px; }

.notif-item-del {
  background: none; border: none; color: #CBD5E1;
  cursor: pointer; padding: 2px; border-radius: 4px;
  font-size: 14px; line-height: 1;
  flex-shrink: 0;
}
.notif-item-del:hover { color: var(--accent4); background: #FEF2F2; }

.notif-empty {
  text-align: center; padding: 28px 16px;
  font-size: 12px; color: var(--muted);
}

/* ── User Menu (sidebar footer popup) ─────────────────────── */

.user-chip-btn {
  display: flex; align-items: center; gap: 10px;
  background: none; border: none; padding: 0;
  cursor: pointer; width: 100%; text-align: left;
  border-radius: 6px; transition: background 0.12s;
  font-family: inherit;
}
.user-chip-btn:hover { background: rgba(0,0,0,0.04); }

.user-menu {
  position: fixed;
  min-width: 224px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  z-index: 300;
  overflow: hidden;
  display: none;
}
.user-menu.open { display: block; }

.user-menu-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  font-size: 13px; color: var(--text);
  cursor: pointer; background: none; border: none;
  width: 100%; font-family: inherit; text-align: left;
  transition: background 0.12s; white-space: nowrap;
}
.user-menu-item:hover { background: var(--surface2); }
.user-menu-item.danger { color: var(--accent4); }
.user-menu-sep { border: none; border-top: 1px solid var(--border); margin: 0; }

.user-menu-theme {
  padding: 10px 12px 12px;
}
.user-menu-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.theme-mode-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.theme-mode-btn {
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  border-radius: 7px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 6px;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: border-color .12s, background .12s, color .12s;
}
.theme-mode-btn span {
  font-size: 13px;
  line-height: 1;
}
.theme-mode-btn:hover {
  border-color: var(--border-hover);
  color: var(--text);
  background: var(--surface);
}
.theme-mode-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(37,99,235,.1);
}

html[data-theme="dark"] .nav-link.active,
html[data-theme="dark"] .dx-datagrid-rowsview .dx-selection.dx-row > td,
html[data-theme="dark"] .dx-datagrid-rowsview .dx-selection.dx-row:hover > td,
html[data-theme="dark"] .notif-item.unread,
html[data-theme="dark"] .dx-overlay-content .dx-list-item.dx-state-hover,
html[data-theme="dark"] .dx-overlay-content .dx-list-item.dx-list-item-selected {
  background: rgba(96,165,250,.16) !important;
}
html[data-theme="dark"] .data-table tbody tr:hover td,
html[data-theme="dark"] .dx-datagrid-rowsview .dx-row:hover > td,
html[data-theme="dark"] .dx-datagrid-headers .dx-datagrid-table .dx-row > td,
html[data-theme="dark"] .dx-datagrid-header-panel {
  background: var(--surface2) !important;
}
html[data-theme="dark"] .dx-widget,
html[data-theme="dark"] .dx-datagrid,
html[data-theme="dark"] .dx-datagrid-headers,
html[data-theme="dark"] .dx-datagrid-rowsview,
html[data-theme="dark"] .dx-editor-outlined,
html[data-theme="dark"] .dx-overlay-content {
  background: var(--surface) !important;
  color: var(--text) !important;
}
html[data-theme="dark"] .dx-texteditor-input,
html[data-theme="dark"] .dx-placeholder,
html[data-theme="dark"] .dx-list-item-content {
  color: var(--text) !important;
}
html[data-theme="dark"] .modal-overlay {
  background: rgba(2,6,23,.68);
}

/* ── Notification Detail overlay ──────────────────────────── */
.notif-detail-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 1200;
  display: flex; align-items: center; justify-content: center;
}
.notif-detail-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 420px; max-width: 94vw;
  padding: 0; overflow: hidden;
}
.ndm-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.ndm-head-title { font-size: 14px; font-weight: 700; color: var(--text); }
.ndm-close {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 16px; padding: 2px 6px; border-radius: 4px;
}
.ndm-close:hover { background: var(--surface2); color: var(--text); }
.ndm-body { padding: 18px 18px 20px; }
.ndm-type  { font-size: 10px; font-weight: 700; color: var(--accent); letter-spacing: .6px; text-transform: uppercase; margin-bottom: 8px; }
.ndm-title { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 10px; line-height: 1.4; }
.ndm-msg   { font-size: 13px; color: var(--muted); line-height: 1.65; margin-bottom: 14px; white-space: pre-wrap; }
.ndm-time  { font-size: 11px; color: #94A3B8; margin-bottom: 18px; }
.ndm-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Deviation Report Page ────────────────────────────────────────────────── */
.deviation-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.devstat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  text-align: center;
}
.devstat-val {
  font-size: 28px; font-weight: 700; color: var(--text);
  line-height: 1;
}
.devstat-val.danger  { color: #DC2626; }
.devstat-val.warning { color: #D97706; }
.devstat-val.success { color: #059669; }
.devstat-val.info    { color: var(--accent); }
.devstat-lbl {
  font-size: 11px; color: var(--muted); font-weight: 500;
  margin-top: 4px; text-transform: uppercase; letter-spacing: 0.05em;
}

.progress-bar-wrap {
  background: var(--border);
  border-radius: 99px;
  height: 8px;
  overflow: hidden;
  margin-top: 4px;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--accent3);
  transition: width 0.4s ease;
}

.deviation-section-title {
  font-size: 13px; font-weight: 700; color: var(--text);
  margin: 0 0 12px;
  display: flex; align-items: center; gap: 8px;
}
.deviation-section-title .count-pill {
  font-size: 11px; font-weight: 700;
  padding: 1px 8px; border-radius: 99px;
  background: #FEE2E2; color: #DC2626;
}
.deviation-section-title .count-pill.warning {
  background: #FEF3C7; color: #D97706;
}
