/* Enterprise Design System: SUNAT Cloud Engine (Unified Dark SaaS Theme) */

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-gradient: linear-gradient(135deg, #2563eb, #0284c7);
  --accent: #38bdf8;
  /* Light theme colors */
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-sub: #f3f4f6;
  --border-color: #e5e7eb;
  --border-focus: #3b82f6;
  --sidebar-bg: #f9fafb;
  --sidebar-hover: #e5e7eb;
  --sidebar-border: #d1d5db;
  --sidebar-text: #374151;
  --sidebar-active: #111827;
  --text-main: #111827;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.12);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

/* Dark theme overrides */
body.dark-theme {
  --bg-app: #090d16;
  --bg-card: #121826;
  --bg-card-sub: #172033;
  --border-color: #1e293b;
  --border-focus: #3b82f6;
  --sidebar-bg: #0d121f;
  --sidebar-hover: #172033;
  --sidebar-border: #1e293b;
  --sidebar-text: #94a3b8;
  --sidebar-active: #ffffff;
  --text-main: #f3f4f6;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
}

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

body.dark-theme {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
}

/* Auth Overlay Screen */
.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 13, 22, 0.95);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-header .brand-icon.lg {
  width: 52px;
  height: 52px;
  font-size: 1.25rem;
  margin: 0 auto 1rem;
}

.login-header h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: #ffffff;
}

.login-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.login-form .form-group {
  margin-bottom: 1.25rem;
}

.login-form label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
}

.login-form input {
  width: 100%;
  background: #090d16;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  color: #ffffff;
  outline: none;
  transition: border-color 0.2s;
}

.login-form input:focus {
  border-color: var(--border-focus);
}

/* Layout */
.admin-layout {
  display: flex;
  min-height: 100vh;
}

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

.sidebar-brand {
  padding: 1.5rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  border-bottom: 1px solid var(--sidebar-border);
}

.brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-weight: 800;
  font-size: 0.95rem;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
}

.brand-text h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-faint);
  font-weight: 500;
}

.sidebar-nav {
  padding: 1.25rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.nav-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: #475569;
  padding: 0.75rem 0.75rem 0.35rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
  width: 100%;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #ffffff;
}

.nav-item.active {
  background: #1e293b;
  color: var(--sidebar-active);
  font-weight: 700;
  border-left: 3px solid var(--accent);
}

.nav-icon {
  font-size: 1rem;
}

.nav-badge {
  margin-left: auto;
  font-size: 0.65rem;
  padding: 0.15rem 0.45rem;
  border-radius: 9999px;
  font-weight: 700;
}

