@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700;900&display=swap');
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css');

:root {
  --primary: #096A6D;
  --primary-light: #0e8588;
  --primary-dark: #065557;
  --primary-ultra-light: #e8f4f4;
  --secondary: #64748b;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --background: #f5f7fa;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --text: #1e293b;
  --text-light: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 40px rgba(9, 106, 109, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --sidebar-width: 260px;
  --header-height: 70px;
}

.tooltip {
  position: relative;
  display: inline-block;
}

.tooltip .tooltiptext {
  visibility: hidden;
  width: 280px;
  background-color: #333;
  color: #fff;
  text-align: left;
  border-radius: 8px;
  padding: 12px;
  position: absolute;
  z-index: 1000;
  bottom: 125%;
  left: 50%;
  margin-left: -140px;
  opacity: 0;
  transition: opacity 0.3s;
  font-size: 13px;
  font-weight: normal;
  line-height: 1.4;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.tooltip .tooltiptext::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: #333 transparent transparent transparent;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
  opacity: 1;
}

.tooltip-icon {
  color: var(--text-light);
  cursor: help;
  margin-left: 5px;
  font-size: 12px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.header-actions .search-input {
  width: 200px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
}

.header-actions .filter-select {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
}

.docs-card {
  background: white;
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.docs-card h3 {
  color: var(--primary);
  margin-bottom: 16px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.docs-card p, .docs-card li {
  color: var(--text-light);
  font-size: 0.9rem;
  line-height: 1.6;
}

.docs-card ul {
  margin: 10px 0;
  padding-left: 20px;
}

.docs-card code {
  background: var(--primary-ultra-light);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85rem;
  color: var(--primary-dark);
}

.docs-card .example {
  background: #f8f9fa;
  border-left: 3px solid var(--primary);
  padding: 12px;
  margin: 12px 0;
  font-size: 0.85rem;
}

.form-container {
  margin-bottom: 20px;
}

.form-container.hidden {
  display: none;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.form-row {
  display: flex;
  gap: 15px;
}

.form-row .form-group {
  flex: 1;
}

@media (max-width: 768px) {
  .form-row {
    flex-direction: column;
  }
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--background);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

body.with-sidebar .main-content {
  margin-left: var(--sidebar-width);
}

#sidebar-container {
  display: none;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size:rem; }
 1.125h4 { font-size: 1rem; }

.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }

/* Login Page */
#login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-ultra-light) 0%, var(--background) 100%);
  padding: 20px;
}

.login-container {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  padding: 48px 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-logo {
  width: 72px;
  height: 72px;
  background: var(--primary);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
}

.login-logo i {
  font-size: 32px;
  color: white;
}

.login-container h1 {
  color: var(--primary);
  margin-bottom: 8px;
}

.login-container .subtitle {
  color: var(--text-light);
  margin-bottom: 32px;
  font-weight: 500;
}

/* Forms */
.form-group {
  margin-bottom: 20px;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.form-group label .help-text {
  font-weight: 400;
  color: var(--text-light);
  font-size: 0.75rem;
  margin-left: 8px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-family: inherit;
  transition: all 0.2s ease;
  background: var(--surface);
  color: var(--text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(9, 106, 109, 0.1);
}

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

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 2px solid var(--border);
}

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

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

.btn-danger:hover {
  background: #dc2626;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 0.8125rem;
}

.btn-block {
  width: 100%;
}

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

/* Dashboard Layout */
#dashboard-page {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-header i {
  font-size: 24px;
  color: var(--primary);
}

.sidebar-brand {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  margin-bottom: 4px;
  text-decoration: none;
}

.nav-item:hover,
.nav-item:focus {
  background: var(--primary-ultra-light);
  color: var(--primary);
  text-decoration: none;
}

.nav-item.active {
  background: var(--primary);
  color: white;
  text-decoration: none;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-light);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

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

.user-details {
  flex: 1;
  min-width: 0;
}

.user-name {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-logout {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border: 2px solid var(--border);
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-logout:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: #fef2f2;
}

.btn-logout svg {
  width: 18px;
  height: 18px;
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  background: var(--background);
}

.section {
  display: none;
  padding: 32px;
  animation: fadeIn 0.3s ease;
}

.section.active {
  display: block;
}

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

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

.section-header h2 {
  color: var(--text);
}

/* Dashboard Stats */
.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.dash-stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  transition: all 0.2s ease;
}

.dash-stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.dash-stat-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-ultra-light);
}

.dash-stat-icon i {
  font-size: 24px;
  color: var(--primary);
}

.dash-stat-icon.success { background: #dcfce7; }
.dash-stat-icon.success i { color: #16a34a; }
.dash-stat-icon.warning { background: #fef3c7; }
.dash-stat-icon.warning i { color: #d97706; }
.dash-stat-icon.info { background: #e0f2fe; }
.dash-stat-icon.info i { color: #0284c7; }

.dash-stat-info {
  flex: 1;
}

.dash-stat-value {
  display: block;
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}

.dash-stat-label {
  display: block;
  font-size: 0.8125rem;
  color: var(--text-light);
  margin-top: 4px;
}

.dash-stat-sublabel {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 24px;
}

.dash-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.dash-card-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-light);
}

.dash-card-header h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1rem;
}

.dash-card-header h3 i {
  color: var(--primary);
}

.dash-card-body {
  padding: 20px 24px;
  min-height: 200px;
}

/* Cards */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  transition: all 0.2s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.card h3 {
  font-size: 1rem;
  margin-bottom: 8px;
}

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

.card .meta {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

/* Status Badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.status-badge.nuovo,
.status-badge.in_conversazione {
  background: #fef3c7;
  color: #92400e;
}

.status-badge.appuntamento_fissato,
.status-badge.confermato {
  background: #dcfce7;
  color: #166534;
}

.status-badge.perso,
.status-badge.cancellato {
  background: #fee2e2;
  color: #991b1b;
}

/* Filter */
.filter-group {
  display: flex;
  gap: 12px;
}

.filter-group select {
  padding: 10px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  background: var(--surface);
  cursor: pointer;
}

/* Chat */
.chat-container {
  display: flex;
  height: calc(100vh - var(--header-height) - 64px);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-sidebar {
  width: 320px;
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
}

.chat-sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-light);
}

.chat-sidebar-header h3 {
  font-size: 1rem;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
}

.chat-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  cursor: pointer;
  transition: background 0.2s ease;
  border-bottom: 1px solid var(--border-light);
}

.chat-list-item:hover {
  background: var(--surface-alt);
}

.chat-list-item.active {
  background: var(--primary-ultra-light);
}

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

.chat-info {
  flex: 1;
  min-width: 0;
}

.chat-info h4 {
  font-size: 0.9375rem;
  margin-bottom: 2px;
}

.chat-info p {
  font-size: 0.8125rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.chat-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-light);
  font-weight: 600;
}

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

.chat-message {
  max-width: 70%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 0.9375rem;
}

.chat-message.incoming {
  background: var(--surface-alt);
  align-self: flex-start;
  border-bottom-left-radius: var(--radius-sm);
}

.chat-message.outgoing {
  background: var(--primary);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: var(--radius-sm);
}

.chat-input {
  display: flex;
  gap: 12px;
  padding: 20px 24px;
  border-top: 1px solid var(--border-light);
  background: var(--surface-alt);
}

.chat-input input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 0.9375rem;
}

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

.chat-input button {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: var(--radius-full);
}

.chat-input button svg {
  width: 20px;
  height: 20px;
}

/* Settings */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 24px;
  margin-bottom: 24px;
}

