/* =========================================================
   Dashboard Layout
   ========================================================= */

.dashboard-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px;
}

/* =========================================================
   Reporting Timezone
   ========================================================= */

.timezone-banner {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 14px;
  box-shadow: var(--shadow-sm);
  color: var(--text-700);
  font-size: 13px;
  margin-bottom: 18px;
}

.timezone-label {
  color: var(--text-500);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.timezone-value {
  color: var(--text-900);
  font-weight: 600;
}

/* =========================================================
   Stats
   ========================================================= */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

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

.stat-label {
  color: var(--text-600);
  font-size: 14px;
  margin-bottom: 8px;
}

.stat-value {
  color: var(--text-900);
  font-size: 32px;
  font-weight: 700;
}

.stat-change {
  color: var(--success-600);
  font-size: 14px;
  margin-top: 8px;
}

.stat-change.negative {
  color: var(--danger-600);
}

/* =========================================================
   Main Content Grids
   ========================================================= */

.main-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
  margin-bottom: 30px;
}

@media (max-width: 968px) {
  .main-content {
    grid-template-columns: 1fr;
  }
}

/* =========================================================
   Charts
   ========================================================= */

.chart-container {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
  height: 400px;
  position: relative;
}

.chart-body {
  position: relative;
  height: 300px;
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 10px;
}

.chart-title {
  color: var(--brand-800);
  font-size: 18px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.chart-title-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chart-title-icon svg {
  width: 18px;
  height: 18px;
}

.time-filter {
  display: flex;
  gap: 10px;
}

.filter-btn {
  padding: 6px 12px;
  background: var(--surface-50);
  border: 1px solid var(--border-200);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-700);
}

.filter-btn.active {
  background: var(--brand-800);
  color: var(--white);
  border-color: var(--brand-800);
}

/* =========================================================
   Conversations
   ========================================================= */

.conversations-section {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
}

.reported-conversations-section {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
  margin-top: 20px;
}

.reported-list {
  display: grid;
  gap: 12px;
}

.reported-item {
  border: 1px solid var(--border-200);
  border-radius: var(--r-md);
  padding: 14px;
  cursor: pointer;
  background: var(--surface-50);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.reported-item:hover {
  border-color: var(--brand-800);
  box-shadow: var(--shadow-sm);
}

.reported-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.reported-id {
  font-weight: 600;
  color: var(--text-900);
}

.reported-tag {
  font-size: 11px;
  text-transform: uppercase;
  border-radius: 12px;
  padding: 2px 8px;
  background: var(--surface-100);
  color: var(--text-700);
}

.reported-tag.positive {
  background: color-mix(in srgb, var(--success-600) 20%, var(--white));
  color: var(--success-600);
}

.reported-tag.neutral {
  background: color-mix(in srgb, var(--brand-700) 20%, var(--white));
  color: var(--brand-700);
}

.reported-tag.negative {
  background: var(--danger-bg);
  color: var(--danger-600);
}

.reported-meta {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-600);
}

.reported-preview {
  margin: 8px 0 10px;
  color: var(--text-800);
  font-size: 14px;
}

.reported-footer {
  display: flex;
  gap: 10px;
  font-size: 12px;
  color: var(--text-600);
  flex-wrap: wrap;
}

.reported-issue {
  font-weight: 600;
  color: var(--text-700);
  text-transform: capitalize;
}

.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.search-input {
  flex: 1;
  padding: 10px 15px;
  border: 1px solid var(--border-200);
  border-radius: var(--r-md);
  font-size: 14px;
  color: var(--text-600);
}

.conversation-list {
  max-height: 600px;
  overflow-y: auto;
}

.conversation-item {
  border: 1px solid var(--border-200);
  border-radius: var(--r-md);
  padding: 15px;
  margin-bottom: 10px;
  cursor: pointer;
}

.conversation-item:hover {
  background: var(--surface-50);
  border-color: var(--brand-800);
}

.conversation-header,
.conversation-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.conversation-time {
  margin-left: auto;
}

/* =========================================================
   Sentiment Badges
   ========================================================= */

