/* ==========================================================================
   Sales & Margin System - Modern Enterprise Design System
   ========================================================================== */

:root {
  --bg-app: #090d16;
  --bg-sidebar: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #273549;
  --bg-card-subtle: rgba(30, 41, 59, 0.7);
  --bg-input: #131d31;
  --bg-glass: rgba(15, 23, 42, 0.88);

  --border-color: #334155;
  --border-subtle: rgba(51, 65, 85, 0.6);
  --border-focus: #6366f1;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --accent-indigo: #6366f1;
  --accent-indigo-hover: #4f46e5;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-purple: #8b5cf6;
  --accent-pink: #ec4899;

  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.25);

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

/* Light Mode Overrides */
[data-theme-mode="light"] {
  --bg-app: #f1f5f9;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-card-subtle: #f1f5f9;
  --bg-input: #f8fafc;
  --bg-glass: rgba(255, 255, 255, 0.96);

  --border-color: #e2e8f0;
  --border-subtle: #cbd5e1;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;

  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

[data-theme-mode="light"] .data-table thead th {
  background-color: #f8fafc !important;
  color: #334155 !important;
  border-bottom: 2px solid #cbd5e1 !important;
}

[data-theme-mode="light"] .data-table tbody td:first-child,
[data-theme-mode="light"] .data-table thead th:first-child {
  background-color: #f8fafc !important;
  border-right: 1px solid #cbd5e1 !important;
}

[data-theme-mode="light"] .data-table td {
  background-color: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  color: #0f172a;
}

[data-theme-mode="light"] strong, 
[data-theme-mode="light"] h1, 
[data-theme-mode="light"] h2, 
[data-theme-mode="light"] h3, 
[data-theme-mode="light"] h4 {
  color: #0f172a !important;
}

[data-theme-mode="light"] .stat-card,
[data-theme-mode="light"] .card,
[data-theme-mode="light"] .modal-container,
[data-theme-mode="light"] .filter-bar {
  background-color: #ffffff !important;
  color: #0f172a !important;
}

[data-theme-mode="light"] .form-control {
  background-color: #f8fafc !important;
  border-color: #cbd5e1 !important;
  color: #0f172a !important;
}

[data-theme-mode="light"] .top-header {
  background-color: #ffffff !important;
  border-bottom-color: #e2e8f0 !important;
}

[data-theme-mode="light"] .role-switcher-select {
  background-color: #f8fafc !important;
  border-color: #cbd5e1 !important;
  color: #0f172a !important;
}

[data-theme-mode="light"] .table-filter-popup {
  background-color: #ffffff !important;
  border-color: #cbd5e1 !important;
  color: #0f172a !important;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15) !important;
}

[data-theme-mode="light"] .sidebar-footer {
  background-color: #f8fafc !important;
  border-top-color: #e2e8f0 !important;
}

/* Accent Color Variations */
[data-theme-accent="indigo"] {
  --accent-indigo: #6366f1;
  --accent-indigo-hover: #4f46e5;
  --accent-purple: #8b5cf6;
}

[data-theme-accent="cyan"] {
  --accent-indigo: #0284c7;
  --accent-indigo-hover: #0369a1;
  --accent-purple: #06b6d4;
  --border-focus: #0284c7;
}

[data-theme-accent="emerald"] {
  --accent-indigo: #059669;
  --accent-indigo-hover: #047857;
  --accent-purple: #10b981;
  --border-focus: #059669;
}

[data-theme-accent="amber"] {
  --accent-indigo: #d97706;
  --accent-indigo-hover: #b45309;
  --accent-purple: #f59e0b;
  --border-focus: #d97706;
}

[data-theme-accent="rose"] {
  --accent-indigo: #e11d48;
  --accent-indigo-hover: #be123c;
  --accent-purple: #f43f5e;
  --border-focus: #e11d48;
}

.theme-color-dot {
  transition: transform 0.15s ease, outline 0.15s ease;
}

.theme-color-dot:hover {
  transform: scale(1.2);
}

.theme-color-dot.active {
  outline: 2px solid #fff;
  outline-offset: 2px;
  transform: scale(1.15);
}

.theme-mode-btn.active {
  background: var(--accent-indigo) !important;
  color: #fff !important;
  border-color: var(--accent-indigo) !important;
}

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

body {
  font-family: 'Plus Jakarta Sans', 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
}

/* ---------------- Layout & App Shell ---------------- */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.app-sidebar {
  width: 260px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 30;
  transition: width var(--transition-normal);
}

.sidebar-brand {
  height: 52px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border-color);
  box-sizing: border-box;
}