.badge-idle { background: #334155; color: #94a3b8; }
.badge-running { background: #0284c7; color: #ffffff; animation: pulse 1.5s infinite; }
.badge-success { background: #059669; color: #ffffff; }
.badge-danger { background: #dc2626; color: #ffffff; }

.sidebar-footer {
  padding: 1.25rem;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.connection-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.pulse-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.pulse-indicator.online {
  background: var(--success);
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.pulse-indicator.offline {
  background: var(--danger);
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

.server-stat {
  font-size: 0.75rem;
  color: var(--text-faint);
  font-family: 'JetBrains Mono', monospace;
}

.btn-logout {
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: transparent;
  border: 1px solid #334155;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-logout:hover {
  background: #1e293b;
  color: #ef4444;
  border-color: #ef4444;
}

/* Main Wrapper */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

/* Topbar */
.topbar {
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border-color);
  padding: 1.25rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.topbar-title h1 {
  font-size: 1.35rem;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.3px;
}

.topbar-title p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.content-body {
  padding: 2rem;
  flex: 1;
}

.view-pane {
  display: none;
}

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

/* KPI Summary Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

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

.kpi-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--text-faint);
}

.kpi-icon-badge {
  font-size: 1.1rem;
}

.kpi-value {
  font-size: 1.9rem;
  font-weight: 800;
  color: #ffffff;
  font-family: 'JetBrains Mono', monospace;
  line-height: 1.1;
  margin-bottom: 0.5rem;
}

.kpi-footer {
  font-size: 0.75rem;
  font-weight: 600;
}

/* Split Grid for Dashboard Charts */
.dashboard-grid-split {
  display: flex;
  gap: 1.5rem;
}

.dashboard-grid-split .flex-2 { flex: 2; }
.dashboard-grid-split .flex-1 { flex: 1; }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 1.5rem;
}

.dashboard-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
}

.card-title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.card-title-bar h3, .card-title-bar h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffffff;
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.time-range-pill {
  font-size: 0.72rem;
  background: var(--bg-card-sub);
  color: var(--text-muted);
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  font-weight: 600;
  border: 1px solid var(--border-color);
}

.chart-canvas-container {
  width: 100%;
  position: relative;
}

.chart-canvas-container.donut-container {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Ingestion Monitor Card */
.import-monitor-card {
  border-left: 4px solid var(--primary);
}

.monitor-actions {
  display: flex;
  gap: 0.75rem;
}

.import-status-box {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  margin-top: 1rem;
}

.status-top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.current-phase {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.status-dot-pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #64748b;
}

.status-dot-pulse.running {
  background: var(--accent);
  animation: pulse 1.2s infinite;
}

.status-dot-pulse.completed { background: var(--success); }
.status-dot-pulse.failed { background: var(--danger); }

.live-progress-container {
  width: 100%;
  height: 10px;
  background: #090d16;
  border-radius: 9999px;
  overflow: hidden;
  margin-bottom: 0.65rem;
  border: 1px solid var(--border-color);
}

.live-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #38bdf8);
  border-radius: 9999px;
  transition: width 0.3s ease;
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}

.import-stats-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-color);
}

.sub-stat {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sub-label {
  font-size: 0.72rem;
  color: var(--text-faint);
  font-weight: 600;
  text-transform: uppercase;
}

.sub-val {
  font-size: 1.2rem;
  font-weight: 700;
  color: #ffffff;
  font-family: 'JetBrains Mono', monospace;
}

/* ============================================================ */
/* API PROVIDERS VIEW (MODERN DARK SAAS REDESIGN)               */
/* ============================================================ */
.providers-modern-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(440px, 1fr));
  gap: 1.5rem;
  margin-top: 1.25rem;
}

.provider-card-modern {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.provider-card-modern:hover {
  border-color: #334155;
}

.provider-card-modern.disabled {
  opacity: 0.75;
}

.provider-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.provider-title-group h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #ffffff;
}

.provider-id-chip {
  font-size: 0.72rem;
  color: var(--accent);
  background: rgba(56, 189, 248, 0.1);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  margin-top: 0.2rem;
  display: inline-block;
}

/* iOS Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #334155;
  transition: 0.25s;
  border-radius: 26px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: #ffffff;
  transition: 0.25s;
  border-radius: 50%;
}

input:checked + .toggle-slider {
  background-color: var(--success);
}

input:checked + .toggle-slider:before {
  transform: translateX(22px);
}

/* Quota Progress Group */
.quota-meter-group {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.quota-meter-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.quota-track-bg {
  width: 100%;
  height: 8px;
  background: #090d16;
  border-radius: 9999px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.quota-track-fill {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #a855f7);
  border-radius: 9999px;
  transition: width 0.3s;
}

.quota-track-fill.warning { background: var(--warning); }
.quota-track-fill.danger { background: var(--danger); }

/* Stats Chips Row */
.provider-chips-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.chip-item {
  flex: 1;
  min-width: 90px;
  background: #090d16;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.chip-num {
  font-size: 1.05rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
}

.chip-label {
  font-size: 0.68rem;
  color: var(--text-faint);
  text-transform: uppercase;
  font-weight: 600;
  margin-top: 0.15rem;
}

/* Provider Edit Form */
.provider-form-body {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border-color);
}

.form-split-row {
  display: flex;
  gap: 1rem;
}

.form-split-row .form-field {
  flex: 1;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-field label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-field input {
  background: #090d16;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  color: #ffffff;
  font-size: 0.85rem;
  outline: none;
}

.form-field input:focus {
  border-color: var(--border-focus);
}

.password-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.password-input-wrapper input {
  width: 100%;
  padding-right: 2.5rem;
}

.btn-toggle-eye {
  position: absolute;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 4px;
}

.btn-toggle-eye:hover {
  color: #ffffff;
}

/* Tables */
.table-responsive {
  overflow-x: auto;
}

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

.data-table th, .data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.85rem;
}

.data-table th {
  background: #090d16;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

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

/* Console & Search */
.input-wrapper {
  display: flex;
  gap: 0.75rem;
}

.input-wrapper input {
  flex: 1;
  font-size: 1rem;
  padding: 0.75rem 1rem;
  background: #090d16;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: #ffffff;
  font-family: 'JetBrains Mono', monospace;
}

.input-wrapper input:focus {
  outline: none;
  border-color: var(--border-focus);
}

.input-hint {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.input-hint code {
  background: #172033;
  color: var(--accent);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
}

.console-result {
  margin-top: 1.5rem;
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.badge-group {
  display: flex;
  gap: 0.5rem;
}

/* Buttons */
.btn {
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary-gradient {
  background: var(--primary-gradient);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-primary-gradient:hover {
  filter: brightness(1.1);
}

.btn-secondary {
  background: #172033;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: #1e293b;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 0.45rem 0.85rem;
  font-size: 0.8rem;
}

/* Alerts */
.alert {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.alert-danger {
  background: var(--danger-bg);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.alert-success {
  background: var(--success-bg);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.alert-info {
  background: rgba(56, 189, 248, 0.1);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

/* Badges & Pills */
.pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.pill-success { background: var(--success-bg); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
.pill-danger { background: var(--danger-bg); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.3); }
.pill-warning { background: var(--warning-bg); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
.pill-muted { background: #1e293b; color: #94a3b8; }

.badge {
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-blue { background: rgba(56, 189, 248, 0.15); color: #38bdf8; }
.badge-purple { background: rgba(168, 85, 247, 0.15); color: #c084fc; }
.badge-gray { background: #1e293b; color: #94a3b8; }

/* Guide & Code boxes */
.code-box {
  background: #090d16;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  overflow-x: auto;
  color: #e2e8f0;
}

.code-box pre {
  margin: 0;
}

.config-form .form-group {
  margin-bottom: 1rem;
}

.config-form label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.config-form input {
  width: 100%;
  background: #090d16;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  color: #ffffff;
  font-size: 0.85rem;
}

.input-code {
  font-family: 'JetBrains Mono', monospace;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-faint);
  margin-top: 0.35rem;
  display: block;
}

/* Spinner */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.hidden { display: none !important; }
.font-mono { font-family: 'JetBrains Mono', monospace; }
.font-bold { font-weight: 700; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--accent); }
.text-gray { color: var(--text-faint); }
