/**
 * WhatsApp Bot TJ - User Dashboard Styles
 * v1.5.2-beta.1
 * Mobile-First Design
 */

/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* WhatsApp Colors */
  --primary: #25D366;
  --primary-dark: #128C7E;
  --secondary: #075E54;
  --background: #f0f2f5;
  --surface: #ffffff;
  --text: #111b21;
  --text-light: #667781;
  --border: #e9edef;
  --error: #ea0038;
  --success: #00a884;

  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Shadow */
  --shadow: 0 1px 3px rgba(11, 20, 26, 0.08);
  --shadow-lg: 0 2px 8px rgba(11, 20, 26, 0.12);

  /* Safe area for notch devices */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background-color: var(--background);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Utilities */
.hidden {
  display: none !important;
}

/* ===================== */
/* LOGIN SCREEN          */
/* ===================== */

#login-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--secondary) 0%, var(--secondary) 30%, var(--background) 30%);
  padding: var(--spacing-md);
  padding-top: calc(var(--safe-top) + var(--spacing-xl));
}

.login-header {
  text-align: center;
  color: white;
  margin-bottom: var(--spacing-xl);
}

.login-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: var(--spacing-xs);
}

.login-header .version {
  font-size: 0.75rem;
  opacity: 0.8;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}

.login-card h2 {
  font-size: 1.25rem;
  margin-bottom: var(--spacing-lg);
  text-align: center;
}

/* Form */
.form-group {
  margin-bottom: var(--spacing-md);
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-light);
  margin-bottom: var(--spacing-xs);
}

.form-group input {
  width: 100%;
  padding: var(--spacing-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--surface);
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.15);
}

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

/* Buttons */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: var(--spacing-md);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

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

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

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

/* Error Message */
.error-message {
  margin-top: var(--spacing-md);
  padding: var(--spacing-sm) var(--spacing-md);
  background-color: #ffeef0;
  border-radius: var(--radius-sm);
  color: var(--error);
  font-size: 0.875rem;
  text-align: center;
}

/* Remember me */
.form-checkbox {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-lg);
}

.form-checkbox input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.form-checkbox label {
  font-size: 0.875rem;
  color: var(--text-light);
  cursor: pointer;
}

/* ===================== */
/* DASHBOARD SCREEN      */
/* ===================== */

#dashboard-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
}

/* Header */
.header {
  background: var(--secondary);
  color: white;
  padding: var(--spacing-md);
  padding-top: calc(var(--safe-top) + var(--spacing-md));
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.menu-btn {
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: var(--spacing-xs);
  -webkit-tap-highlight-color: transparent;
}

.header h1 {
  font-size: 1.125rem;
  font-weight: 600;
}

.header-version {
  font-size: 0.625rem;
  opacity: 0.7;
  background: rgba(255, 255, 255, 0.15);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

/* Bot Status Indicator */
.bot-status {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  font-size: 0.75rem;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  cursor: pointer;
}

.bot-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-light);
  animation: pulse 2s infinite;
}

.bot-status.online .bot-status-dot {
  background: #4ade80;
  box-shadow: 0 0 6px #4ade80;
}

.bot-status.offline .bot-status-dot {
  background: #f87171;
  box-shadow: 0 0 6px #f87171;
  animation: none;
}

.bot-status.loading .bot-status-dot {
  background: #fbbf24;
  animation: pulse 1s infinite;
}

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

.bot-status-text {
  color: rgba(255, 255, 255, 0.9);
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
}

/* Main Content */
.main-content {
  flex: 1;
  padding: var(--spacing-md);
  overflow-y: auto;
}

/* Welcome Card */
.welcome-card {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: var(--spacing-lg);
  border-radius: var(--radius-md);
  margin-bottom: var(--spacing-md);
}

.welcome-card h2 {
  font-size: 1.25rem;
  margin-bottom: var(--spacing-xs);
}

.welcome-card p {
  font-size: 0.875rem;
  opacity: 0.9;
}

/* Feature Cards */
.feature-grid {
  display: grid;
  gap: var(--spacing-md);
}

.feature-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: var(--spacing-lg);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.feature-card:active {
  transform: scale(0.98);
}

.feature-card:hover {
  box-shadow: var(--shadow-lg);
}