.brand-badge {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  flex-shrink: 0;
}

.brand-badge img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(99, 102, 241, 0.35));
}

.brand-text h2 {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.1;
  margin: 0;
}

.brand-text span {
  font-size: 0.68rem;
  color: var(--text-muted);
  display: block;
}

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

.nav-section-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 14px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.86rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.nav-item i {
  font-size: 1rem;
  width: 20px;
  text-align: center;
  opacity: 0.85;
}

.nav-item:hover {
  background-color: var(--bg-card);
  color: var(--text-main);
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.15), rgba(99, 102, 241, 0.05));
  color: #818cf8;
  border-color: rgba(99, 102, 241, 0.3);
  font-weight: 600;
}

.nav-item.active i {
  color: var(--accent-indigo);
  opacity: 1;
}

.nav-badge {
  margin-left: auto;
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background-color: rgba(244, 63, 94, 0.2);
  color: var(--accent-rose);
  font-weight: 700;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  background-color: rgba(15, 23, 42, 0.6);
}

/* User Profile in Sidebar */
.user-widget {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-indigo));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.1);
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  text-transform: uppercase;
}

/* Main Content Area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
  background: radial-gradient(circle at 80% 20%, rgba(99, 102, 241, 0.05) 0%, transparent 40%),
              radial-gradient(circle at 20% 80%, rgba(6, 182, 212, 0.04) 0%, transparent 40%),
              var(--bg-app);
}

/* Top Navigation Bar */
.top-header {
  height: 52px;
  background-color: var(--bg-glass);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 20;
  flex-shrink: 0;
  box-sizing: border-box;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-page-title h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
}

.header-page-title p {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.role-switcher-select {
  background-color: var(--bg-card);
  color: #fff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.8rem;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.role-switcher-select:focus {
  border-color: var(--accent-indigo);
}

/* Content View Wrapper */
.content-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
}

/* Tab View Panes */
.view-pane {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 100%;
  animation: fadeIn 0.25s ease forwards;
}

.view-pane.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------- Universal Components ---------------- */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-indigo), #4f46e5);
  color: white;
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #4f46e5, #4338ca);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--bg-card-hover);
  border-color: var(--accent-indigo);
}

