/* ==========================================================================
   Chatwoot Design System Stylesheet
   ========================================================================== */

:root {
  /* Brand */
  --primary: #1F93FF;
  --primary-dark: #1677D2;
  --primary-light: #EBF5FF;
  --primary-focus: rgba(31, 147, 255, 0.2);

  /* Sidebar - Dark slate with blue tone */
  --sidebar-bg: #1B1F36;
  --sidebar-hover: rgba(255, 255, 255, 0.08);
  --sidebar-active: rgba(31, 147, 255, 0.15);
  --sidebar-text: #8D919A;
  --sidebar-text-active: #FFFFFF;

  /* Surfaces & Backgrounds */
  --bg-body: #F6F6F7;
  --bg-white: #FFFFFF;
  --bg-card: #FFFFFF;
  --border-light: #E8E8E8;
  --border-subtle: #F0F0F2;

  /* Chat Bubbles */
  --msg-incoming-bg: #FFFFFF;
  --msg-incoming-border: #E8E8E8;
  --msg-outgoing-bg: #CCE5FF;
  --msg-outgoing-border: #B3D7FF;

  /* Status Badges */
  --green-resolved: #44CE4B;
  --green-resolved-bg: #E8F8EA;
  --yellow-snoozed: #FFC532;
  --yellow-snoozed-bg: #FFF8E6;
  --blue-open: #1F93FF;
  --blue-open-bg: #EBF5FF;
  --gray-pending: #8D919A;
  --gray-pending-bg: #F0F0F2;

  /* Typography */
  --text-primary: #1B1F36;
  --text-secondary: #6E6F73;
  --text-muted: #8D919A;

  /* Dimensions & Radius */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-popover: 0 4px 12px rgba(0, 0, 0, 0.08);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background-color: var(--bg-body);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.5;
}

.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ==========================================================================
   1. Left Navigation Sidebar
   ========================================================================== */
.nav-sidebar {
  width: 60px;
  background-color: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
  flex-shrink: 0;
  z-index: 20;
}

.nav-brand {
  margin-bottom: 20px;
}

.brand-logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #1F93FF 0%, #006EFA 100%);
  color: #FFFFFF;
  font-weight: 700;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  box-shadow: 0 2px 6px rgba(0, 110, 250, 0.35);
  user-select: none;
}

.nav-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  width: 100%;
  align-items: center;
}

.nav-btn {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease-in-out;
  position: relative;
}

.nav-btn svg {
  fill: currentColor;
  width: 22px;
  height: 22px;
}

.nav-btn:hover {
  background-color: var(--sidebar-hover);
  color: var(--sidebar-text-active);
}

.nav-btn.active {
  background-color: var(--sidebar-active);
  color: var(--primary);
}

.nav-btn.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background-color: var(--primary);
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}

.nav-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 4px;
}

.status-indicator {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  background-color: var(--green-resolved);
  box-shadow: 0 0 6px rgba(68, 206, 75, 0.6);
  cursor: pointer;
}

/* ==========================================================================
   2. Main Layout & View Panels
   ========================================================================== */
.main-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
  background-color: var(--bg-body);
}

.view-panel {
  display: none;
  width: 100%;
  height: 100%;
}

.view-panel.active {
  display: flex;
}

/* ==========================================================================
   3. Conversations Sidebar (Inbox list)
   ========================================================================== */
.conversations-sidebar {
  width: 340px;
  background-color: var(--bg-white);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

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

.sidebar-header h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  letter-spacing: -0.01em;
}

.search-box {
  display: flex;
  align-items: center;
  background-color: var(--bg-body);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 0 10px;
  height: 36px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.search-box:focus-within {
  border-color: var(--primary);
  background-color: #FFFFFF;
  box-shadow: 0 0 0 2px var(--primary-focus);
}

.search-box svg {
  fill: var(--text-muted);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin-right: 8px;
}

.search-box input {
  border: none;
  background: transparent;
  width: 100%;
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
}

.search-box input::placeholder {
  color: var(--text-muted);
}

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

.loading-state, .empty-list-state {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.conv-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background-color 0.12s ease;
  position: relative;
}

.conv-item:hover {
  background-color: #FAFAFA;
}

.conv-item.active {
  background-color: var(--primary-light);
}

.conv-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background-color: var(--primary);
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
  margin-right: 12px;
  user-select: none;
}

