/* Thailand Post (ไปรษณีย์ไทย) Corporate Chatbot Widget Design System */
:root {
  /* Corporate Colors */
  --thp-red: #E31B23;
  --thp-red-hover: #b81218;
  --thp-navy: #002D62;
  --thp-navy-dark: #092240;
  --thp-navy-light: #1E468A;
  
  /* Backgrounds */
  --bg-main: #F4F6F9;
  --bg-widget: #FFFFFF;
  --bg-chat-log: #F8FAFC;
  
  /* Statuses */
  --status-green: #10b981;
  --status-orange: #f59e0b;
  --status-red: #ef4444;
  
  /* Text colors */
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-dark: #0f172a;
  
  /* Typography & Layouts */
  --font-family: 'Sarabun', 'Outfit', 'Inter', sans-serif;
  --transition-speed: 0.3s;
}

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

body {
  font-family: var(--font-family);
  background-color: transparent; /* Transparent to fit iframe nicely */
  color: var(--text-main);
  height: 100vh;
  display: flex;
  overflow: hidden;
}

/* Chat Widget Container (Takes 100% of iframe/window) */
.chat-widget-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  background-color: var(--bg-widget);
  position: relative;
  overflow: hidden;
}

/* ==========================================================================
   Header Section
   ========================================================================== */
.widget-header {
  height: 60px;
  background-color: #FFFFFF;
  border-bottom: 1px solid #E2E8F0;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 10;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo-icon {
  font-size: 20px;
  color: var(--thp-red);
}

.header-brand-text h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--thp-navy);
  line-height: 1.2;
}

.header-brand-text span {
  font-size: 10px;
  color: var(--text-muted);
  display: block;
}

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

.header-action-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.header-action-btn:hover {
  background-color: #F1F5F9;
  color: var(--thp-red);
}

/* ==========================================================================
   Chat log (Bubbles, Avatars)
   ========================================================================== */
.chat-log {
  flex-grow: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background-color: var(--bg-chat-log);
}

.chat-message {
  display: flex;
  gap: 10px;
  max-width: 90%;
  animation: slide-up 0.3s ease;
}

.chat-message.model {
  align-self: flex-start;
}

.chat-message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

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

.chat-message.model .message-avatar {
  background-color: var(--thp-navy);
  color: white;
}

.chat-message.user .message-avatar {
  background-color: var(--thp-red);
  color: white;
}

