/* ============================================================
   app.css — AI Receptionist Dashboard Styles
   ============================================================
   Design: Clean, professional, dark sidebar + light content.
   Optimized for a business owner checking their call dashboard
   quickly, often on mobile.
   ============================================================ */

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

:root {
  /* Brand colors */
  --brand:       #4F6EF7;   /* Indigo — primary action */
  --brand-dark:  #3A58E0;
  --brand-light: #EEF1FE;

  /* Sidebar */
  --sidebar-bg:   #111827;  /* Very dark navy */
  --sidebar-text: #9CA3AF;
  --sidebar-active-bg: #1F2937;
  --sidebar-active-text: #FFFFFF;

  /* Content area */
  --bg:          #F9FAFB;
  --surface:     #FFFFFF;
  --border:      #E5E7EB;
  --border-soft: #F3F4F6;

  /* Text */
  --text-primary:   #111827;
  --text-secondary: #6B7280;
  --text-muted:     #9CA3AF;

  /* Status colors */
  --green:  #10B981;
  --green-bg: #ECFDF5;
  --amber:  #F59E0B;
  --amber-bg: #FFFBEB;
  --red:    #EF4444;
  --red-bg: #FEF2F2;
  --blue:   #3B82F6;
  --blue-bg: #EFF6FF;

  /* Layout */
  --sidebar-width: 220px;
  --header-h:      64px;
  --radius:        8px;
  --radius-lg:     12px;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:     0 4px 16px rgba(0,0,0,.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg);
  line-height: 1.5;
}

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

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

/* --- Sidebar ------------------------------------------------ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.brand-icon { font-size: 20px; }

.brand-name {
  font-size: 14px;
  font-weight: 600;
  color: #FFFFFF;
  letter-spacing: -0.01em;
}

.admin-tag {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .06em;
  background: var(--brand);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: auto;
}

.nav-links {
  list-style: none;
  padding: 12px 8px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 6px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s, color .15s;
  margin-bottom: 2px;
  text-decoration: none;
}

.nav-link:hover { background: var(--sidebar-active-bg); color: #FFFFFF; text-decoration: none; }
.nav-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); }

.nav-icon { font-size: 15px; width: 20px; text-align: center; }

.badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.06);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-name {
  font-size: 12px;
  color: var(--sidebar-text);
  truncate: ellipsis;
}

.btn-logout {
  background: transparent;
  border: 1px solid rgba(255,255,255,.12);
  color: var(--sidebar-text);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s;
}

.btn-logout:hover { background: rgba(255,255,255,.06); color: #fff; }

/* --- Main Content ------------------------------------------ */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 32px;
  min-width: 0;
}

/* --- Page Header ------------------------------------------- */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.page-subtitle {
  color: var(--text-secondary);
  margin-top: 2px;
  font-size: 13.5px;
}

.header-date {
  color: var(--text-muted);
  font-size: 13px;
  padding-top: 4px;
}

.back-link {
  font-size: 13px;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 6px;
}

/* --- Stats Cards ------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-card--alert { border-left: 3px solid var(--amber); }

.stat-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  line-height: 1;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* --- Sections ---------------------------------------------- */
.section { margin-bottom: 32px; }

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

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.section-desc {
  color: var(--text-secondary);
  font-size: 13.5px;
  margin-bottom: 16px;
}

.link-more { font-size: 13px; color: var(--brand); }

/* --- Tables ------------------------------------------------ */
.table-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}

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

.data-table th {
  background: var(--border-soft);
  padding: 10px 16px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-secondary);
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13.5px;
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #FAFAFA; }

.loading-cell {
  text-align: center;
  color: var(--text-muted);
  padding: 40px !important;
}

/* --- Buttons ----------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, transform .1s;
  text-decoration: none;
}

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

.btn--primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.btn--primary:hover { background: var(--brand-dark); text-decoration: none; }

.btn--secondary {
  background: var(--surface);
  color: var(--brand);
  border-color: var(--brand);
}
.btn--secondary:hover { background: var(--brand-light); text-decoration: none; }

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn--ghost:hover { background: var(--border-soft); text-decoration: none; }

.btn--full { width: 100%; justify-content: center; }
.btn--sm { padding: 5px 10px; font-size: 12px; }

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

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color .15s;
  font-family: inherit;
}

.form-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(79,110,247,.12);
}

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

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

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

/* --- Alerts ------------------------------------------------ */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  margin-bottom: 16px;
}

