/* ============================================================
   PrismEQ - Global Styles
   WhatsApp-inspired dark green theme
   ============================================================ */

/* ----- CSS Custom Properties ----- */
:root {
  /* Brand colors */
  --wa-dark-green: #075e54;
  --wa-teal: #128c7e;
  --wa-light-green: #25d366;
  --wa-chat-bg: #ece5dd;
  --wa-sent-bubble: #dcf8c6;
  --wa-received-bubble: #ffffff;
  --wa-header-bg: #075e54;
  --wa-sidebar-bg: #111b21;

  /* Neutrals */
  --bg-primary: #f0f2f5;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --text-primary: #111b21;
  --text-secondary: #667781;
  --text-muted: #8696a0;
  --border-color: #e9edef;
  --border-light: #f0f2f5;

  /* Functional */
  --success: #25d366;
  --warning: #f59f00;
  --danger: #ef4444;
  --info: #3b82f6;

  /* Grade colors */
  --grade-a: #25d366;
  --grade-b: #6dd400;
  --grade-c: #f59f00;
  --grade-d: #f76707;
  --grade-f: #ef4444;

  /* Trend arrows */
  --trend-up: #25d366;
  --trend-down: #ef4444;
  --trend-neutral: #8696a0;

  /* Layout */
  --sidebar-width: 240px;
  --sidebar-collapsed-width: 64px;
  --header-height: 56px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms ease;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #111b21;
    --bg-secondary: #1f2c34;
    --bg-card: #1f2c34;
    --text-primary: #e9edef;
    --text-secondary: #8696a0;
    --text-muted: #667781;
    --border-color: #2a3942;
    --border-light: #233138;
    --wa-chat-bg: #0b141a;
    --wa-sent-bubble: #005c4b;
    --wa-received-bubble: #1f2c34;
    --wa-sidebar-bg: #111b21;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
  }
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

a {
  color: var(--wa-teal);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--wa-dark-green);
}

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

/* ----- Typography ----- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.1rem; }

/* ============================================================
   NAVIGATION - Fixed sidebar
   ============================================================ */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--wa-sidebar-bg);
  color: #e9edef;
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: width var(--transition-normal);
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  min-height: var(--header-height);
}

.sidebar-header .logo {
  width: 32px;
  height: 32px;
  background: var(--wa-light-green);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.sidebar-header .app-name {
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-nav {
  flex: 1;
  padding: 8px 0;
  overflow-y: auto;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  color: #aebac1;
  font-size: 0.9rem;
  transition: all var(--transition-fast);
  border-left: 3px solid transparent;
  white-space: nowrap;
}

.sidebar-nav a:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #e9edef;
}

.sidebar-nav a.active {
  background: rgba(37, 211, 102, 0.1);
  color: var(--wa-light-green);
  border-left-color: var(--wa-light-green);
}

.sidebar-nav a .nav-icon {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.15rem;
}

.sidebar-nav a .nav-label {
  overflow: hidden;
}

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

.sidebar-footer .user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: #aebac1;
}

.sidebar-footer .user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--wa-teal);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.8rem;
  color: #fff;
  flex-shrink: 0;
}

/* Main content area shifts for sidebar */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  transition: margin-left var(--transition-normal);
}

/* ============================================================
   AUTH PAGES - Centered card
   ============================================================ */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: linear-gradient(135deg, var(--wa-dark-green) 0%, var(--wa-teal) 100%);
}

.auth-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  animation: fadeInUp 0.4s ease;
}

.auth-card .auth-logo {
  text-align: center;
  margin-bottom: 24px;
}

.auth-card .auth-logo .logo-icon {
  width: 64px;
  height: 64px;
  background: var(--wa-light-green);
  border-radius: var(--radius-lg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin-bottom: 12px;
}

.auth-card .auth-logo h1 {
  font-size: 1.3rem;
  color: var(--text-primary);
}

.auth-card .auth-logo p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-form .form-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  margin-top: 8px;
}

.auth-form .form-footer a {
  color: var(--wa-teal);
}

.auth-message {
  display: none;
  padding: 16px;
  border-radius: var(--radius-md);
  text-align: center;
  font-size: 0.9rem;
}

