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

:root {
  --carabao-red: #C8102E;
  --carabao-red-dark: #9E0B23;
  --carabao-green: #00843D;
  --carabao-green-dark: #00602C;
  --carabao-gold: #F2B705;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Sarabun", sans-serif;
  background: #f5f6fa;
  color: #1a1a2e;
}

.app { max-width: 1200px; margin: 0 auto; padding: 20px; }

.brand-logo { height: 40px; display: block; }

.header { text-align: center; margin-bottom: 24px; }
.header h1 { font-size: 28px; margin-bottom: 4px; color: var(--carabao-red-dark); }
.subtitle { color: #666; font-size: 14px; }

.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
}

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

.panel {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  border-top: 4px solid var(--carabao-green);
}

.panel h2 { font-size: 16px; margin-bottom: 16px; color: #333; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  color: #444;
}

input[type="text"], input[type="password"], input[type="number"],
select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d8dae5;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--carabao-red);
  box-shadow: 0 0 0 2px rgba(200,16,46,0.12);
}

.btn-primary {
  width: 100%;
  padding: 10px;
  background: var(--carabao-red);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
}
.btn-primary:hover { background: var(--carabao-red-dark); }
.btn-primary:disabled { background: #aab; cursor: not-allowed; }

.btn-secondary {
  width: 100%;
  padding: 6px;
  background: #e9f6ee;
  color: var(--carabao-green-dark);
  border: 1px solid #b9e3c8;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  margin-top: 6px;
}
.btn-secondary:hover { background: #dcf0e3; }

.status-msg { font-size: 12px; margin-top: 8px; min-height: 16px; }
.status-msg.success { color: var(--carabao-green-dark); }
.status-msg.error { color: #d64545; }

.input-type-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.tab {
  flex: 1;
  padding: 8px;
  border: 1px solid #d8dae5;
  border-radius: 6px;
  background: #fafafa;
  cursor: pointer;
  font-size: 13px;
}
.tab.active { background: var(--carabao-green); color: #fff; border-color: var(--carabao-green); }

.input-area { margin-bottom: 12px; }
.file-preview {
  margin-top: 8px;
  padding: 8px;
  background: #f0f2fa;
  border-radius: 6px;
  font-size: 12px;
}
.file-preview img { max-width: 100%; max-height: 200px; border-radius: 6px; margin-top: 6px; }

.loading {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
  font-size: 13px;
  color: #666;
}

.spinner {
  width: 16px; height: 16px;
  border: 2px solid #d8dae5;
  border-top-color: var(--carabao-red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.conversation { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; max-height: 600px; overflow-y: auto; }

.msg {
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.msg-user { background: #fdecef; align-self: flex-end; max-width: 80%; }
.msg-result { background: #eaf7f0; border: 1px solid #bfe6cf; }
.msg-error { background: #fdeeee; border: 1px solid #f5c6c6; color: #b02a2a; }

.msg-meta {
  font-size: 11px;
  color: #888;
  margin-top: 6px;
  display: flex;
  gap: 12px;
}


/* --- Login Screen --- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--carabao-red-dark), var(--carabao-green-dark));
}

.login-card {
  background: #fff;
  padding: 40px;
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
  width: 380px;
  text-align: center;
}

.login-card .brand-logo { height: 56px; margin: 0 auto 16px; }
.login-card h1 { font-size: 22px; margin-bottom: 6px; color: var(--carabao-red-dark); }
.login-card .subtitle { color: #666; font-size: 13px; margin-bottom: 20px; }
.login-card .field { text-align: left; margin-bottom: 16px; }

/* --- Header with agent badge + logout --- */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  margin-bottom: 24px;
}
.header .header-left { display: flex; align-items: center; gap: 12px; }
.header h1 { font-size: 22px; color: var(--carabao-red-dark); }
.header-right { display: flex; align-items: center; gap: 12px; }

.agent-badge {
  background: #e9f6ee;
  color: var(--carabao-green-dark);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}

.btn-logout {
  background: none;
  border: 1px solid #d8dae5;
  color: #666;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.btn-logout:hover { background: #f5f6fa; }

.btn-secondary {
  background: none;
  border: 1px solid var(--carabao-green);
  color: var(--carabao-green);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.btn-secondary:hover { background: #e9f6ee; }

.output-mode-btn {
  flex: 1;
  padding: 7px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  color: #555;
  transition: all 0.15s;
}
.output-mode-btn.active {
  background: #00843D;
  color: #fff;
  border-color: #00843D;
  font-weight: 600;
}
.output-mode-btn:hover:not(.active) { background: #f5f6fa; }

.role-badge {
  background: #fff3cd;
  color: #856404;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid #ffc107;
}

.hint-text {
  font-size: 12px;
  color: #888;
  margin-top: 10px;
  margin-bottom: 4px;
  line-height: 1.4;
}
.hint-text code {
  background: #eef0f5;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
}

.code-textarea {
  font-family: "SF Mono", "Consolas", "Monaco", monospace;
  font-size: 12px;
  background: #f7f8fb;
}

/* --- Collapsible API usage hint (bottom of page) --- */
.api-hint-section {
  margin-top: 20px;
  border-top: 1px solid #e4e6f0;
  padding-top: 16px;
}

.api-hint-toggle {
  width: 100%;
  text-align: left;
  background: #fff;
  border: 1px solid #d8dae5;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: #666;
  cursor: pointer;
}
.api-hint-toggle:hover { background: #f5f6fa; }

.api-hint-body {
  margin-top: 12px;
  background: #fff;
  border: 1px solid #e4e6f0;
  border-radius: 8px;
  padding: 18px 20px;
  font-size: 13px;
  line-height: 1.6;
  color: #333;
}

.api-hint-body h3 {
  font-size: 14px;
  margin: 16px 0 8px;
  color: var(--carabao-red-dark);
}
.api-hint-body h3:first-child { margin-top: 0; }

.api-hint-body pre {
  background: #1a1a2e;
  color: #e8e8f0;
  padding: 12px 14px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 12px;
  font-family: "SF Mono", "Consolas", "Monaco", monospace;
  margin: 8px 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.api-hint-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin: 8px 0;
}
.api-hint-body th, .api-hint-body td {
  border: 1px solid #e4e6f0;
  padding: 6px 10px;
  text-align: left;
}
.api-hint-body th { background: #f7f8fb; font-weight: 600; }

.api-hint-body code {
  background: #eef0f5;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

/* --- Apply confirmation modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-card {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  max-width: 480px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

.modal-card h2 { font-size: 18px; margin-bottom: 14px; color: var(--carabao-red-dark); }

.confirm-summary {
  list-style: none;
  margin: 12px 0;
  padding: 12px;
  background: #f7f8fb;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.7;
}
.confirm-summary li { word-break: break-word; }

.confirm-warning {
  font-size: 13px;
  font-weight: 600;
  color: #b02a2a;
  margin-top: 8px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}
.modal-actions .btn-secondary, .modal-actions .btn-primary { width: auto; flex: 1; margin-top: 0; }

/* --- Draft section --- */
.draft-section { margin-top: 4px; }
.draft-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.draft-title { font-weight: 600; font-size: 13px; color: var(--text); }
.draft-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: #fff3cd; color: #856404; border: 1px solid #ffc107;
  font-weight: 600;
}
.draft-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.draft-actions .btn-secondary { width: auto; flex: 1; min-width: 90px; }
.btn-danger {
  background: #fff0f0; color: var(--carabao-red);
  border: 1px solid #f5c6cb; border-radius: 6px; cursor: pointer;
  font-size: 13px; padding: 6px 12px;
}
.btn-danger:hover { background: #fce4e4; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* --- Chat header with clear button --- */
.chat-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.chat-header h2 { margin: 0; }
.btn-clear {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 10px; font-size: 12px; cursor: pointer; color: #888;
}
.btn-clear:hover { background: #f5f6fa; color: var(--carabao-red); border-color: var(--carabao-red); }

/* --- Async Job History panel --- */
.job-history-section {
  margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px;
}
.job-history-header {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 8px;
}
.job-history-list { display: flex; flex-direction: column; gap: 8px; max-height: 400px; overflow-y: auto; }
.job-card {
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  font-size: 12px; background: #fafafa;
}
.job-card-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.job-status-badge {
  padding: 2px 8px; border-radius: 10px; font-weight: 600; font-size: 11px;
}
.job-status-badge.completed { background: #d4edda; color: #155724; }
.job-status-badge.failed { background: #f8d7da; color: #721c24; }
.job-status-badge.partial { background: #fff3cd; color: #856404; }
.job-status-badge.processing, .job-status-badge.queued { background: #d1ecf1; color: #0c5460; }
.job-id { color: #888; font-family: monospace; font-size: 11px; }
.job-created { color: #aaa; font-size: 11px; margin-left: auto; }
.job-result-preview {
  margin-top: 6px; padding: 6px 8px; background: #fff; border: 1px solid #e9ecef;
  border-radius: 4px; font-size: 11px; white-space: pre-wrap; word-break: break-all;
  max-height: 120px; overflow-y: auto;
}
.job-expand-btn {
  background: none; border: none; color: var(--carabao-green); cursor: pointer;
  font-size: 11px; padding: 2px 0; text-decoration: underline;
}