.feature-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}

.feature-icon.messages {
  background: #e7f8f0;
  color: var(--success);
}

.feature-icon.settings {
  background: #e8f4fd;
  color: #0088cc;
}

.feature-icon.history {
  background: #fef3e7;
  color: #f5a623;
}

.feature-info h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: var(--spacing-xs);
}

.feature-info p {
  font-size: 0.875rem;
  color: var(--text-light);
}

.feature-badge {
  margin-left: auto;
  background: var(--error);
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

/* Footer */
.footer {
  padding: var(--spacing-md);
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-light);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ===================== */
/* SIDEBAR (Mobile)      */
/* ===================== */

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.sidebar-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  max-width: 80vw;
  background: var(--surface);
  z-index: 201;
  transform: translateX(-100%);
  transition: transform 0.3s;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
}

.sidebar.active {
  transform: translateX(0);
}

.sidebar-header {
  background: var(--secondary);
  color: white;
  padding: var(--spacing-lg);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.sidebar-avatar {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1.25rem;
}

.sidebar-name {
  font-weight: 600;
  margin-bottom: var(--spacing-xs);
}

.sidebar-email {
  font-size: 0.875rem;
  opacity: 0.8;
}

.sidebar-menu {
  flex: 1;
  padding: var(--spacing-md) 0;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  padding: var(--spacing-md) var(--spacing-lg);
  color: var(--text);
  text-decoration: none;
  transition: background 0.2s;
  cursor: pointer;
}

.sidebar-item:hover {
  background: var(--background);
}

.sidebar-item.active {
  background: #e7f8f0;
  color: var(--primary-dark);
}

.sidebar-item-icon {
  font-size: 1.25rem;
  width: 24px;
  text-align: center;
}

.sidebar-footer {
  padding: var(--spacing-md) var(--spacing-lg);
  border-top: 1px solid var(--border);
}

.logout-btn {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  color: var(--error);
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  padding: var(--spacing-sm) 0;
  width: 100%;
}

/* ===================== */
/* RESPONSIVE            */
/* ===================== */

@media (min-width: 768px) {
  .feature-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .main-content {
    max-width: 800px;
    margin: 0 auto;
    padding: var(--spacing-lg);
  }
}

@media (min-width: 1024px) {
  .feature-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* PWA Install Banner */
.install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  padding: var(--spacing-md);
  padding-bottom: calc(var(--safe-bottom) + var(--spacing-md));
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  z-index: 100;
}

.install-banner p {
  flex: 1;
  font-size: 0.875rem;
}

.install-banner .btn {
  width: auto;
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: 0.875rem;
}

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

/* ===================== */
/* SETTINGS SCREEN       */
/* ===================== */

#settings-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
}

.back-btn {
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: var(--spacing-xs);
  -webkit-tap-highlight-color: transparent;
}

.settings-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: var(--spacing-lg);
  box-shadow: var(--shadow);
}

.settings-card h3 {
  font-size: 1.125rem;
  margin-bottom: var(--spacing-xs);
}

.settings-desc {
  color: var(--text-light);
  font-size: 0.875rem;
  margin-bottom: var(--spacing-lg);
}

.status-message {
  margin-top: var(--spacing-md);
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 0.875rem;
}

.status-message.success {
  background: #e7f8f0;
  color: var(--success);
}

.status-message.error {
  background: #ffeef0;
  color: var(--error);
}

/* Phone Saved Box */
.phone-saved-box {
  background: #e7f8f0;
  border: 2px solid var(--success);
  border-radius: var(--radius-md);
  padding: var(--spacing-lg);
  text-align: center;
}

.phone-saved-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  color: var(--success);
  font-weight: 600;
  margin-bottom: var(--spacing-md);
}

.phone-saved-icon {
  width: 24px;
  height: 24px;
  background: var(--success);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
}

.phone-saved-number {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--spacing-lg);
  letter-spacing: 1px;
}

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

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

/* ===================== */
/* PHONE INPUT GROUP     */
/* ===================== */

.phone-input-group {
  display: flex;
  gap: var(--spacing-sm);
  align-items: stretch;
}

.country-selector {
  position: relative;
  flex-shrink: 0;
}

.country-btn {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  font-size: 1rem;
  height: 100%;
  min-width: 100px;
}