.sentiment-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.sentiment-icon {
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sentiment-icon svg {
  width: 14px;
  height: 14px;
}

.sentiment-badge.positive {
  background: color-mix(in srgb, var(--success-600) 20%, var(--white));
  color: var(--success-600);
}

.sentiment-badge.neutral {
  background: color-mix(in srgb, var(--brand-700) 20%, var(--white));
  color: var(--brand-700);
}

.sentiment-badge.negative {
  background: var(--danger-bg);
  color: var(--danger-600);
}

.conversation-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-600);
}

.meta-icon {
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.meta-icon svg {
  width: 14px;
  height: 14px;
}

/* =========================================================
   Messages
   ========================================================= */

.message {
  padding: 10px 15px;
  margin-bottom: 10px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
}

.message.user {
  background: var(--surface-50);
  border-left: 3px solid var(--brand-800);
}

.message.ai {
  background: var(--surface-100);
  border-left: 3px solid var(--success-600);
}

.message.system {
  background: var(--danger-bg);
  border-left: 3px solid var(--danger-600);
}

.message.instruction {
  background: color-mix(in srgb, var(--brand-700) 12%, var(--surface-50));
  border-left: 3px solid var(--brand-700);
}

.message-label {
  font-size: 12px;
  color: var(--text-600);
  margin-bottom: 5px;
}

.message-text {
  color: var(--text-900);
  font-size: 14px;
}

.instruction-details {
  display: block;
}

.instruction-summary {
  cursor: pointer;
  user-select: none;
}

.instruction-summary::marker {
  color: var(--brand-700);
}

.instruction-body {
  margin-top: 8px;
}

.instruction-code {
  margin: 0;
  padding: 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-200);
  background: var(--surface);
  font-size: 12px;
  color: var(--text-900);
  white-space: pre-wrap;
  word-break: break-word;
}

.instruction-empty {
  font-size: 12px;
  color: var(--text-600);
  font-style: italic;
}

/* =========================================================
   Tool Calls
   ========================================================= */

.tool-calls {
  margin-top: 16px;
  padding-top: 8px;
  border-top: 1px solid var(--border-200);
}

.tool-calls-header {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-600);
  margin: 8px 0 12px;
}

.tool-call {
  padding: 10px 12px;
  margin-bottom: 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-200);
  background: var(--surface-50);
}

.tool-call-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-700);
  margin-bottom: 0;
}

.tool-call-name {
  font-weight: 600;
  color: var(--text-900);
}

.tool-call-time {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-500);
}

.tool-call-body {
  display: grid;
  gap: 8px;
}

.tool-call-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-600);
  margin-bottom: 4px;
}

.tool-call-pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface-100);
  border: 1px solid var(--border-200);
  border-radius: var(--r-sm);
  padding: 8px;
  font-size: 12px;
  color: var(--text-900);
}

/* =========================================================
   Feedback Panel
   ========================================================= */

.modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.feedback-panel {
  border-top: 1px solid var(--border-200);
  padding: 16px 20px 20px;
  background: var(--surface-50);
}

.feedback-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-800);
  margin-bottom: 12px;
}

.feedback-session {
  font-size: 12px;
  color: var(--text-600);
}

.feedback-form {
  display: grid;
  gap: 10px;
}

.feedback-history {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.feedback-item {
  border: 1px solid var(--border-200);
  border-radius: var(--r-sm);
  background: var(--surface);
  padding: 10px 12px;
}

.feedback-item-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--text-600);
  margin-bottom: 6px;
}

.feedback-issue {
  font-weight: 600;
  color: var(--text-800);
  text-transform: capitalize;
}

.feedback-body {
  font-size: 13px;
  color: var(--text-900);
}

.feedback-history .empty-state,
.feedback-history .error-message,
.feedback-history .loading {
  font-size: 13px;
  color: var(--text-600);
}

.feedback-form label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-700);
}

.feedback-form select,
.feedback-form textarea {
  padding: 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-200);
  font-size: 14px;
  background: var(--surface);
  color: var(--text-900);
}

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

.feedback-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* =========================================================
   Mobile Overrides
   ========================================================= */

