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

:root {
  --blue: #1d8df7;
  --dark-blue: #0b5796;
  --orange: #ff8d0f;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-light: #6b7280;
  --border: #e2e8f0;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
}

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

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* === Auth Pages === */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-dark {
  background: var(--dark-blue);
}

.auth-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 420px;
}

.auth-top-logo {
  max-width: 280px;
  margin-bottom: 28px;
}

.auth-dark .auth-footer {
  color: rgba(255,255,255,0.7);
}

.auth-dark .auth-footer a {
  color: rgba(255,255,255,0.9);
}

.auth-card {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 420px;
}

.auth-card .logo {
  display: block;
  max-width: 220px;
  margin: 0 auto 24px;
}

.auth-card h1 {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
}

.auth-card p {
  text-align: center;
  color: var(--text-light);
  margin-bottom: 24px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s;
  background: var(--surface);
  color: var(--text);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29,141,247,0.12);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

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

.btn-orange {
  background: var(--orange);
  color: white;
}
.btn-orange:hover { background: #e67d00; }

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

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: #dc2626; }

.btn-full { width: 100%; }

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

.error-msg {
  background: #fef2f2;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid #fecaca;
}

.success-msg {
  background: #f0fdf4;
  color: var(--success);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid #bbf7d0;
}

.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: var(--text-light);
}

/* === Account Type Selection === */
.type-selection {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.type-cards {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 700px;
}

.type-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 300px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.type-card:hover {
  border-color: var(--blue);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.type-card .icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.type-card h3 {
  font-size: 20px;
  margin-bottom: 8px;
}

.type-card p {
  color: var(--text-light);
  font-size: 14px;
}

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

.sidebar {
  width: 260px;
  background: var(--dark-blue);
  color: white;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header .logo {
  max-width: 180px;
  display: block;
}

.sidebar-header .app-title {
  font-size: 18px;
  font-weight: 700;
  color: white;
}

.sidebar-nav {
  flex: 1;
  padding: 12px;
}

.sidebar-nav a, .sidebar-nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
  color: rgba(255,255,255,0.8);
  font-size: 14px;
  transition: all 0.15s;
  border: none;
  background: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  font-family: inherit;
  text-decoration: none;
}

.sidebar-nav a:hover, .sidebar-nav button:hover {
  background: rgba(255,255,255,0.1);
  color: white;
  text-decoration: none;
}

.sidebar-nav a.active, .sidebar-nav button.active {
  background: rgba(255,255,255,0.15);
  color: white;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-footer .user-info {
  padding: 10px 14px;
  font-size: 13px;
  color: rgba(255,255,255,0.6);
}

.sidebar-footer .usage-bar {
  margin: 8px 14px;
  height: 4px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  overflow: hidden;
}

.sidebar-footer .usage-bar .fill {
  height: 100%;
  background: var(--orange);
  border-radius: 2px;
  transition: width 0.3s;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* === Top Bar === */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.top-bar h2 {
  font-size: 20px;
  font-weight: 700;
}

.top-bar-actions {
  display: flex;
  gap: 10px;
}

/* === Dashboard === */
.dashboard-content {
  padding: 28px;
  flex: 1;
  overflow-y: auto;
}

.email-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.email-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.email-item-info h4 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 2px;
}

.email-item-info span {
  font-size: 13px;
  color: var(--text-light);
}

.email-item-meta {
  font-size: 13px;
  color: var(--text-light);
  text-align: right;
}

.email-item-actions {
  display: flex;
  gap: 14px;
  margin-top: 6px;
}

.email-item-actions a {
  font-size: 13px;
  font-weight: 500;
  color: var(--blue);
  cursor: pointer;
}

.email-item-actions a:hover {
  color: var(--dark-blue);
}

.email-item-actions a.delete-link {
  color: var(--danger);
}

.email-item-actions a.delete-link:hover {
  color: #dc2626;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}

.empty-state h3 {
  font-size: 18px;
  margin-bottom: 8px;
  color: var(--text);
}

.empty-state p {
  margin-bottom: 20px;
}

/* === Settings === */
.settings-content {
  padding: 28px;
  flex: 1;
  overflow-y: auto;
  max-width: 800px;
}

.settings-bottom-actions {
  padding: 8px 0 20px;
}

.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

.settings-section h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.slider-group {
  margin-bottom: 20px;
}

.slider-group label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
}

.slider-group label span {
  font-weight: 700;
  color: var(--blue);
}

.slider-group input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-light);
  margin-top: 4px;
}

/* === Chat Interface === */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 65px);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  max-width: 80%;
  display: flex;
  flex-direction: column;
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message.user .message-bubble {
  background: var(--blue);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message-time {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 4px;
  padding: 0 4px;
}

.message.user .message-time {
  text-align: right;
}

.chat-input-area {
  padding: 16px 28px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.chat-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input-row textarea {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  line-height: 1.4;
}

.chat-input-row textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29,141,247,0.12);
}