.country-btn:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.15);
}

.country-flag {
  font-size: 1.25rem;
}

.country-code {
  font-weight: 500;
  color: var(--text);
}

.country-arrow {
  font-size: 0.625rem;
  color: var(--text-light);
  margin-left: auto;
}

.country-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  margin-top: var(--spacing-xs);
  max-height: 250px;
  overflow-y: auto;
}

.country-option {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-md);
  cursor: pointer;
  transition: background 0.15s;
}

.country-option:hover {
  background: var(--background);
}

.country-option.selected {
  background: #e7f8f0;
  color: var(--primary-dark);
}

.phone-input-group input {
  flex: 1;
  min-width: 0;
}

/* ===================== */
/* QR CODE               */
/* ===================== */

.feature-icon.qrcode {
  background: #e8f5e9;
  color: #2e7d32;
}

.qrcode-container {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: var(--spacing-md);
}

.qrcode-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--spacing-xl);
  text-align: center;
  max-width: 350px;
  width: 100%;
  animation: slideUp 0.3s ease;
}

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

.qrcode-box h3 {
  margin-bottom: var(--spacing-md);
  color: var(--secondary);
}

.qrcode-image {
  background: white;
  padding: var(--spacing-md);
  border-radius: var(--radius-md);
  margin-bottom: var(--spacing-md);
  min-height: 256px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qrcode-image img {
  max-width: 100%;
  height: auto;
}

.qrcode-loading {
  color: var(--text-light);
}

.qrcode-error {
  color: var(--error);
  font-size: 0.875rem;
  text-align: center;
  padding: var(--spacing-md);
}

/* QR Code Status */
.qrcode-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-lg);
  text-align: center;
}

.qrcode-status-icon {
  font-size: 3rem;
}

.qrcode-status.connected {
  color: var(--success);
}

.qrcode-status.waiting {
  color: var(--text-light);
}

.qrcode-phone {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--primary-dark);
  margin-bottom: var(--spacing-md);
}

.qrcode-instructions {
  font-size: 0.875rem;
  color: var(--text-light);
  margin-bottom: var(--spacing-lg);
  line-height: 1.6;
}

/* ===================== */
/* WORKFLOW SELECTOR     */
/* ===================== */

/* Workflow Card Icon */
.feature-icon.workflow {
  background: #fff3e0;
  color: #e65100;
}

/* Modal Overlay (Generic) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: var(--spacing-md);
  overflow-y: auto;
}

/* Workflow Modal */
.workflow-modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}

.workflow-modal h3 {
  color: var(--secondary);
  margin-bottom: var(--spacing-xs);
}

.modal-subtitle {
  color: var(--text-light);
  font-size: 0.875rem;
  margin-bottom: var(--spacing-lg);
}

/* Workflow Options */
.workflow-options {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
}

.workflow-option {
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--spacing-md);
  cursor: pointer;
  transition: all 0.2s;
}

.workflow-option:hover:not(.disabled) {
  border-color: var(--primary);
  background: #f0fdf4;
}

.workflow-option.active {
  border-color: var(--primary);
  background: #f0fdf4;
}

.workflow-option.disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--background);
}

.workflow-header {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-sm);
}

.workflow-icon {
  font-size: 1.5rem;
}

.workflow-option h4 {
  font-size: 1rem;
  margin: 0;
}

.workflow-badge {
  font-size: 0.625rem;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--border);
  color: var(--text-light);
  margin-left: var(--spacing-xs);
}

.workflow-badge.active {
  background: var(--primary);
  color: white;
}

.workflow-badge.coming-soon {
  background: #fef3c7;
  color: #92400e;
}

.workflow-option p {
  font-size: 0.875rem;
  color: var(--text);
  margin-bottom: var(--spacing-sm);
}

.workflow-option ul {
  font-size: 0.75rem;
  color: var(--text-light);
  margin: 0;
  padding-left: var(--spacing-lg);
}

.workflow-option ul li {
  margin-bottom: 2px;
}

/* Modal Actions */
.modal-actions {
  display: flex;
  gap: var(--spacing-sm);
  margin-top: var(--spacing-lg);
}

.modal-actions .btn {
  flex: 1;
}
