/* ==========================================================================
   FINFLOW ENTERPRISE ADMIN PORTAL - MODERN RESPONSIVE STYLESHEET
   Aesthetics: Deep Obsidian Slate, Glassmorphism, Electric Accents, High Contrast
   ========================================================================== */

:root {
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.75);
  --bg-card-hover: rgba(31, 41, 55, 0.65);
  --bg-input: #1f2937;
  --border-color: rgba(55, 65, 81, 0.6);
  --border-subtle: rgba(55, 65, 81, 0.3);
  
  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  
  --accent-indigo: #6366f1;
  --accent-indigo-glow: rgba(99, 102, 241, 0.25);
  --accent-emerald: #10b981;
  --accent-emerald-glow: rgba(16, 185, 129, 0.25);
  --accent-amber: #f59e0b;
  --accent-amber-glow: rgba(245, 158, 11, 0.25);
  --accent-rose: #ef4444;
  --accent-rose-glow: rgba(239, 68, 68, 0.25);
  --accent-cyan: #06b6d4;
  --accent-cyan-glow: rgba(6, 182, 212, 0.25);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  
  --sidebar-width: 260px;
  --header-height: 70px;
  --transition-speed: 0.2s;
  --border-radius: 12px;
}

[data-theme="light"] {
  --bg-primary: #f3f4f6;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-card-hover: #f9fafb;
  --bg-input: #f3f4f6;
  --border-color: #e5e7eb;
  --border-subtle: #f3f4f6;
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Background Ambient Glow */
.ambient-glow {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 400px;
  background: radial-gradient(circle at 50% -100px, rgba(99, 102, 241, 0.15), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* --------------------------------------------------------------------------
   LAYOUT ARCHITECTURE
   -------------------------------------------------------------------------- */
.app-container {
  display: flex;
  width: 100vw;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  transition: transform var(--transition-speed) ease;
}

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

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, #4f46e5, #06b6d4);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px var(--accent-indigo-glow);
}

.brand-logo svg {
  width: 22px;
  height: 22px;
  fill: #ffffff;
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.brand-text span {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-indigo);
  background: rgba(99, 102, 241, 0.15);
  padding: 2px 6px;
  border-radius: 4px;
}

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

.nav-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 12px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  border-radius: 8px;
  transition: all var(--transition-speed) ease;
  position: relative;
  cursor: pointer;
}

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

.nav-item.active {
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.15), rgba(99, 102, 241, 0.05));
  color: var(--accent-indigo);
  font-weight: 600;
  border-left: 3px solid var(--accent-indigo);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  background: var(--accent-indigo);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
}

.nav-badge.danger {
  background: var(--accent-rose);
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.admin-profile {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #374151;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.82rem;
  color: #fff;
  border: 1px solid var(--border-color);
}

.admin-info {
  display: flex;
  flex-direction: column;
}

.admin-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
}

.admin-role {
  font-size: 0.7rem;
  color: var(--accent-emerald);
}

/* Main Content Area */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  width: calc(100vw - var(--sidebar-width));
}

/* Top Header Bar */
.topbar {
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 90;
  backdrop-filter: blur(12px);
}

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

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
}

.page-title-wrap h2 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

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

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Connection Pill */
.connection-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 20px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-emerald);
}

.connection-pill.disconnected {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.25);
  color: var(--accent-rose);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
  animation: pulse-ring 2s infinite;
}

.connection-pill.disconnected .pulse-dot {
  background: var(--accent-rose);
  box-shadow: 0 0 8px var(--accent-rose);
  animation: none;
}

@keyframes pulse-ring {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.mode-toggle-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-speed);
}

.mode-toggle-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent-indigo);
}

/* Page Body Container */
.page-body {
  padding: 32px;
  flex: 1;
}

.tab-pane {
  display: none;
  animation: fadeIn 0.25s ease forwards;
}

.tab-pane.active {
  display: block;
}

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

/* --------------------------------------------------------------------------
   DASHBOARD KPI CARDS & GRIDS
   -------------------------------------------------------------------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform var(--transition-speed), border-color var(--transition-speed);
  backdrop-filter: blur(10px);
}

.kpi-card:hover {
  transform: translateY(-2px);
  border-color: rgba(99, 102, 241, 0.4);
}

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

.kpi-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-icon-wrap {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-icon-wrap.indigo { background: rgba(99, 102, 241, 0.15); color: var(--accent-indigo); }
.kpi-icon-wrap.emerald { background: rgba(16, 185, 129, 0.15); color: var(--accent-emerald); }
.kpi-icon-wrap.amber { background: rgba(245, 158, 11, 0.15); color: var(--accent-amber); }
.kpi-icon-wrap.cyan { background: rgba(6, 182, 212, 0.15); color: var(--accent-cyan); }
.kpi-icon-wrap.rose { background: rgba(239, 68, 68, 0.15); color: var(--accent-rose); }

.kpi-value {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.kpi-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.kpi-trend {
  font-weight: 600;
}

.kpi-trend.positive { color: var(--accent-emerald); }
.kpi-trend.negative { color: var(--accent-rose); }

/* Dashboard Sections Grid */
.dashboard-grid-2col {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
  margin-bottom: 28px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  backdrop-filter: blur(10px);
  padding: 24px;
}

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

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-title svg {
  width: 20px;
  height: 20px;
  color: var(--accent-indigo);
}

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