.btn-success {
  background: linear-gradient(135deg, var(--accent-emerald), #059669);
  color: white;
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
  background: linear-gradient(135deg, #059669, #047857);
}

.btn-warning {
  background: linear-gradient(135deg, var(--accent-amber), #d97706);
  color: white;
}

.btn-danger {
  background: linear-gradient(135deg, var(--accent-rose), #e11d48);
  color: white;
  box-shadow: 0 2px 10px rgba(244, 63, 94, 0.3);
}

.btn-danger:hover {
  background: linear-gradient(135deg, #e11d48, #be123c);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.76rem;
}

/* Cards */
.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-md);
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
}

.view-pane > .card:only-child,
.view-pane > .card:last-child {
  flex: 1;
  margin-bottom: 0;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-shrink: 0;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Tables & Frozen Columns */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  overflow-y: auto;
  max-height: calc(100vh - 210px);
  position: relative;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
}

.table-frozen-container {
  flex: 1;
  max-height: calc(100vh - 210px);
  min-height: 380px;
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  position: relative;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.82rem;
  text-align: left;
}

/* Sticky Header (Freeze Header While Scroll) */
.data-table thead th {
  position: sticky !important;
  top: 0 !important;
  z-index: 10 !important;
  background-color: var(--bg-card) !important;
  padding: 10px 14px;
  color: var(--text-main);
  font-weight: 700;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  user-select: none;
}

/* Freeze First Column (#ID or Code) */
.data-table tbody td:first-child {
  position: sticky !important;
  left: 0 !important;
  z-index: 5 !important;
  background-color: var(--bg-card) !important;
  border-right: 1px solid var(--border-color);
}

.data-table thead th:first-child {
  position: sticky !important;
  left: 0 !important;
  top: 0 !important;
  z-index: 25 !important;
  background-color: var(--bg-card) !important;
  border-right: 1px solid var(--border-color);
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-main);
  vertical-align: middle;
  background-color: var(--bg-card);
}

.data-table tr:hover td {
  background-color: rgba(99, 102, 241, 0.09) !important;
}

/* Light Theme Overrides for Tables */
[data-theme-mode="light"] .data-table thead th {
  background-color: #f1f5f9 !important;
  color: #1e293b !important;
  border-bottom: 2px solid #cbd5e1;
}

[data-theme-mode="light"] .data-table tbody td:first-child,
[data-theme-mode="light"] .data-table thead th:first-child {
  background-color: #f8fafc !important;
  border-right: 1px solid #cbd5e1;
}

[data-theme-mode="light"] .data-table td {
  background-color: #ffffff;
  color: #0f172a;
  border-bottom: 1px solid #e2e8f0;
}

[data-theme-mode="light"] .data-table tr:hover td {
  background-color: #f1f5f9 !important;
}

/* Column Width Resizer */
.th-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  cursor: col-resize;
  user-select: none;
  height: 100%;
  z-index: 25;
  transition: background 0.15s;
}

.th-resizer:hover, .th-resizer.resizing {
  background: var(--accent-indigo);
  box-shadow: 0 0 8px var(--accent-indigo);
}

/* Column Drag & Drop Reordering */
th.th-dragging {
  opacity: 0.45;
  cursor: grabbing;
}

th.th-drag-over-left {
  border-left: 3px solid var(--accent-cyan) !important;
  background: rgba(6, 182, 212, 0.18) !important;
}

th.th-drag-over-right {
  border-right: 3px solid var(--accent-cyan) !important;
  background: rgba(6, 182, 212, 0.18) !important;
}

/* TH Content Wrapper, Sorting, Move Buttons and Filter Elements */
.th-content-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 24px;
}

.th-title-text {
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  flex: 1;
}

.th-title-text:hover {
  color: var(--accent-indigo);
}

