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

:root {
  --primary: #3D3D3D;
  --primary-light: #555555;
  --accent: #6B7B3A;
  --accent-hover: #5A6930;
  --text: #333;
  --text-muted: #666;
  --text-light: #999;
  --border: #e0e0e0;
  --border-light: #f0f0f0;
  --bg: #f8f9fa;
  --bg-white: #fff;
  --success: #6B7B3A;
  --warning: #dc6b00;
  --danger: #dc3545;
  --info: #6B7B3A;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.admin-container {
  min-height: 100vh;
}

.admin-header {
  background: var(--primary);
  color: #fff;
  padding: 16px 24px;
  border-bottom: 1px solid var(--primary-light);
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.admin-header h1 {
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.3px;
}

/* ── Header controls (chatbot toggle) ── */
.header-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: rgba(255,255,255,0.85);
  cursor: pointer;
  user-select: none;
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.2);
  border-radius: 24px;
  transition: background 0.25s;
  cursor: pointer;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.25s;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.logout-btn {
  background: transparent;
  color: rgba(255,255,255,0.7);
  border: 1px solid rgba(255,255,255,0.25);
  padding: 6px 14px;
  border-radius: 3px;
  font-size: 12px;
  cursor: pointer;
}

.logout-btn:hover {
  color: #fff;
  border-color: rgba(255,255,255,0.5);
}

.admin-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 24px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 16px;
}

.search-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.search-filters input,
.search-filters select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 13px;
  background: var(--bg-white);
}

.search-filters input:focus,
.search-filters select:focus {
  outline: none;
  border-color: var(--accent);
}

.search-filters input {
  min-width: 280px;
}

#search-btn {
  padding: 8px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

#search-btn:hover {
  background: var(--primary-light);
}

.stats {
  font-size: 13px;
  color: var(--text-muted);
}

.status-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 10px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: all 0.15s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 500;
}

.inquiry-table-container {
  background: var(--bg-white);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.inquiry-table {
  width: 100%;
  border-collapse: collapse;
}

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

.inquiry-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.inquiry-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
}

.inquiry-table tbody tr:hover {
  background: var(--bg);
}

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

.status-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.status-badge.new {
  background: #f0f3e8;
  color: #6B7B3A;
}

.status-badge.in_progress {
  background: #fff4e5;
  color: #b45309;
}

.status-badge.completed {
  background: #e6f4ea;
  color: #137333;
}

.status-badge.rejected {
  background: #fce8e6;
  color: #c5221f;
}

.btn-primary {
  padding: 8px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.btn-primary:hover {
  background: var(--primary-light);
}

.btn-open {
  padding: 6px 12px;
  background: var(--bg-white);
  color: var(--primary);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}

.btn-open:hover {
  background: var(--bg);
  border-color: var(--primary);
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
}

.pagination button {
  padding: 6px 12px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  font-size: 13px;
}

.pagination button:hover:not(:disabled) {
  background: var(--bg);
}

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

#page-info {
  font-size: 13px;
  color: var(--text-muted);
}

.back-button {
  margin-bottom: 12px;
  padding: 6px 14px;
  background: var(--bg-white);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  font-size: 13px;
  flex-shrink: 0;
  align-self: flex-start;
  width: auto;
}

.back-button:hover {
  background: var(--bg);
}

#inquiry-detail-view.view.active {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 90px);
}

/* ── Detail layout ── */
.detail-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  align-items: stretch;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.detail-sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}

.sidebar-card {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px;
}

.sidebar-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-light);
}

.detail-meta-inline {
  font-size: 11px;
  color: var(--text-light);
}

.sidebar-card-body #contact-info {
  font-size: 13px;
  line-height: 1.6;
}

#contact-info .contact-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

#contact-info .contact-detail {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 2px;
}

.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-field {
  margin-bottom: 10px;
}

.sidebar-field:last-of-type {
  margin-bottom: 0;
}

.sidebar-field label {
  display: block;
  font-size: 11px;
  color: var(--text-light);
  margin-bottom: 5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.sidebar-field select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 13px;
  background: var(--bg-white);
}

.sidebar-field select:focus {
  outline: none;
  border-color: var(--accent);
}

.sidebar-action-row {
  display: flex;
  gap: 6px;
}

.sidebar-action-row select {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 13px;
  background: var(--bg-white);
}

.sidebar-action-row select:focus {
  outline: none;
  border-color: var(--accent);
}

.btn-sm {
  padding: 7px 12px !important;
  font-size: 12px !important;
  white-space: nowrap;
}

.btn-export {
  width: 100%;
  padding: 9px 16px;
  margin-top: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.btn-export:hover {
  background: var(--accent-hover);
}

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


/* ── Detail main ── */
.detail-main {
  background: var(--bg-white);
  border-radius: 6px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.detail-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  flex-shrink: 0;
}

.detail-tab {
  padding: 10px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
}

.detail-tab:hover {
  color: var(--text);
}

.detail-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 500;
}

.detail-tab-content {
  display: none;
  padding: 16px 20px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.detail-tab-content.active {
  display: flex;
  flex-direction: column;
}

.conversation-container {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.message-item {
  margin-bottom: 10px;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.5;
}

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

.message-item.user {
  background: #f0f3e8;
  margin-left: 20%;
  border: 1px solid #d4dbb8;
}

.message-item.bot {
  background: var(--bg);
  margin-right: 20%;
  border: 1px solid var(--border-light);
}

.message-meta {
  font-size: 11px;
  color: var(--text-light);
  margin-bottom: 3px;
}

.documents-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.document-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.document-item:last-child {
  border-bottom: none;
}

.document-item .doc-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
  margin-right: 12px;
}

.document-item a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  flex-shrink: 0;
}

.document-item a:hover {
  text-decoration: underline;
}

.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 9000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.visible {
  display: flex;
}

.modal-box {
  background: var(--bg-white);
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  padding: 28px 32px 22px;
  max-width: 420px;
  width: 90%;
  animation: modalIn 0.15s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-body {
  font-size: 14px;
  color: var(--text);
  line-height: 1.6;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-btn {
  padding: 8px 18px;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.modal-btn-cancel {
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.modal-btn-cancel:hover {
  background: var(--border-light);
}

.modal-btn-confirm {
  background: var(--accent);
  color: #fff;
}

.modal-btn-confirm:hover {
  background: var(--accent-hover);
}

.modal-btn-ok {
  background: var(--primary);
  color: #fff;
}

.modal-btn-ok:hover {
  background: var(--primary-light);
}

/* ── Toast notifications ── */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 12px 18px;
  font-size: 13px;
  color: var(--text);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  pointer-events: auto;
  animation: toastIn 0.2s ease-out;
  max-width: 360px;
}

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

.toast.success {
  border-left-color: var(--success);
}

.toast.fadeout {
  animation: toastOut 0.25s ease-in forwards;
}

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

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

@media (max-width: 1024px) {
  .detail-layout {
    grid-template-columns: 1fr;
    overflow: auto;
  }

  #inquiry-detail-view.view.active {
    height: auto;
  }
  
  .search-filters input {
    min-width: 200px;
  }
}