/* Charts */
.chart-container {
  width: 100%;
  height: 240px;
  position: relative;
}

.chart-svg {
  width: 100%;
  height: 100%;
}

.chart-grid-line {
  stroke: rgba(55, 65, 81, 0.3);
  stroke-dasharray: 4;
}

.chart-area {
  fill: url(#indigoGradient);
}

.chart-line {
  fill: none;
  stroke: var(--accent-indigo);
  stroke-width: 3;
  stroke-linecap: round;
}

/* Real-Time Live Activity Feed */
.live-stream-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 280px;
  overflow-y: auto;
}

.live-stream-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(31, 41, 55, 0.4);
  border-left: 3px solid var(--accent-indigo);
  font-size: 0.8rem;
  transition: background var(--transition-speed);
}

.live-stream-item:hover {
  background: rgba(31, 41, 55, 0.7);
}

.live-stream-item.warn { border-left-color: var(--accent-amber); }
.live-stream-item.err { border-left-color: var(--accent-rose); }
.live-stream-item.ok { border-left-color: var(--accent-emerald); }

.live-stream-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  font-family: var(--font-mono);
}

.live-stream-content {
  flex: 1;
}

.live-stream-msg {
  font-weight: 500;
  color: var(--text-primary);
}

.live-stream-detail {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* --------------------------------------------------------------------------
   DATA TABLES & CONTROLS
   -------------------------------------------------------------------------- */
.table-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-input-wrap {
  position: relative;
  flex: 1;
  max-width: 380px;
}

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

.search-input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition-speed);
}

.search-input:focus {
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 3px var(--accent-indigo-glow);
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.select-filter {
  padding: 9px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition-speed);
  text-decoration: none;
}

.btn-primary {
  background: var(--accent-indigo);
  color: #ffffff;
  box-shadow: 0 4px 12px var(--accent-indigo-glow);
}

.btn-primary:hover {
  background: #4f46e5;
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

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

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-rose);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: var(--accent-rose);
  color: #fff;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.85rem;
}

.data-table th {
  background: rgba(31, 41, 55, 0.7);
  padding: 14px 18px;
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tr:hover td {
  background: var(--bg-card-hover);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-emerald { background: rgba(16, 185, 129, 0.15); color: var(--accent-emerald); border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-indigo { background: rgba(99, 102, 241, 0.15); color: var(--accent-indigo); border: 1px solid rgba(99, 102, 241, 0.3); }
.badge-amber { background: rgba(245, 158, 11, 0.15); color: var(--accent-amber); border: 1px solid rgba(245, 158, 11, 0.3); }
.badge-rose { background: rgba(239, 68, 68, 0.15); color: var(--accent-rose); border: 1px solid rgba(239, 68, 68, 0.3); }
.badge-cyan { background: rgba(6, 182, 212, 0.15); color: var(--accent-cyan); border: 1px solid rgba(6, 182, 212, 0.3); }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.pagination-btns {
  display: flex;
  gap: 8px;
}

/* --------------------------------------------------------------------------
   MODAL DIALOGS
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

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

.modal-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  width: 100%;
  max-width: 540px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  animation: modalPop 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  overflow: hidden;
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.96) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

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

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
}

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

.modal-close-btn:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-input, .form-textarea, .form-select {
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 3px var(--accent-indigo-glow);
}

.form-textarea {
  resize: vertical;
  min-height: 90px;
}

.modal-footer {
  padding: 16px 24px;
  background: rgba(31, 41, 55, 0.3);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
}

.toast {
  padding: 12px 18px;
  border-radius: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  animation: slideToast 0.25s ease forwards;
}

@keyframes slideToast {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* --------------------------------------------------------------------------
   RESPONSIVE MEDIA QUERIES
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .dashboard-grid-2col {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
    width: 100vw;
  }

  .mobile-menu-btn {
    display: block;
  }

  .page-body {
    padding: 20px;
  }
  
  .topbar {
    padding: 0 20px;
  }
}