.auth-message.info {
  background: rgba(59, 130, 246, 0.1);
  color: var(--info);
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.auth-message.success {
  background: rgba(37, 211, 102, 0.1);
  color: var(--success);
  border: 1px solid rgba(37, 211, 102, 0.2);
}

.auth-message.error {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.auth-message.visible {
  display: block;
}

/* ============================================================
   DASHBOARD - Summary cards & chart containers
   ============================================================ */
.page-header {
  padding: 20px 28px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h1 {
  font-size: 1.35rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  padding: 24px 28px;
}

.summary-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  transition: box-shadow var(--transition-fast);
}

.summary-card:hover {
  box-shadow: var(--shadow-md);
}

.summary-card .card-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.summary-card .card-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.summary-card .card-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  margin-top: 6px;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  padding: 0 28px 28px;
}

.chart-container {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  min-height: 300px;
  display: flex;
  flex-direction: column;
}

.chart-container.full-width {
  grid-column: 1 / -1;
}

.chart-container .chart-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chart-container .chart-body {
  flex: 1;
  position: relative;
  min-height: 0;
}

.chart-container .chart-body svg,
.chart-container .chart-body canvas {
  width: 100%;
  height: 100%;
}

/* ============================================================
   DATE FILTER BAR
   ============================================================ */
.date-filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
}

.date-filter-bar .filter-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.date-filter-bar .filter-btn {
  padding: 6px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.date-filter-bar .filter-btn:hover {
  border-color: var(--wa-teal);
  color: var(--wa-teal);
}

.date-filter-bar .filter-btn.active {
  background: var(--wa-teal);
  color: #fff;
  border-color: var(--wa-teal);
}

.date-filter-bar .date-inputs {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
}

.date-filter-bar .date-inputs input[type="date"] {
  padding: 5px 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.82rem;
}

.date-filter-bar .date-inputs .separator {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ============================================================
   TREND ARROWS
   ============================================================ */
.trend-up {
  color: var(--trend-up);
}

.trend-down {
  color: var(--trend-down);
}

.trend-neutral {
  color: var(--trend-neutral);
}

.trend-arrow {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-weight: 600;
}

.trend-arrow::before {
  font-size: 0.9em;
}

.trend-arrow.up::before {
  content: "\25B2"; /* up triangle */
}

.trend-arrow.down::before {
  content: "\25BC"; /* down triangle */
}

/* ============================================================
   REPORT CARD / GRADE DISPLAY
   ============================================================ */
.grade-display {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 1.5rem;
  font-weight: 800;
  color: #fff;
}

.grade-display.grade-a { background: var(--grade-a); }
.grade-display.grade-b { background: var(--grade-b); }
.grade-display.grade-c { background: var(--grade-c); }
.grade-display.grade-d { background: var(--grade-d); }
.grade-display.grade-f { background: var(--grade-f); }

.grade-display.large {
  width: 80px;
  height: 80px;
  font-size: 2.2rem;
}

.report-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  text-align: center;
}

.report-card .grade-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}

.report-card .grade-description {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 12px;
}

/* ============================================================
   CHAT VIEWER - WhatsApp-style bubbles
   ============================================================ */
.chat-viewer {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height));
}

.chat-search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.chat-search-bar input {
  flex: 1;
  padding: 8px 14px;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition-fast);
}

.chat-search-bar input:focus {
  border-color: var(--wa-teal);
}

.chat-search-bar .search-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 60px;
  background: var(--wa-chat-bg);
  background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 10 Q35 5 40 10 T50 10' fill='none' stroke='%23c8c2b9' stroke-width='0.5' opacity='0.3'/%3E%3C/svg%3E");
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-bubble {
  max-width: 65%;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  line-height: 1.45;
  position: relative;
  word-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
}

.chat-bubble.sent {
  align-self: flex-end;
  background: var(--wa-sent-bubble);
  border-top-right-radius: 2px;
}

.chat-bubble.received {
  align-self: flex-start;
  background: var(--wa-received-bubble);
  border-top-left-radius: 2px;
}

.chat-bubble .bubble-sender {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--wa-teal);
  margin-bottom: 2px;
}

.chat-bubble .bubble-text {
  color: var(--text-primary);
}

.chat-bubble .bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 4px;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.chat-bubble .bubble-media {
  margin: 6px 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  max-width: 320px;
}