.settings-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.settings-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-light);
}

.settings-card-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-card-icon.wa { background: #dcfce7; color: #16a34a; }
.settings-card-icon.ai { background: #e0f2fe; color: #0284c7; }
.settings-card-icon.time { background: #fef3c7; color: #d97706; }
.settings-card-icon.reminder { background: #f3e8ff; color: #9333ea; }
.settings-card-icon.calendar { background: #e0f2fe; color: #0284c7; }

.settings-card-header h3 {
  font-size: 1rem;
}

.settings-card-body {
  padding: 24px;
}

.wa-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  font-size: 0.875rem;
}

.wa-status-indicator {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--danger);
}

.wa-status-indicator.connected {
  background: var(--success);
}

.wa-qr {
  text-align: center;
  padding: 20px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
}

.wa-qr p {
  margin-bottom: 12px;
  font-size: 0.875rem;
  color: var(--text-light);
}

.wa-qr img {
  max-width: 200px;
  border-radius: var(--radius-sm);
}

.wa-buttons {
  display: flex;
  gap: 12px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-size: 0.9375rem;
}

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

.reminder-guide {
  margin-top: 20px;
  padding: 16px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
}

.reminder-guide h4 {
  font-size: 0.875rem;
  margin-bottom: 12px;
}

.reminder-guide ul {
  list-style: none;
}

.reminder-guide li {
  font-size: 0.8125rem;
  color: var(--text-light);
  margin-bottom: 6px;
}

.reminder-guide code {
  background: var(--border-light);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
}

.btn-save {
  max-width: 300px;
}

/* Appointments Section */
.appointments-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.appointments-header h3 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.next-appointments-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 32px;
}

.next-appointment-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.next-appointment-card .apt-date {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 16px;
  background: var(--primary-ultra-light);
  border-radius: var(--radius-sm);
  min-width: 70px;
}

.next-appointment-card .apt-date .day {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}

.next-appointment-card .apt-date .month {
  font-size: 0.75rem;
  color: var(--primary);
  text-transform: uppercase;
  font-weight: 600;
}

.next-appointment-card .apt-info {
  flex: 1;
}

.next-appointment-card .apt-info h4 {
  font-size: 0.9375rem;
  margin-bottom: 4px;
}

.next-appointment-card .apt-info .time {
  font-size: 0.8125rem;
  color: var(--text-light);
}

.next-appointment-card .apt-status {
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
}

/* Calendar */
.calendar-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.calendar-nav button {
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#cal-week-label {
  font-weight: 600;
  min-width: 200px;
  text-align: center;
}

.calendar-view {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.cal-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: var(--primary-ultra-light);
}

.cal-header > div {
  padding: 14px;
  text-align: center;
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--primary);
}

.cal-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.cal-day {
  min-height: 100px;
  padding: 8px;
  border-right: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
}

.cal-day:last-child {
  border-right: none;
}

.cal-day.other-month {
  background: var(--surface-alt);
  opacity: 0.5;
}

.cal-day.today {
  background: var(--primary-ultra-light);
}

.cal-day-number {
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 6px;
}

.cal-day.today .cal-day-number {
  color: var(--primary);
}

.cal-event {
  padding: 4px 6px;
  margin-bottom: 4px;
  border-radius: 4px;
  font-size: 0.6875rem;
  background: var(--primary);
  color: white;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-event:hover {
  background: var(--primary-dark);
}

.cal-no-events {
  font-size: 0.6875rem;
  color: var(--text-muted);
  text-align: center;
  padding: 4px;
}

/* Activity List */
.activity-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.activity-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-alt);
  color: var(--primary);
  flex-shrink: 0;
}