.message-content {
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.6;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.chat-message.model .message-content {
  background-color: #FFFFFF;
  border: 1px solid #E2E8F0;
  border-top-left-radius: 2px;
  color: var(--text-dark);
}

.chat-message.user .message-content {
  background-color: var(--thp-red);
  color: white;
  border-top-right-radius: 2px;
}

.message-content p {
  margin-bottom: 6px;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content ul, .message-content ol {
  padding-left: 18px;
  margin-bottom: 6px;
}

.message-content li {
  margin-bottom: 3px;
}

.chat-message.model .message-content a {
  color: var(--thp-navy-light);
  font-weight: 700;
  text-decoration: underline;
}

.chat-message.user .message-content a {
  color: white;
  text-decoration: underline;
}

/* Custom Cards in chat (Incident results, KB rows, etc.) */
.ticket-card, .approval-card, .offering-card {
  background: #F8FAFC;
  border: 1px solid #E2E8F0;
  border-radius: 8px;
  padding: 10px;
  margin-top: 6px;
  color: var(--text-dark);
}

.inline-actions-wrapper {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.inline-btn {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: opacity 0.2s;
}

.inline-btn:hover {
  opacity: 0.9;
}

.inline-btn.approve {
  background-color: var(--status-green);
  color: white;
}

.inline-btn.reject {
  background-color: var(--status-red);
  color: white;
}

/* Typing Indicator */
.typing-indicator-wrapper {
  display: none;
  align-items: center;
  gap: 8px;
  margin-left: 16px;
  margin-bottom: 8px;
}

.typing-indicator-wrapper.active {
  display: flex;
}

.typing-bubble {
  background: white;
  border: 1px solid #E2E8F0;
  padding: 8px 12px;
  border-radius: 14px;
  display: flex;
  gap: 3px;
}

.typing-bubble .dot {
  width: 5px;
  height: 5px;
  background-color: var(--text-muted);
  border-radius: 50%;
  animation: typing-dot 1.4s infinite ease-in-out both;
}

.typing-bubble .dot:nth-child(1) { animation-delay: -0.32s; }
.typing-bubble .dot:nth-child(2) { animation-delay: -0.16s; }

.typing-text {
  font-size: 10px;
  color: var(--text-muted);
}

/* ==========================================================================
   Quick Replies Drawer
   ========================================================================== */
.quick-replies-drawer {
  padding: 8px 16px;
  border-top: 1px solid #E2E8F0;
  background-color: #FFFFFF;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}

.quick-replies-drawer::-webkit-scrollbar {
  display: none;
}

.quick-reply-pill {
  padding: 6px 12px;
  border-radius: 99px;
  background-color: #EFF6FF;
  border: 1px solid #DBEAFE;
  color: var(--thp-navy);
  font-family: var(--font-family);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
}

.quick-reply-pill:hover {
  background-color: var(--thp-red);
  color: white;
  border-color: var(--thp-red);
}

/* ==========================================================================
   Input Form Bar
   ========================================================================== */
.chat-input-bar {
  padding: 10px 16px;
  border-top: 1px solid #E2E8F0;
  background-color: #FFFFFF;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

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

.attach-btn,
.mic-btn,
.send-btn {
  background: none;
  border: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.attach-btn, .mic-btn {
  color: var(--text-muted);
}

.attach-btn:hover, .mic-btn:hover {
  background-color: #F1F5F9;
  color: var(--thp-navy);
}

.mic-btn.listening {
  background-color: #FEE2E2;
  color: var(--thp-red);
  animation: pulse-red 1.5s infinite;
}

.send-btn {
  background-color: var(--thp-red);
  color: white;
}

.send-btn:hover {
  background-color: var(--thp-red-hover);
}

.chat-form input {
  flex-grow: 1;
  padding: 8px 14px;
  border: 1px solid #CBD5E1;
  border-radius: 20px;
  outline: none;
  font-family: var(--font-family);
  font-size: 13px;
  transition: border-color 0.2s;
}

.chat-form input:focus {
  border-color: var(--thp-navy);
}

/* Previews container for attachments */
.attachment-preview-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-bottom: 4px;
}

.attachment-preview {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #CBD5E1;
}

.attachment-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.remove-attachment-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  background-color: rgba(0, 0, 0, 0.6);
  color: white;
  border: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  font-size: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==========================================================================
   Collapsible API Log Console (Widget Footer)
   ========================================================================== */
.console-drawer-section {
  border-top: 1px solid #E2E8F0;
  background-color: #FFFFFF;
  flex-shrink: 0;
}

.console-toggle-btn {
  width: 100%;
  padding: 10px 16px;
  background-color: #F8FAFC;
  border: none;
  border-bottom: 1px solid #E2E8F0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-family);
  font-size: 11px;
  font-weight: 700;
  color: var(--thp-navy);
  cursor: pointer;
  transition: background-color 0.2s;
}

.console-toggle-btn:hover {
  background-color: #F1F5F9;
}

.console-toggle-btn .toggle-chevron {
  transition: transform var(--transition-speed);
}

.console-drawer-section.active .console-toggle-btn .toggle-chevron {
  transform: rotate(180deg);
}

.console-body-wrapper {
  display: none;
  background-color: #0F172A;
  color: #E2E8F0;
}

.console-drawer-section.active .console-body-wrapper {
  display: flex;
  flex-direction: column;
  height: 200px;
}

.console-header-actions {
  padding: 6px 16px;
  border-bottom: 1px solid #334155;
  background-color: #1E293B;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.connection-status-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: #94A3B8;
}

.connection-status-inline .status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.connection-status-inline .status-dot.green { background-color: var(--status-green); box-shadow: 0 0 6px var(--status-green); }
.connection-status-inline .status-dot.orange { background-color: var(--status-orange); box-shadow: 0 0 6px var(--status-orange); }

.status-text-val {
  font-weight: 700;
  color: #E2E8F0;
}

.status-detail-val {
  opacity: 0.8;
}

.clear-console-btn {
  background: none;
  border: none;
  color: #94A3B8;
  font-family: var(--font-family);
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.clear-console-btn:hover {
  color: #F87171;
}

.console-body {
  padding: 10px;
  overflow-y: auto;
  font-family: 'Courier New', Courier, monospace;
  font-size: 9px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-grow: 1;
}

.console-placeholder {
  color: #64748B;
  text-align: center;
  margin-top: 20px;
  font-style: italic;
}

.console-log-entry {
  border-left: 2px solid var(--thp-navy-light);
  padding-left: 6px;
  margin-bottom: 2px;
}

.console-log-entry.mock {
  border-left-color: var(--status-orange);
}

.log-meta {
  color: #94A3B8;
  margin-bottom: 2px;
  display: flex;
  gap: 6px;
}

.log-meta .method {
  font-weight: bold;
  color: #38BDF8;
}

.console-log-entry.mock .log-meta .method {
  color: #FDBA74;
}

.log-url {
  color: #E2E8F0;
  word-break: break-all;
}

.log-body {
  background: rgba(0, 0, 0, 0.4);
  padding: 4px;
  border-radius: 4px;
  color: #94A3B8;
  white-space: pre-wrap;
  word-break: break-all;
  margin-top: 2px;
  max-height: 60px;
  overflow-y: auto;
}

/* ==========================================================================
   Modals (Settings & Dashboard)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(9, 34, 64, 0.6);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

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

.modal-card {
  background-color: #FFFFFF;
  border-radius: 12px;
  width: 90%;
  max-width: 440px;
  box-shadow: 0 15px 25px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(15px);
  transition: transform 0.3s;
}

.modal-overlay.active .modal-card {
  transform: translateY(0);
}

.modal-header {
  padding: 14px 20px;
  border-bottom: 1px solid #E2E8F0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  font-size: 14px;
  font-weight: 700;
  color: var(--thp-navy);
  display: flex;
  align-items: center;
  gap: 8px;
}

.close-modal-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
}

.close-modal-btn:hover {
  color: var(--thp-red);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  max-height: 65vh;
}

.input-group {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-group label {
  font-size: 12px;
  font-weight: 700;
  color: var(--thp-navy);
}

.input-group label .required {
  color: var(--thp-red);
}

.input-group input {
  padding: 8px 12px;
  border: 1px solid #CBD5E1;
  border-radius: 6px;
  font-family: var(--font-family);
  font-size: 12px;
  outline: none;
}

.input-group input:focus {
  border-color: var(--thp-navy);
}

.input-tip {
  font-size: 11px;
  color: var(--text-muted);
}

.divider {
  height: 1px;
  background-color: #E2E8F0;
  margin: 14px 0;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid #E2E8F0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background-color: #F8FAFC;
}

.btn-cancel,
.btn-save {
  padding: 8px 16px;
  border-radius: 6px;
  font-family: var(--font-family);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.btn-cancel {
  background-color: #FFFFFF;
  border: 1px solid #CBD5E1;
  color: var(--text-muted);
}

.btn-cancel:hover {
  background-color: #F1F5F9;
}

.btn-save {
  background-color: var(--thp-red);
  color: white;
  border: none;
}

.btn-save:hover {
  background-color: var(--thp-red-hover);
}

/* Dashboard modal sizes */
.modal-card.dashboard-card {
  max-width: 720px;
}

.dashboard-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stat-box {
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
}

.stat-box.purple { background-color: #FAF5FF; border: 1px solid #E9D5FF; color: #6B21A8; }
.stat-box.blue { background-color: #EFF6FF; border: 1px solid #BFDBFE; color: #1E40AF; }
.stat-box.green { background-color: #ECFDF5; border: 1px solid #A7F3D0; color: #065F46; }

.stat-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.stat-value {
  font-size: 20px;
  font-weight: 800;
}

.dashboard-selector-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.selector-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--thp-navy);
}

.chart-type-selector {
  display: flex;
  background-color: #F1F5F9;
  border-radius: 6px;
  padding: 3px;
}

.chart-type-btn {
  background: none;
  border: none;
  padding: 5px 10px;
  font-family: var(--font-family);
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-muted);
}

.chart-type-btn.active {
  background-color: white;
  color: var(--thp-navy);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.dashboard-charts-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.dashboard-panel {
  border: 1px solid #E2E8F0;
  border-radius: 8px;
  padding: 12px;
  background-color: #FFFFFF;
}

.dashboard-panel h3 {
  font-size: 12px;
  font-weight: 700;
  color: var(--thp-navy);
  margin-bottom: 8px;
  border-bottom: 1px solid #F1F5F9;
  padding-bottom: 6px;
}

.dashboard-panel.full-width {
  grid-column: 1 / -1;
}

.stat-summary-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-summary-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
}

.stat-summary-label {
  color: var(--text-muted);
}

.stat-summary-val {
  font-weight: 700;
  color: var(--text-dark);
}

.table-container {
  overflow-x: auto;
}

.dashboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  text-align: left;
}

.dashboard-table th {
  background-color: #F8FAFC;
  padding: 8px 10px;
  font-weight: 700;
  color: var(--thp-navy);
  border-bottom: 1px solid #E2E8F0;
}

.dashboard-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #F1F5F9;
  color: var(--text-dark);
}

/* ==========================================================================
   Animations
   ========================================================================== */
@keyframes pulse-red {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  70% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

@keyframes typing-dot {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1.0); }
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Embedded Mode Styles (hideHeader=true)
   ========================================================================== */
html.hide-header .widget-header {
  display: none !important;
}

html.hide-header .console-drawer-section {
  display: none !important;
}

html.hide-header .chat-widget-container {
  height: 100vh !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  border: none !important;
}