.chat-bubble .bubble-media img,
.chat-bubble .bubble-media video {
  display: block;
  width: 100%;
  border-radius: var(--radius-sm);
}

/* Behaviour tags */
.behaviour-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.5;
}

.behaviour-tag.positive {
  background: rgba(37, 211, 102, 0.15);
  color: #1a8d4e;
}

.behaviour-tag.negative {
  background: rgba(239, 68, 68, 0.12);
  color: #c0392b;
}

.behaviour-tag.neutral {
  background: rgba(134, 150, 160, 0.15);
  color: var(--text-secondary);
}

/* Mood indicators */
.mood-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.mood-indicator.mood-positive { background: var(--success); }
.mood-indicator.mood-neutral  { background: var(--warning); }
.mood-indicator.mood-negative { background: var(--danger); }

/* System messages in chat */
.chat-system-msg {
  align-self: center;
  background: rgba(255, 255, 255, 0.85);
  padding: 4px 14px;
  border-radius: var(--radius-md);
  font-size: 0.78rem;
  color: var(--text-muted);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
}

/* Date dividers */
.chat-date-divider {
  align-self: center;
  background: rgba(225, 218, 208, 0.9);
  padding: 4px 14px;
  border-radius: var(--radius-md);
  font-size: 0.76rem;
  color: var(--text-secondary);
  margin: 12px 0;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
}

/* Search highlights */
.chat-bubble mark {
  background: rgba(255, 210, 0, 0.45);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* ============================================================
   ANALYTICS - Chart grid
   ============================================================ */
.analytics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  padding: 24px 28px;
}

.analytics-grid .chart-container {
  min-height: 280px;
}

.analytics-grid .chart-container.span-2 {
  grid-column: span 2;
}

/* ============================================================
   COACHING - Cards & comparison panels
   ============================================================ */
.coaching-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
  padding: 24px 28px;
}

.coaching-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--wa-teal);
  transition: box-shadow var(--transition-fast);
}

.coaching-card:hover {
  box-shadow: var(--shadow-md);
}

.coaching-card .tip-category {
  font-size: 0.75rem;
  color: var(--wa-teal);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 8px;
}

.coaching-card .tip-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.coaching-card .tip-body {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Escalation replay comparison */
.comparison-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding: 0 28px 28px;
}

.comparison-panel {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.comparison-panel .panel-header {
  padding: 12px 20px;
  font-weight: 600;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border-color);
}

.comparison-panel .panel-header.original {
  background: rgba(239, 68, 68, 0.08);
  color: var(--danger);
}

.comparison-panel .panel-header.improved {
  background: rgba(37, 211, 102, 0.08);
  color: var(--success);
}

.comparison-panel .panel-body {
  padding: 16px 20px;
  max-height: 400px;
  overflow-y: auto;
}

/* ============================================================
   ADMIN - Table layout
   ============================================================ */
.admin-table-wrapper {
  padding: 24px 28px;
}

.admin-table {
  width: 100%;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border-collapse: collapse;
}

.admin-table thead {
  background: var(--bg-primary);
}

.admin-table th {
  padding: 12px 16px;
  text-align: left;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-color);
}

.admin-table td {
  padding: 12px 16px;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
}

.admin-table tbody tr:hover {
  background: rgba(18, 140, 126, 0.04);
}

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

/* ============================================================
   COMMON - Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.4;
}

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

.btn-primary {
  background: var(--wa-teal);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--wa-dark-green);
}

.btn-success {
  background: var(--wa-light-green);
  color: #fff;
}

.btn-success:hover:not(:disabled) {
  background: #1eb954;
}

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

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

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

.btn-outline:hover:not(:disabled) {
  background: var(--wa-teal);
  color: #fff;
}

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

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

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

.btn-lg {
  padding: 14px 28px;
  font-size: 1rem;
}

.btn-full {
  width: 100%;
}

/* ============================================================
   COMMON - Form inputs
   ============================================================ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-input,
.form-select,
.form-textarea {
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font-family);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--wa-teal);
  box-shadow: 0 0 0 3px rgba(18, 140, 126, 0.12);
}

.form-input.error {
  border-color: var(--danger);
}

.form-helper {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.form-error {
  font-size: 0.78rem;
  color: var(--danger);
}

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

/* ============================================================
   COMMON - Modals
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(20px) scale(0.97);
  transition: transform var(--transition-normal);
}

.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 1.05rem;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: 50%;
  transition: background var(--transition-fast);
}

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

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
}

/* ============================================================
   COMMON - Loading spinner
   ============================================================ */