.conv-item-content {
  flex: 1;
  min-width: 0;
}

.conv-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 3px;
}

.conv-name {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
}

.conv-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.conv-snippet {
  font-size: 12.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   4. Chat Area
   ========================================================================== */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-body);
  position: relative;
  overflow: hidden;
}

.empty-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
}

.empty-chat-icon {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-full);
  background-color: #EAEBED;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.empty-chat-icon svg {
  width: 32px;
  height: 32px;
  fill: var(--text-muted);
}

.empty-chat h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.empty-chat p {
  color: var(--text-muted);
  font-size: 13px;
  max-width: 320px;
}

.active-chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

.active-chat.hidden {
  display: none;
}

/* Chat Header */
.chat-header {
  height: 62px;
  background-color: var(--bg-white);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
}

.chat-header-info h3 {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}

.phone-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-status {
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-status.open {
  background-color: var(--blue-open-bg);
  color: var(--blue-open);
}

.badge-status.resolved {
  background-color: var(--green-resolved-bg);
  color: var(--green-resolved);
}

.badge-status.snoozed {
  background-color: var(--yellow-snoozed-bg);
  color: var(--yellow-snoozed);
}

.badge-channel {
  background-color: #F0F0F2;
  color: var(--text-secondary);
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  font-size: 11px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}

.badge-channel svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
}

/* Messages Feed */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message-bubble {
  max-width: 65%;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.45;
  word-wrap: break-word;
  position: relative;
  box-shadow: var(--shadow-sm);
}

.message-bubble.incoming {
  align-self: flex-start;
  background-color: var(--msg-incoming-bg);
  color: var(--text-primary);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-xs);
  border: 1px solid var(--msg-incoming-border);
}

.message-bubble.outgoing {
  align-self: flex-end;
  background-color: var(--msg-outgoing-bg);
  color: var(--text-primary);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-xs) var(--radius-lg);
  border: 1px solid var(--msg-outgoing-border);
}

.msg-content {
  white-space: pre-wrap;
}

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

.msg-meta svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.msg-meta .status-icon-read {
  color: var(--primary);
}

.msg-meta .status-icon-sent {
  color: var(--text-muted);
}

.attachment-preview {
  margin-top: 6px;
  padding: 8px 10px;
  background-color: rgba(0, 0, 0, 0.03);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.attachment-preview svg {
  width: 16px;
  height: 16px;
  fill: var(--text-secondary);
  flex-shrink: 0;
}

/* Chat Footer / Input */
.chat-footer {
  background-color: var(--bg-white);
  border-top: 1px solid var(--border-light);
  padding: 10px 20px;
  flex-shrink: 0;
}

.staged-attachment-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #F4F5F7;
  border-radius: var(--radius-md);
  padding: 6px 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border-light);
}

.staged-attachment-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--text-primary);
  max-width: 85%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.staged-attachment-preview-img {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  object-fit: cover;
  border: 1px solid var(--border-light);
}

.staged-remove-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: var(--radius-full);
}

.staged-remove-btn:hover {
  background-color: #E5E7EB;
  color: #EF4444;
}

.composer-action-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  background: transparent;
  border: none;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}

.composer-action-btn:hover {
  background-color: rgba(0, 0, 0, 0.06);
  color: var(--primary);
}

.composer-action-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.recording-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #FEE2E2;
  border-radius: var(--radius-lg);
  padding: 8px 14px;
  width: 100%;
}

.recording-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #DC2626;
}

.recording-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #DC2626;
  animation: pulse-recording 1.2s infinite;
}

@keyframes pulse-recording {
  0% { transform: scale(0.95); opacity: 0.7; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.7; }
}

.message-input-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background-color: var(--bg-body);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 6px 8px 6px 12px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.message-input-form:focus-within {
  border-color: var(--primary);
  background-color: #FFFFFF;
  box-shadow: 0 0 0 2px var(--primary-focus);
}