.alert--error { background: var(--red-bg); color: var(--red); border: 1px solid #FCA5A5; }
.alert--success { background: var(--green-bg); color: #059669; border: 1px solid #6EE7B7; }

/* --- Status Badges ----------------------------------------- */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.status-badge--completed { background: var(--green-bg); color: #059669; }
.status-badge--in_progress { background: var(--blue-bg); color: var(--blue); }
.status-badge--failed { background: var(--red-bg); color: var(--red); }
.status-badge--pending { background: var(--amber-bg); color: #D97706; }
.status-badge--confirmed { background: var(--green-bg); color: #059669; }
.status-badge--cancelled { background: var(--red-bg); color: var(--red); }

/* --- Transcript -------------------------------------------- */
.transcript {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.transcript-msg {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.transcript-msg--ai { flex-direction: row; }
.transcript-msg--user { flex-direction: row-reverse; }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.msg-avatar--ai { background: var(--brand-light); }
.msg-avatar--user { background: var(--border-soft); }

.msg-bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.5;
}

.msg-bubble--ai {
  background: var(--brand-light);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.msg-bubble--user {
  background: var(--border-soft);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
}

/* --- Summary Box ------------------------------------------- */
.summary-box {
  background: var(--brand-light);
  border: 1px solid #C7D2FE;
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
}

/* --- Detail Meta ------------------------------------------- */
.detail-meta-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}

.meta-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.meta-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: 4px; }
.meta-value { font-size: 15px; font-weight: 600; color: var(--text-primary); }

/* --- Message Cards ----------------------------------------- */
.message-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.message-card--unread { border-left: 3px solid var(--brand); }

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

.message-from { font-weight: 600; font-size: 14px; }
.message-time { font-size: 12px; color: var(--text-muted); }
.message-body { font-size: 13.5px; color: var(--text-secondary); line-height: 1.5; }
.message-phone { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* --- FAQ List ---------------------------------------------- */
.faq-add-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
}

.faq-list { display: flex; flex-direction: column; gap: 10px; }

.faq-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.faq-qa { flex: 1; }
.faq-question { font-weight: 600; font-size: 13.5px; margin-bottom: 4px; }
.faq-answer { font-size: 13px; color: var(--text-secondary); }

/* --- Filter Bar -------------------------------------------- */
.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.filter-search { flex: 1; }
.filter-select { width: 200px; }

/* --- Pagination -------------------------------------------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 20px;
}

.page-info { font-size: 13px; color: var(--text-secondary); }

/* --- Empty State ------------------------------------------- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state p { font-size: 13.5px; }

/* --- Auth Pages -------------------------------------------- */
.auth-page {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.auth-container { width: 100%; max-width: 400px; padding: 20px; }

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  box-shadow: var(--shadow-md);
}

.auth-brand { text-align: center; margin-bottom: 32px; }
.auth-logo { font-size: 36px; margin-bottom: 12px; }
.auth-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.auth-subtitle { color: var(--text-secondary); font-size: 13.5px; margin-top: 4px; }
.auth-form { margin-bottom: 16px; }
.auth-footer { text-align: center; font-size: 12px; color: var(--text-muted); }

/* --- Intent tags ------------------------------------------- */
.intent-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11.5px;
  font-weight: 500;
}

.intent-tag--appointment_booking { background: var(--green-bg); color: #059669; }
.intent-tag--message_taking { background: var(--blue-bg); color: var(--blue); }
.intent-tag--general_inquiry { background: var(--amber-bg); color: #D97706; }
.intent-tag--other { background: var(--border-soft); color: var(--text-muted); }

/* --- Responsive -------------------------------------------- */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .detail-meta-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr; }
  .detail-meta-grid { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; }
  .filter-select { width: 100%; }
  .auth-card { padding: 24px; }
}