.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border-color);
  border-top-color: var(--wa-teal);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner.lg {
  width: 40px;
  height: 40px;
  border-width: 4px;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  border-radius: inherit;
}

@media (prefers-color-scheme: dark) {
  .loading-overlay {
    background: rgba(17, 27, 33, 0.7);
  }
}

.page-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
}

/* ============================================================
   COMMON - Notification toasts
   ============================================================ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--wa-teal);
  font-size: 0.88rem;
  pointer-events: auto;
  animation: slideInRight 0.3s ease, fadeOut 0.3s ease 4.7s forwards;
  max-width: 360px;
}

.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast.info    { border-left-color: var(--info); }

.toast .toast-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 2px;
}

/* ============================================================
   COMMON - Badges
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.5;
}

.badge-primary {
  background: rgba(18, 140, 126, 0.15);
  color: var(--wa-teal);
}

.badge-success {
  background: rgba(37, 211, 102, 0.15);
  color: #1a8d4e;
}

.badge-warning {
  background: rgba(245, 159, 0, 0.15);
  color: #b87700;
}

.badge-danger {
  background: rgba(239, 68, 68, 0.12);
  color: #c0392b;
}

.badge-neutral {
  background: var(--bg-primary);
  color: var(--text-muted);
}

/* ============================================================
   COMMON - Tooltips
   ============================================================ */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 10px;
  background: #1a1a2e;
  color: #e9edef;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
  z-index: 1500;
}

[data-tooltip]:hover::after {
  opacity: 1;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes spin {
  to { transform: rotate(360deg); }
}

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

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(60px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translateX(30px);
  }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
  .summary-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .chart-grid,
  .analytics-grid {
    grid-template-columns: 1fr;
  }

  .comparison-panels {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  :root {
    --sidebar-width: 0px;
  }

  .sidebar {
    transform: translateX(-100%);
    width: 240px;
  }

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

  .main-content {
    margin-left: 0;
  }

  .mobile-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--wa-header-bg);
    color: #fff;
  }

  .mobile-menu-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px;
  }

  .summary-grid {
    grid-template-columns: 1fr 1fr;
    padding: 16px;
    gap: 12px;
  }

  .summary-card .card-value {
    font-size: 1.35rem;
  }

  .chart-grid,
  .analytics-grid {
    padding: 0 16px 16px;
  }

  .page-header {
    padding: 16px;
  }

  .date-filter-bar {
    padding: 10px 16px;
  }

  .chat-messages {
    padding: 12px 16px;
  }

  .chat-bubble {
    max-width: 82%;
  }

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

  .admin-table-wrapper {
    padding: 16px;
    overflow-x: auto;
  }

  .comparison-panels {
    padding: 0 16px 16px;
  }
}

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

  .auth-card {
    padding: 28px 20px;
  }

  .date-filter-bar .date-inputs {
    width: 100%;
    margin-left: 0;
    margin-top: 4px;
  }
}

/* Mobile header hidden on desktop */
.mobile-header {
  display: none;
}

/* Mobile sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 999;
}

@media (max-width: 768px) {
  .mobile-header {
    display: flex;
  }

  .sidebar.open ~ .sidebar-overlay {
    display: block;
  }
}

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
  .sidebar,
  .mobile-header,
  .sidebar-overlay,
  .date-filter-bar,
  .toast-container,
  .modal-overlay,
  .chat-search-bar,
  .btn {
    display: none !important;
  }

  .main-content {
    margin-left: 0 !important;
  }

  body {
    background: #fff;
    color: #000;
  }

  .summary-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .chart-grid,
  .analytics-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .summary-card,
  .chart-container,
  .coaching-card,
  .report-card {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
  }

  .chat-bubble {
    box-shadow: none;
    border: 1px solid #ddd;
  }

  .chat-bubble.sent {
    background: #eef9e4;
  }

  .admin-table {
    box-shadow: none;
  }

  a {
    color: #000;
    text-decoration: underline;
  }
}

/* ============================================================
   UTILITY CLASSES
   ============================================================ */
.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