@media (max-width: 768px) {
  .dashboard-container {
    padding: 0 12px;
  }

  /* Stats */
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 16px;
  }

  .stat-card {
    padding: 14px;
  }

  .stat-value {
    font-size: 28px;
  }

  /* Main content */
  .main-content {
    grid-template-columns: 1fr;
    gap: 14px;
    margin-bottom: 16px;
  }

  /* Charts */
  .chart-container {
    padding: 14px;
    height: auto;
  }

  .chart-body {
    height: 240px;
  }

  .chart-header {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .chart-title {
    font-size: 16px;
    flex: 1 1 100%;
  }

  .time-filter {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }

  .filter-btn {
    flex: 1 1 auto;
    padding: 8px 10px;
  }

  /* Conversations */
  .conversations-section {
    padding: 14px;
  }

  .reported-conversations-section {
    padding: 14px;
  }

  .search-bar {
    flex-direction: column;
    gap: 10px;
  }

  .search-input,
  .search-btn {
    width: 100% !important;
  }

  .conversation-list {
    max-height: 60vh;
  }

  .conversation-item {
    padding: 12px;
  }

  .conversation-time {
    margin-left: 0;
    width: 100%;
    font-size: 12px;
    color: var(--text-600);
  }

  .reported-meta {
    margin-left: 0;
    width: 100%;
  }
}

/* =========================================================
   Call Transcription Styles
   ========================================================= */

.transcription-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
  border-bottom: 2px solid var(--border-200);
  padding-bottom: 10px;
}

.tab-button {
  padding: 8px 16px;
  border: 1px solid var(--border-200);
  border-radius: var(--r-md);
  background: var(--surface-50);
  color: var(--text-700);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-button:hover {
  background: var(--surface-100);
  border-color: var(--brand-800);
}

.tab-button.active {
  background: var(--brand-800);
  color: var(--white);
  border-color: var(--brand-800);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.formatted-transcription {
  border: 1px solid var(--border-200);
  border-radius: var(--r-md);
  background: var(--white);
  margin-bottom: 15px;
}

.transcription-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 15px;
  background: var(--surface-50);
  border-bottom: 1px solid var(--border-200);
  border-radius: var(--r-md) var(--r-md) 0 0;
  font-weight: 600;
  color: var(--text-800);
}

.transcription-body {
  padding: 15px;
  max-height: 400px;
  overflow-y: auto;
}

.transcription-turn {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  padding: 10px;
  border-radius: var(--r-sm);
  line-height: 1.5;
}

.transcription-turn:last-child {
  margin-bottom: 0;
}

.ai-turn {
  background: color-mix(in srgb, var(--brand-800) 8%, var(--white));
  border-left: 3px solid var(--brand-800);
}

.customer-turn {
  background: color-mix(in srgb, var(--success-600) 8%, var(--white));
  border-left: 3px solid var(--success-600);
}

.turn-label {
  flex-shrink: 0;
  min-width: 70px;
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ai-label {
  color: var(--brand-800);
}

.customer-label {
  color: var(--success-600);
}

.turn-text {
  flex: 1;
  color: var(--text-700);
  font-size: 14px;
}

.no-messages {
  padding: 20px;
  text-align: center;
  color: var(--text-600);
  font-style: italic;
}

/* Recording badge for phone calls */
.recording-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: color-mix(in srgb, var(--success-600) 15%, var(--white));
  color: var(--success-600);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  margin-right: 8px;
}

.recording-badge .meta-icon svg {
  width: 12px;
  height: 12px;
}

.conversation-item.phone-call {
  border-left: 3px solid var(--brand-800);
}

/* =========================================================
   Extra Small Phones
   ========================================================= */

@media (max-width: 420px) {
  .stat-value {
    font-size: 24px;
  }

  .filter-btn {
    flex: 1 1 48%;
  }

  /* Transcription mobile styles */
  .transcription-tabs {
    flex-direction: column;
    gap: 5px;
  }

  .tab-button {
    width: 100%;
    text-align: center;
  }

  .transcription-turn {
    flex-direction: column;
    gap: 5px;
  }

  .turn-label {
    min-width: auto;
  }

  .transcription-body {
    max-height: 300px;
  }
}
