/* =============================================================================
   Artivity WA Gateway — Dashboard Styles
   Premium dark-mode glassmorphism design
   ============================================================================= */

/* ---------- Reset & Base ---------- */

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

:root {
  /* Background */
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.7);
  --bg-card-hover: rgba(17, 24, 39, 0.85);
  --bg-glass: rgba(255, 255, 255, 0.03);
  --bg-input: rgba(255, 255, 255, 0.06);
  --bg-input-focus: rgba(255, 255, 255, 0.1);

  /* Accent */
  --accent-primary: #6366f1;
  --accent-primary-soft: rgba(99, 102, 241, 0.15);
  --accent-primary-glow: rgba(99, 102, 241, 0.3);
  --accent-secondary: #818cf8;

  /* Status */
  --color-success: #22c55e;
  --color-success-soft: rgba(34, 197, 94, 0.15);
  --color-warning: #f59e0b;
  --color-warning-soft: rgba(245, 158, 11, 0.15);
  --color-danger: #ef4444;
  --color-danger-soft: rgba(239, 68, 68, 0.15);
  --color-info: #3b82f6;
  --color-info-soft: rgba(59, 130, 246, 0.15);

  /* Text */
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-accent: #a5b4fc;

  /* Border */
  --border: rgba(255, 255, 255, 0.06);
  --border-accent: rgba(99, 102, 241, 0.3);

  /* Misc */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px var(--accent-primary-glow);

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Animated background gradient */
body::before {
  content: '';
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(ellipse at 30% 20%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
              radial-gradient(ellipse at 80% 80%, rgba(139, 92, 246, 0.06) 0%, transparent 50%),
              radial-gradient(ellipse at 50% 50%, rgba(59, 130, 246, 0.04) 0%, transparent 70%);
  animation: bgShift 20s ease-in-out infinite alternate;
  z-index: -1;
  pointer-events: none;
}

@keyframes bgShift {
  0% { transform: translate(0, 0) rotate(0deg); }
  50% { transform: translate(-3%, 2%) rotate(1deg); }
  100% { transform: translate(2%, -2%) rotate(-1deg); }
}

/* ---------- Screens ---------- */

.screen { display: none; }
.screen.active { display: flex; }

/* ---------- Login ---------- */

#login-screen {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-container {
  width: 100%;
  max-width: 420px;
}

.login-card {
  padding: 2.5rem;
  animation: slideUp 0.6s var(--transition-slow) both;
}

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

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

.login-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent-primary-soft);
  color: var(--accent-secondary);
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-glow);
}

.login-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 400;
}

.input-group {
  margin-bottom: 1.25rem;
}

.input-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.45rem;
  letter-spacing: 0.02em;
}

.input-group input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  transition: all var(--transition-fast);
  outline: none;
}

.input-group input:focus {
  border-color: var(--accent-primary);
  background: var(--bg-input-focus);
  box-shadow: 0 0 0 3px var(--accent-primary-soft);
}

.input-group input::placeholder {
  color: var(--text-muted);
}

.error-message {
  background: var(--color-danger-soft);
  color: var(--color-danger);
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 1rem;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.login-footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ---------- Glass Card ---------- */

.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  transition: all var(--transition-normal);
}

.glass-card:hover {
  border-color: rgba(255, 255, 255, 0.1);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.7rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  outline: none;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent-primary);
  color: white;
  box-shadow: 0 2px 12px var(--accent-primary-glow);
}

.btn-primary:hover:not(:disabled) {
  background: #5558e6;
  box-shadow: 0 4px 20px var(--accent-primary-glow);
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--accent-primary);
  color: var(--accent-secondary);
  background: var(--accent-primary-soft);
}

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

.btn-danger-outline:hover:not(:disabled) {
  background: var(--color-danger-soft);
  border-color: var(--color-danger);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover { color: var(--text-primary); background: rgba(255,255,255,0.05); }

.btn-sm { padding: 0.45rem 0.85rem; font-size: 0.8rem; }
.btn-full { width: 100%; }

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

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

/* ---------- Dashboard Layout ---------- */

#dashboard-screen {
  flex-direction: column;
  min-height: 100vh;
}

.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 14, 23, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 0.5rem; }
.header-right { display: flex; align-items: center; gap: 0.75rem; }

.logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--accent-primary-soft);
  color: var(--accent-secondary);
}

.logo-text {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

.user-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ---------- Dashboard Main ---------- */

.dashboard-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  width: 100%;
}

/* ---------- Status Bar ---------- */

.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition-normal);
}

.status-dot.connected {
  background: var(--color-success);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
  animation: pulse 2s ease-in-out infinite;
}

.status-dot.connecting,
.status-dot.need_qr {
  background: var(--color-warning);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
  animation: pulse 1.5s ease-in-out infinite;
}

.status-dot.disconnected {
  background: var(--color-danger);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}

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

#status-text {
  font-weight: 600;
  font-size: 0.9rem;
}

.status-actions {
  display: flex;
  gap: 0.5rem;
}

/* ---------- Dashboard Grid ---------- */

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.card {
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.75rem;
}

.card-header h2 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.card-header h2 svg {
  color: var(--text-muted);
}

.card-body {
  padding: 0 1.25rem 1.25rem;
}

.badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 100px;
  background: var(--accent-primary-soft);
  color: var(--accent-secondary);
}

/* ---------- QR Card ---------- */

.qr-card {
  grid-row: span 1;
}

.qr-body {
  display: flex;
  justify-content: center;
  padding-top: 0.5rem;
}

#qr-container {
  position: relative;
  width: 260px;
  height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#qr-image {
  width: 240px;
  height: 240px;
  border-radius: var(--radius-md);
  border: 3px solid var(--border);
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.qr-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

.qr-placeholder p {
  font-size: 0.85rem;
}

/* ---------- Info Grid ---------- */

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.info-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.info-value {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-primary);
}

/* ---------- Stats Row ---------- */

.stats-row {
  grid-column: span 2;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
}

.stat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.stat-icon-sent { background: var(--accent-primary-soft); color: var(--accent-secondary); }
.stat-icon-received { background: var(--color-info-soft); color: var(--color-info); }
.stat-icon-order { background: var(--color-warning-soft); color: var(--color-warning); }
.stat-icon-total { background: var(--color-success-soft); color: var(--color-success); }

.stat-content {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 0.15rem;
}

/* ---------- Log Card ---------- */

.log-card {
  grid-column: span 2;
}

.log-container {
  max-height: 240px;
  overflow-y: auto;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.78rem;
  line-height: 1.65;
}

.log-container::-webkit-scrollbar {
  width: 4px;
}

.log-container::-webkit-scrollbar-track {
  background: transparent;
}

.log-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 100px;
}

.log-entry {
  display: flex;
  gap: 0.75rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
  animation: logSlide 0.3s ease;
}

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

.log-time {
  color: var(--text-muted);
  flex-shrink: 0;
  min-width: 75px;
}

.log-level {
  font-weight: 600;
  flex-shrink: 0;
  min-width: 40px;
  text-transform: uppercase;
  font-size: 0.7rem;
  padding-top: 0.1rem;
}

.log-level.info { color: var(--color-info); }
.log-level.warn { color: var(--color-warning); }
.log-level.error { color: var(--color-danger); }

.log-message {
  color: var(--text-secondary);
  word-break: break-word;
}

.log-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 2rem;
  font-style: italic;
  font-family: 'Inter', sans-serif;
}

/* ---------- Toast Notifications ---------- */

.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.5rem;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.4s ease;
  backdrop-filter: blur(12px);
}

.toast.success { background: rgba(34, 197, 94, 0.9); color: white; }
.toast.error { background: rgba(239, 68, 68, 0.9); color: white; }
.toast.info { background: rgba(59, 130, 246, 0.9); color: white; }

.toast.leaving { animation: toastOut 0.3s ease forwards; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateY(12px) scale(0.95); }
}

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .stats-row {
    grid-column: span 1;
    grid-template-columns: repeat(2, 1fr);
  }

  .log-card { grid-column: span 1; }

  .status-bar {
    flex-direction: column;
    gap: 0.75rem;
    align-items: stretch;
  }

  .status-actions {
    justify-content: center;
  }

  .dashboard-main {
    padding: 1rem;
  }
}

@media (max-width: 480px) {
  .stats-row {
    grid-template-columns: 1fr;
  }

  .login-card {
    padding: 1.75rem;
  }

  .info-grid {
    grid-template-columns: 1fr;
  }
}