.th-actions {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.table-sort-indicator, .table-filter-trigger, .table-move-btn {
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 0.72rem;
  color: var(--text-dim);
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.table-sort-indicator:hover, .table-filter-trigger:hover, .table-move-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
}

[data-theme-mode="light"] .table-sort-indicator:hover,
[data-theme-mode="light"] .table-filter-trigger:hover,
[data-theme-mode="light"] .table-move-btn:hover {
  color: #0f172a;
  background: rgba(0, 0, 0, 0.08);
}

.sort-active-asc {
  color: var(--accent-cyan) !important;
}

.sort-active-desc {
  color: var(--accent-amber) !important;
}

.filter-active {
  color: var(--accent-cyan) !important;
  background: rgba(6, 182, 212, 0.2) !important;
}

/* Table Filter Popup Modal */
.table-filter-popup {
  position: fixed;
  width: 250px;
  background: #0f172a;
  border: 1px solid var(--accent-indigo);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(99, 102, 241, 0.3);
  border-radius: 8px;
  padding: 12px;
  z-index: 999999;
  font-family: inherit;
  animation: fadeInDown 0.15s ease-out;
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.filter-popup-header {
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(51, 65, 85, 0.6);
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 600;
}

/* Badges & Status */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-valid { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
.status-invalid { background: rgba(244, 63, 94, 0.15); color: #fb7185; border: 1px solid rgba(244, 63, 94, 0.3); }
.status-pending { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
.status-approved { background: rgba(99, 102, 241, 0.15); color: #818cf8; border: 1px solid rgba(99, 102, 241, 0.3); }

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal-container {
  background-color: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 650px;
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalScale 0.2s ease forwards;
}

@keyframes modalScale {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

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

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background-color: var(--bg-input);
}

/* Form Controls */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition-fast);
}

.form-control:focus {
  border-color: var(--accent-indigo);
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: #475569;
}

/* ================= SQL IntelliSense Autocomplete ================= */
.sql-autocomplete-dropdown {
  position: absolute;
  z-index: 999999;
  width: 320px;
  max-height: 280px;
  background: #090d16;
  border: 1px solid var(--accent-indigo);
  border-radius: var(--radius-sm);
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.7), 0 0 20px rgba(99, 102, 241, 0.25);
  display: none;
  overflow: hidden;
  font-family: 'Plus Jakarta Sans', sans-serif;
  animation: autocompleteFadeIn 0.15s ease-out;
}

[data-theme-mode="light"] .sql-autocomplete-dropdown {
  background: #ffffff;
  border-color: var(--accent-indigo);
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15);
}

@keyframes autocompleteFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.sql-autocomplete-header {
  padding: 8px 12px;
  background: rgba(15, 23, 42, 0.85);
  border-bottom: 1px solid var(--border-color);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-indigo);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

[data-theme-mode="light"] .sql-autocomplete-header {
  background: #f8fafc;
  color: var(--accent-indigo);
}

.sql-autocomplete-list {
  max-height: 230px;
  overflow-y: auto;
}

.sql-autocomplete-item {
  padding: 7px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  border-bottom: 1px solid rgba(51, 65, 85, 0.2);
  transition: all 0.12s ease;
}

.sql-autocomplete-item:hover,
.sql-autocomplete-item.active {
  background: rgba(99, 102, 241, 0.18);
  border-left: 3px solid var(--accent-indigo);
}

.sql-item-text {
  font-family: 'Cascadia Code', 'Fira Code', Consolas, monospace;
  font-size: 0.84rem;
  color: var(--text-main);
}

[data-theme-mode="light"] .sql-item-text {
  color: #0f172a;
}

.sql-item-desc {
  font-size: 0.68rem;
  color: var(--text-muted);
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Badges */
.sql-badge {
  font-size: 0.62rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 3px;
  font-family: monospace;
}

.sql-badge-keyword {
  background: rgba(99, 102, 241, 0.2);
  color: #818cf8;
}

.sql-badge-func {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
}

.sql-badge-table {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
}

.sql-badge-col {
  background: rgba(6, 182, 212, 0.2);
  color: #38bdf8;
}

/* Flash / Blink on Autocomplete Selection */
.sql-editor-flash {
  animation: editorGlow 0.25s ease-out;
}

@keyframes editorGlow {
  0% { box-shadow: 0 0 25px rgba(99, 102, 241, 0.6); border-color: #818cf8; }
  100% { box-shadow: none; border-color: var(--accent-indigo); }
}

/* ================= DYNAMICS 365 TOP HEADER ACTION ICONS & FLYOUTS ================= */
.d365-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
}

.d365-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  position: relative;
  transition: all var(--transition-fast);
  font-size: 0.95rem;
}

.d365-icon-btn:hover {
  background: rgba(148, 163, 184, 0.12);
  border-color: var(--border-color);
  color: var(--accent-indigo);
}

.d365-icon-btn.active {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--accent-indigo);
  color: var(--accent-indigo);
}

.d365-badge {
  position: absolute;
  top: 3px;
  right: 3px;
  background: #f43f5e;
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 4px;
  min-width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-app);
}

.d365-avatar-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-indigo), #4338ca);
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 2px solid var(--border-color);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.d365-avatar-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
}

/* Dynamics 365 Flyout Dropdown Panel */
.d365-flyout {
  position: absolute;
  top: 50px;
  right: 0;
  width: 300px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  padding: 16px;
  z-index: 9999;
  display: none;
  animation: flyoutFadeIn 0.15s ease-out;
}

.d365-flyout.active {
  display: block;
}

@keyframes flyoutFadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.d365-flyout-header {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 10px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Disable duplicate native browser password reveal button in Edge/Chromium */
input::-ms-reveal,
input::-ms-clear {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
}