.activity-icon.lead { background: #e0f2fe; color: #0284c7; }
.activity-icon.appointment { background: #dcfce7; color: #16a34a; }
.activity-icon.message { background: #f3e8ff; color: #9333ea; }

.activity-content {
  flex: 1;
}

.activity-content h4 {
  font-size: 0.9375rem;
  margin-bottom: 4px;
}

.activity-content p {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.activity-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

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

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow-lg);
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-light);
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: var(--border);
  color: var(--text);
}

.modal-close svg {
  width: 18px;
  height: 18px;
}

.modal-content h3 {
  margin-bottom: 24px;
  padding-right: 32px;
}

.modal-content .btn {
  margin-top: 8px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-card .stat-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-ultra-light);
}

.stat-card .stat-icon i {
  font-size: 28px;
  color: var(--primary);
}

.stat-card .stat-icon.active {
  background: #dcfce7;
}

.stat-card .stat-icon.active i {
  color: #16a34a;
}

.stat-card h3 {
  font-size: 0.9375rem;
  color: var(--text-light);
  margin-bottom: 8px;
}

.stat-card p {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--text);
}

/* Error Message */
.error-message {
  color: var(--danger);
  font-size: 0.875rem;
  margin-top: 12px;
  text-align: center;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-light);
}

.empty-state i {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 0.9375rem;
}

/* Responsive */
@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  
  .chat-container {
    flex-direction: column;
  }
  
  .chat-sidebar {
    width: 100%;
    max-height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--border-light);
  }
}