.chat-input-row .btn {
  height: 44px;
  min-width: 44px;
  padding: 0 16px;
}

.copy-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 28px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-light);
}

.copy-bar .btn {
  font-size: 13px;
  padding: 6px 14px;
}

/* Typing indicator */
.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-light);
  border-radius: 50%;
  animation: typing 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1); }
}

/* === Quick Options (for chat suggestions) === */
.quick-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.quick-option {
  padding: 8px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  color: var(--text);
}

.quick-option:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: rgba(29,141,247,0.05);
}

/* === Per-email sliders panel === */
.email-sliders-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  align-self: flex-start;
  max-width: 500px;
  width: 100%;
}

.email-sliders-panel .slider-group:last-of-type {
  margin-bottom: 0;
}

/* === Multi-select panel === */
.multiselect-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  align-self: flex-start;
  max-width: 500px;
  width: 100%;
}

.check-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 0;
  font-size: 14px;
  cursor: pointer;
  line-height: 1.4;
}

.check-item input[type="checkbox"] {
  accent-color: var(--blue);
  width: 16px;
  height: 16px;
  margin-top: 2px;
  flex-shrink: 0;
}

.other-text-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  margin: 4px 0;
}

.other-text-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29,141,247,0.12);
}

.other-inline-input {
  display: flex;
  align-items: center;
  width: 100%;
  margin-top: 8px;
  gap: 8px;
}

/* === Usage Bar === */
.usage-display {
  margin-top: 8px;
}

.usage-bar-track {
  width: 100%;
  height: 12px;
  background: #e0e0e0;
  border-radius: 6px;
  overflow: hidden;
}

.usage-bar-fill {
  height: 100%;
  background: #1d8df7;
  border-radius: 6px;
  transition: width 0.3s ease;
  min-width: 0;
}

.usage-text {
  font-size: 13px;
  color: var(--text-light);
  margin-top: 8px;
}

.success-msg {
  background: #f0fdf4;
  color: #166534;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 12px;
}

/* === Admin === */
.admin-container {
  min-height: 100vh;
  padding: 28px;
}

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

.admin-header h1 {
  font-size: 24px;
}

.admin-table {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.admin-table table {
  width: 100%;
  border-collapse: collapse;
}

.admin-table th {
  background: var(--bg);
  padding: 12px 16px;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.admin-table td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.admin-table tr:last-child td {
  border-bottom: none;
}

.admin-table input {
  width: 70px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}

.admin-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-active {
  background: #dcfce7;
  color: #166534;
}

.badge-paused {
  background: #fef9c3;
  color: #854d0e;
}

.badge-blocked {
  background: #fee2e2;
  color: #991b1b;
}

.admin-actions {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* === Agency Client List === */
.clients-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  padding: 28px;
}

.client-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  cursor: pointer;
  transition: all 0.15s;
}

.client-card:hover {
  border-color: var(--blue);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.client-card h4 {
  font-size: 16px;
  margin-bottom: 4px;
}

.client-card p {
  font-size: 13px;
  color: var(--text-light);
}

.add-client-card {
  border: 2px dashed var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  gap: 8px;
  min-height: 100px;
}

.add-client-card:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.add-client-card .plus {
  font-size: 32px;
  font-weight: 300;
}

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 28px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
}

.modal h3 {
  font-size: 18px;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* === Toast Notification === */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 2000;
  animation: slideUp 0.3s;
  box-shadow: var(--shadow-lg);
}

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

/* === Responsive === */
@media (max-width: 768px) {
  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    flex-direction: row;
    height: 60px;
    padding: 0;
  }

  .sidebar-header, .sidebar-footer {
    display: none;
  }

  .sidebar-nav {
    display: flex;
    padding: 0;
    justify-content: center;
    gap: 0;
  }

  .sidebar-nav a, .sidebar-nav button {
    padding: 8px 16px;
    font-size: 12px;
    justify-content: center;
    flex-direction: column;
    gap: 2px;
  }

  .main-content {
    margin-bottom: 60px;
  }

  .chat-container {
    height: calc(100vh - 60px - 65px);
  }

  .chat-messages {
    padding: 16px;
  }

  .message {
    max-width: 90%;
  }

  .type-cards {
    flex-direction: column;
    align-items: center;
  }

  .auth-card {
    padding: 28px;
  }

  .settings-content, .dashboard-content {
    padding: 16px;
  }

  .top-bar {
    padding: 12px 16px;
  }

  .chat-input-area {
    padding: 12px 16px;
  }

  .copy-bar {
    padding: 10px 16px;
  }

  .clients-grid {
    padding: 16px;
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .top-bar-actions {
    flex-direction: column;
  }

  .top-bar-actions .btn {
    font-size: 13px;
    padding: 8px 12px;
  }
}