.message-input-form textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: 13.5px;
  color: var(--text-primary);
  outline: none;
  max-height: 120px;
  padding: 6px 0;
  line-height: 1.4;
}

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

.send-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  background-color: var(--primary);
  color: #FFFFFF;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s ease;
  flex-shrink: 0;
}

.send-btn svg {
  width: 16px;
  height: 16px;
  fill: #FFFFFF;
}

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

/* ==========================================================================
   5. Config & Webhook View
   ========================================================================== */
.config-container {
  flex: 1;
  overflow-y: auto;
  padding: 28px 36px;
  max-width: 1100px;
  margin: 0 auto;
}

.config-header {
  margin-bottom: 24px;
}

.config-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.config-header p {
  color: var(--text-secondary);
  font-size: 13.5px;
}

.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 22px 24px;
  margin-bottom: 20px;
}

.card h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card h3 svg {
  width: 18px;
  height: 18px;
  fill: var(--primary);
}

.config-grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 20px;
}

/* Meta Config Card */
.meta-config-card {
  border-left: 4px solid var(--primary);
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
}

.meta-field-box label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: block;
}

.meta-field-box > input {
  width: 100%;
  min-width: 0;
  margin-top: 6px;
  padding: 9px 12px;
  background: var(--bg-body);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.meta-field-box > input:focus {
  border-color: var(--primary);
  background: #FFFFFF;
  box-shadow: 0 0 0 2px var(--primary-focus);
}

.meta-field-box > input::placeholder { color: var(--text-muted); }

#meta-credentials-form .btn-primary { min-height: 38px; }
#meta-credentials-form .btn-primary:disabled { opacity: 0.65; cursor: wait; }

.meta-input-group {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.meta-input-group input {
  flex: 1;
  padding: 8px 12px;
  background-color: var(--bg-body);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
  color: var(--text-primary);
  outline: none;
}

.btn-secondary {
  padding: 8px 14px;
  background-color: #FFFFFF;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.btn-secondary svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.btn-secondary:hover {
  background-color: var(--bg-body);
  border-color: #D1D5DB;
}

.meta-tip-box {
  background-color: var(--bg-body);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-top: 16px;
  font-size: 12.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--border-subtle);
}

.meta-tip-box code {
  background-color: rgba(0,0,0,0.05);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  font-family: monospace;
}

/* Health Metrics */
.health-metrics {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 13px;
  color: var(--text-secondary);
}

.metric-row strong {
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.metric-row code {
  font-family: monospace;
  font-size: 12px;
  background-color: var(--bg-body);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
}

.metric-status-ok {
  color: var(--green-resolved);
  display: flex;
  align-items: center;
  gap: 4px;
}

.metric-status-ok svg {
  width: 14px;
  height: 14px;
  fill: var(--green-resolved);
}

/* Form Styles */
.form-group {
  margin-bottom: 14px;
}

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

.form-group input {
  width: 100%;
  padding: 8px 12px;
  background-color: var(--bg-body);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s ease;
}

.form-group input:focus {
  border-color: var(--primary);
  background-color: #FFFFFF;
  box-shadow: 0 0 0 2px var(--primary-focus);
}

.btn-primary,
.primary-btn {
  padding: 8px 16px;
  background-color: var(--primary);
  color: #FFFFFF;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

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

.btn-primary:disabled,
.primary-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

/* Data Table */
.table-responsive {
  overflow-x: auto;
  margin-top: 10px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-light);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.data-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.data-table code {
  font-family: monospace;
  font-size: 12px;
  background-color: var(--bg-body);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
}

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

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #D1D5DB;
  border-radius: 3px;
}

@media (max-width: 760px) {
  .config-container { padding: 20px 16px; }
  .meta-grid { grid-template-columns: 1fr; gap: 12px; }
  .meta-config-card { padding: 18px 16px; }
  .meta-config-card > div:first-child { flex-wrap: wrap; gap: 10px; }
  #meta-credentials-form > div:last-child { flex-wrap: wrap; justify-content: flex-start !important; }
}


::-webkit-scrollbar-thumb:hover {
  background: #9CA3AF;
}