@media (max-width: 768px) {
  :root {
    --sidebar-width: 0px;
  }
  
  .sidebar {
    transform: translateX(-100%);
  }
  
  .sidebar.open {
    transform: translateX(0);
    width: 280px;
  }
  
  .main-content {
    margin-left: 0;
  }
  
  .section {
    padding: 20px;
  }
  
  .dashboard-stats {
    grid-template-columns: 1fr;
  }
  
  .settings-grid {
    grid-template-columns: 1fr;
  }
  
  .card-grid {
    grid-template-columns: 1fr;
  }
  
  .next-appointment-card {
    flex-wrap: wrap;
  }
  
  .calendar-nav {
    gap: 8px;
  }
  
  #cal-week-label {
    font-size: 0.875rem;
    min-width: auto;
  }
  
  .mobile-menu-btn {
    display: flex;
  }
  
  .section-header {
    flex-direction: column;
    gap: 16px;
    align-items: stretch;
  }
  
  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }
  
  .header-actions .search-input {
    flex: 1;
    min-width: 120px;
    width: auto;
  }
  
  .header-actions .filter-select {
    flex: 1;
    min-width: 120px;
    width: auto;
  }
  
  .filter-group {
    width: 100%;
  }
  
  .filter-group select {
    flex: 1;
  }
}

/* Mobile Menu Button */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 99;
  width: 44px;
  height: 44px;
  border: none;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.mobile-menu-btn i {
  font-size: 20px;
  color: var(--primary);
}

@media (max-width: 768px) {
  .mobile-menu-btn {
    display: flex;
  }
  
  .main-content {
    padding-top: 60px;
  }
  
  .section-header h2 {
    padding-left: 44px;
  }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

@media (max-width: 768px) {
  .sidebar-overlay.open {
    display: block;
  }
}

/* Utility */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.p-4 { padding: 16px; }

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--surface-alt);
  color: var(--text-light);
}

.badge.success { background: #dcfce7; color: #166534; }
.badge.warning { background: #fef3c7; color: #92400e; }
.badge.danger { background: #fee2e2; color: #991b1b; }

/* AI Prompt Builder */
.modal-lg {
  max-width: 600px;
}

.modal-desc {
  color: var(--text-light);
  margin-bottom: 20px;
  font-size: 0.9rem;
}

.ai-prompt-chat {
  background: var(--surface-alt);
  border-radius: var(--radius);
  padding: 15px;
  margin-bottom: 20px;
  max-height: 200px;
  overflow-y: auto;
}

.chat-message {
  margin-bottom: 10px;
}

.chat-message.ai {
  background: white;
  padding: 12px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--primary);
}

.chat-message.ai p {
  margin: 5px 0;
  font-size: 0.9rem;
}

.chat-message.user {
  background: var(--primary-ultra-light);
  padding: 10px;
  border-radius: var(--radius-sm);
}

.ai-prompt-questions {
  display: none;
}

.ai-prompt-questions.active {
  display: block;
}

.question-step {
  display: none;
}

.question-step.active {
  display: block;
}

.question-step label {
  display: block;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
}

.question-step input,
.question-step textarea {
  width: 100%;
  margin-bottom: 15px;
}

.question-step .btn {
  margin-right: 10px;
}

.ai-prompt-result {
  display: none;
}

.ai-prompt-result.active {
  display: block;
}

.ai-prompt-result.hidden {
  display: none;
}

.ai-prompt-result h4 {
  color: var(--primary);
  margin-bottom: 10px;
}

.ai-prompt-result textarea {
  width: 100%;
  font-family: monospace;
  font-size: 0.85rem;
  margin-bottom: 15px;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
  padding: 4px 10px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-left: 10px;
}

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

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}

label .btn-outline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.tool-options {
  margin-top: 15px;
  padding: 15px;
  background: var(--surface-hover);
  border-radius: var(--radius);
}

.tool-options .form-group {
  margin-bottom: 12px;
}

.tool-options .form-group:last-child {
  margin-bottom: 0;
}

select[multiple] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  min-height: 100px;
}

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.conditions-builder {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.condition-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.condition-row select,
.condition-row input {
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.condition-row select {
  min-width: 120px;
}

.condition-row input {
  flex: 1;
}

.file-drop-zone {
  border: 2px dashed #e5e7eb;
  border-radius: 12px;
  padding: 32px;
  text-align: center;
  background: #f9fafb;
  transition: all 0.2s ease;
  cursor: pointer;
}

.file-drop-zone:hover {
  border-color: #0a6a6d;
  background: #f0fdfa;
}

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 24px;
}

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

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.4s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: #22c55e;
}

input:checked + .slider:before {
  transform: translateX(24px);
}
