* {
  box-sizing: border-box;
}

:root {
  --scrollbar-size: 10px;
  --scrollbar-thumb: rgba(148, 163, 184, 0.28);
  --scrollbar-thumb-hover: rgba(148, 163, 184, 0.42);
  --scrollbar-track: rgba(15, 23, 42, 0.22);
}

html,
body {
  min-height: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  min-height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

*::-webkit-scrollbar {
  width: var(--scrollbar-size);
  height: var(--scrollbar-size);
}

*::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--scrollbar-thumb), rgba(148, 163, 184, 0.2));
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, var(--scrollbar-thumb-hover), rgba(148, 163, 184, 0.28));
  border: 2px solid transparent;
  background-clip: padding-box;
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

.hidden {
  display: none !important;
}

.container {
  min-height: 100vh;
  padding: 72px 24px 24px;
}

.notification-shell {
  position: fixed;
  top: 16px;
  right: 24px;
  z-index: 1000;
}

.toolbar-panels {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.toast-container {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(360px, calc(100vw - 32px));
  z-index: 1001;
  pointer-events: none;
}

.toast {
  background: rgba(17, 24, 39, 0.98);
  border: 1px solid #1f2937;
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  animation: toast-slide-fade 5s ease forwards;
  pointer-events: auto;
}

.toast.success {
  border-color: #1d4ed8;
}

.toast.error {
  border-color: #dc2626;
}

.toast-title {
  font-weight: 700;
  margin-bottom: 6px;
}

.toast-message {
  color: #cbd5e1;
  white-space: pre-wrap;
}

@keyframes toast-slide-fade {
  0% {
    opacity: 0;
    transform: translateY(-18px) scale(0.98);
  }

  10%,
  78% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  100% {
    opacity: 0;
    transform: translateY(-10px) scale(0.98);
  }
}

.settings-center,
.notification-center {
  position: relative;
}

.tools-panel {
  width: min(560px, calc(100vw - 32px));
  max-height: min(82vh, 860px);
  overflow-y: auto;
}

.tools-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tool-card {
  padding: 14px;
}

.notification-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid #1f2937;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.3);
}

.notification-toggle:hover {
  background: #0b1220;
}

.notification-icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.notification-badge {
  position: absolute;
  top: -4px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #dc2626;
  color: white;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
}

.notification-panel {
  position: absolute;
  top: 64px;
  right: 0;
  width: min(420px, calc(100vw - 32px));
  background: rgba(17, 24, 39, 0.98);
  border: 1px solid #1f2937;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  padding: 14px;
  max-height: min(70vh, 720px);
  overflow: hidden;
}

.settings-panel {
  width: min(520px, calc(100vw - 32px));
  max-height: min(80vh, 820px);
  overflow-y: auto;
}

.data-actions-panel {
  width: min(420px, calc(100vw - 32px));
}

.usage-toolbar-panel {
  width: min(560px, calc(100vw - 32px));
  max-height: min(82vh, 820px);
  overflow-y: auto;
}

.data-actions-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.data-action-button {
  width: 100%;
  text-align: left;
  background: #0b1220;
  border: 1px solid #1f2937;
  border-radius: 14px;
  padding: 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transition: all 0.18s ease;
}

.data-action-button:hover {
  background: #111827;
  border-color: #475569;
}

.data-action-icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
  flex-shrink: 0;
  margin-top: 2px;
}

.data-action-content {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.data-action-button:hover {
  background: #111827;
}

.data-action-title {
  font-weight: 700;
}

.data-action-subtle {
  color: #94a3b8;
  font-size: 13px;
}

.panel-subtle {
  margin: 0 0 12px;
}

.settings-form {
  gap: 10px;
}

.notification-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.notification-panel-header h2 {
  margin: 0;
  font-size: 18px;
}

.notification-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(min(70vh, 720px) - 72px);
  overflow-y: auto;
}

.notification-item {
  width: 100%;
  text-align: left;
  background: #0b1220;
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 12px;
}

.notification-item.active {
  border-color: #2563eb;
  background: #111827;
}

.notification-item:hover {
  background: #111827;
}

.notification-item-title {
  font-weight: 700;
  margin-bottom: 6px;
}

.notification-item-message {
  color: #cbd5e1;
  margin-bottom: 6px;
  white-space: pre-wrap;
}

.notification-item-time {
  color: #94a3b8;
  font-size: 12px;
}

.notification-dialog {
  position: fixed;
  inset: 0;
  z-index: 1100;
}

#server-log-detail-dialog {
  z-index: 1200 !important;
}

.server-log-detail-dialog {
  z-index: 1200;
}

.notification-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
}

.notification-dialog-content {
  position: relative;
  width: min(720px, calc(100vw - 32px));
  margin: 10vh auto 0;
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.4);
}

.notification-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.notification-dialog-header .app-modal-header-center {
  flex: 1;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.notification-dialog-header h2 {
  margin: 0;
}

.notification-dialog-body {
  background: #0b1220;
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 12px;
  margin-top: 12px;
  max-height: 55vh;
  overflow: auto;
}

.app-modal {
  position: fixed;
  inset: 0;
  z-index: 1190;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.app-modal.open {
  opacity: 1;
  pointer-events: auto;
}

.app-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.74);
}

.app-modal-content {
  position: relative;
  width: min(760px, calc(100vw - 32px));
  margin: 8vh auto 0;
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 20px;
  padding: 18px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.4);
  transform: translateY(16px) scale(0.98);
  transition: transform 0.24s ease;
}

.app-modal.open .app-modal-content {
  transform: translateY(0) scale(1);
}

.app-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.app-modal-header-center {
  flex: 1;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.app-modal-header-center h2 {
  margin: 0;
}

.app-modal-header h2 {
  margin: 0 0 6px;
}

.app-modal-header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.server-log-modal-header .app-modal-header-center {
  text-align: center;
}

.server-log-title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.server-log-connection-indicator {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  flex-shrink: 0;
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.server-log-connection-indicator.connected {
  background-color: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2), 0 0 8px rgba(34, 197, 94, 0.4);
}

.server-log-connection-indicator.connecting {
  background-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2), 0 0 8px rgba(245, 158, 11, 0.4);
  animation: pulse-connecting 1.5s ease infinite;
}

.server-log-connection-indicator.disconnected {
  background-color: #94a3b8;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.2);
}

@keyframes pulse-connecting {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.7;
    transform: scale(1.1);
  }
}

.app-modal-body {
  background: #0b1220;
  border: 1px solid #1f2937;
  border-radius: 14px;
  padding: 14px;
}

.data-import-modal-content {
  width: min(640px, calc(100vw - 32px));
}

.data-import-form {
  gap: 12px;
}

.database-modal-content {
  width: min(1480px, calc(100vw - 24px));
  height: min(88vh, 980px);
  margin-top: 4vh;
  display: flex;
  flex-direction: column;
}

.database-modal-body {
  flex: 1;
  min-height: 0;
  background: #0b1220;
  border: 1px solid #1f2937;
  border-radius: 14px;
  padding: 14px;
  overflow-y: auto;
}

.database-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.database-search-input {
  flex: 1;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid #1f2937;
  background: #020617;
  color: #e5e7eb;
  font-size: 13px;
}

.database-search-input::placeholder {
  color: #64748b;
}

.server-log-modal-content {
  width: min(1400px, calc(100vw - 24px));
  height: min(88vh, 980px);
  margin-top: 4vh;
  display: flex;
  flex-direction: column;
}

.server-log-filter-bar {
  display: flex;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid #1f2937;
  margin-bottom: 0;
}

.server-log-search-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #334155;
  border-radius: 10px;
  background: #0b1220;
  color: #e2e8f0;
  font-size: 14px;
}

.server-log-search-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.14);
}

.server-log-level-filter {
  padding: 10px 14px;
  border: 1px solid #334155;
  border-radius: 10px;
  background: #0b1220;
  color: #e2e8f0;
  font-size: 14px;
  min-width: 160px;
  cursor: pointer;
}

.server-log-level-filter:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.14);
}

.server-log-modal-body {
  flex: 1;
  min-height: 0;
  background: #0b1220;
  border: 1px solid #1f2937;
  border-radius: 14px;
  padding: 14px;
  overflow: hidden;
}

.server-log-list {
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-family: Consolas, "Courier New", monospace;
}

.server-log-entry {
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid #1f2937;
  border-left: 4px solid #475569;
  border-radius: 12px;
  padding: 12px;
}

.server-log-entry.info {
  border-left-color: #2563eb;
}

.server-log-entry.warn {
  border-left-color: #f59e0b;
}

.server-log-entry.error {
  border-left-color: #ef4444;
}

.server-log-entry.cost {
  border-left-color: #22c55e;
  background: rgba(34, 197, 94, 0.08);
}

.server-log-entry.cost .server-log-entry-message {
  color: #86efac;
}

.server-log-entry-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  color: #94a3b8;
  font-size: 12px;
}

.server-log-entry-level {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.server-log-entry-level.info {
  background: rgba(37, 99, 235, 0.16);
  color: #93c5fd;
}

.server-log-entry-level.warn {
  background: rgba(245, 158, 11, 0.16);
  color: #fcd34d;
}

.server-log-entry-level.error {
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
}

.server-log-entry-source {
  color: #cbd5e1;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.server-log-entry-cost {
  color: #22c55e;
  font-weight: 700;
  font-size: 13px;
  padding: 2px 8px;
  background: rgba(34, 197, 94, 0.16);
  border-radius: 6px;
}

.server-log-entry-time {
  margin-left: auto;
}

.server-log-entry-message {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: #e2e8f0;
}

.server-log-entry:hover {
  background: rgba(15, 23, 42, 0.98);
  border-color: #334155;
}

.server-log-detail-content {
  width: min(900px, calc(100vw - 32px));
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.server-log-detail-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 12px;
}

.server-log-detail-section {
  background: #0b1220;
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 14px;
}

.server-log-detail-section-title {
  font-weight: 700;
  font-size: 14px;
  color: #93c5fd;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.server-log-detail-section-content {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: #e2e8f0;
  font-size: 13px;
  line-height: 1.6;
}

.server-log-detail-section-content.code {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid #1f2937;
  border-radius: 8px;
  padding: 12px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  max-height: 400px;
  overflow-y: auto;
}

.prompt-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.prompt-modal.open {
  opacity: 1;
  pointer-events: auto;
}

.prompt-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.74);
}

.prompt-modal-content {
  position: relative;
  width: min(1100px, calc(100vw - 32px));
  margin: 7vh auto 0;
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 20px;
  padding: 18px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.4);
  transform: translateY(16px) scale(0.98);
  transition: transform 0.24s ease;
}

.prompt-modal.open .prompt-modal-content {
  transform: translateY(0) scale(1);
}

.prompt-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.prompt-modal-header .app-modal-header-center {
  flex: 1;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.prompt-modal-header h2 {
  margin: 0;
}

.prompt-modal-header-actions {
  display: flex;
  gap: 10px;
}

.prompt-modal-body {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
}

.prompt-library-list-wrap,
.prompt-editor-panel {
  background: #0b1220;
  border: 1px solid #1f2937;
  border-radius: 14px;
  padding: 12px;
}

.prompt-library-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 62vh;
  overflow-y: auto;
}

.prompt-library-item {
  width: 100%;
  text-align: left;
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 12px;
}

.prompt-library-item.active {
  border-color: #2563eb;
}

.prompt-library-item-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  margin-bottom: 6px;
}

.prompt-library-check {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18);
  flex: 0 0 auto;
}

.prompt-editor-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.prompt-editor-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.prompt-manager-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: #1f2937;
  border: 1px solid #334155;
}

.prompt-manager-indicator {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18);
}

.chat-stage {
  width: min(920px, calc(100vw - 40px));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.workspace-layout {
  width: min(1320px, calc(100vw - 40px));
  margin: 0 auto;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
}

.workspace-title {
  grid-column: 1 / -1;
}

.history-sidebar {
  position: sticky;
  top: 72px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: calc(100vh - 170px);
  min-height: 520px;
  overflow: hidden;
}

.history-sidebar-header h2 {
  margin: 0;
}

.history-sidebar-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 2px;
  min-height: 0;
  overflow-y: auto;
}

.history-sidebar-item {
  width: 100%;
  text-align: left;
  background: #0b1220;
  border: 1px solid #1f2937;
  border-radius: 14px;
  padding: 16px 12px 12px;
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
  position: relative;
  z-index: 0;
}

.history-sidebar-item:hover {
  background: #111827;
  transform: translateY(-1px);
  z-index: 1;
}

.history-sidebar-item.selected {
  border-color: #2563eb;
  background: rgba(37, 99, 235, 0.14);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.18);
}

.history-sidebar-item-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.history-sidebar-item-title {
  font-weight: 700;
  color: #ffffff;
}

.history-sidebar-item-title-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.history-sidebar-item-title-badge .check-icon {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: #22c55e;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #0b1120;
  font-size: 10px;
}

.history-sidebar-item-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.history-sidebar-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  background: #4b5563;
  color: #e5e7eb;
}

.history-sidebar-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-sidebar-avatar-bot {
  background: radial-gradient(circle at 30% 20%, #facc15, #f97316);
  color: #111827;
  font-size: 18px;
}

.history-sidebar-item-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-sidebar-item-preview {
  font-size: 13px;
  color: #cbd5f5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-sidebar-item-time {
  margin-top: 2px;
  color: #94a3b8;
  font-size: 12px;
  white-space: nowrap;
}

.history-sidebar-item-time {
  color: #94a3b8;
  font-size: 12px;
  white-space: nowrap;
}

.history-channel-tag {
  position: absolute;
  top: 2px;
  right: 10px;
  transform: translateY(0) rotate(180deg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 10px 4px;
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
  cursor: help;
  background: #2563eb;
  color: #fff;
  border-radius: 6px 6px 0 0;
  box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.25);
}

.history-channel-tag::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -6px;
  margin: 0 auto;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid #2563eb;
}

.history-channel-tag-icon {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
}

.history-channel-tag svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.history-channel-tag.testmode {
  background: #020617;
  color: #e5e7eb;
}

.history-channel-tag.testmode .history-channel-tag-icon {
  background: rgba(59, 130, 246, 0.22);
  color: #bfdbfe;
}

.history-channel-tag.facebook {
  background: #2563eb;
  color: #ffffff;
}

.history-channel-tag.facebook .history-channel-tag-icon {
  background: rgba(37, 99, 235, 0.22);
  color: #dbeafe;
}

.history-sidebar-item-preview {
  color: #cbd5e1;
  font-size: 13px;
  line-height: 1.45;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

.card {
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 16px;
  padding: 16px;
}

.hero-copy {
  text-align: center;
}

.hero-copy h1 {
  margin: 0;
  font-size: clamp(30px, 4.6vw, 52px);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat-topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
}

.chat-topbar-side {
  min-width: 0;
}

.chat-topbar-actions {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.chat-header-leading {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: center;
  align-items: center;
}

.chat-header-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #94a3b8;
}

.chat-header-title {
  margin: 0;
  font-size: 22px;
}

.chat-mode-inline {
  font-size: 12px;
  color: #94a3b8;
  white-space: nowrap;
}

.chat-clear-button {
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(220, 38, 38, 0.14);
  border: 1px solid rgba(248, 113, 113, 0.28);
  color: #fecaca;
  font-size: 12px;
  line-height: 1;
  min-height: 30px;
}

.chat-clear-button:hover {
  background: rgba(220, 38, 38, 0.22);
}

.subtle {
  color: #94a3b8;
}

form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

input,
textarea,
button {
  font: inherit;
}

input,
textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid #334155;
  border-radius: 10px;
  background: #0b1220;
  color: #e2e8f0;
}

button {
  padding: 12px 16px;
  border: 0;
  border-radius: 10px;
  background: #2563eb;
  color: white;
  cursor: pointer;
}

button:hover {
  background: #1d4ed8;
}

/* Icon Button Style - giống toolbar */
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border: 1px solid #334155;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.96);
  color: #e2e8f0;
  cursor: pointer;
  transition: all 0.18s ease;
  min-width: 36px;
  min-height: 36px;
}

.icon-button:hover {
  background: #0b1220;
  border-color: #475569;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  flex-shrink: 0;
}

/* Chat send button - giống Facebook Messenger */
.chat-send-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #2563eb;
  color: white;
  cursor: pointer;
  transition: all 0.18s ease;
  flex-shrink: 0;
  margin-bottom: 0;
}

.chat-send-button:hover {
  background: #1d4ed8;
  transform: scale(1.05);
}

.chat-send-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.icon-button.danger {
  border-color: rgba(248, 113, 113, 0.28);
  color: #fecaca;
}

.icon-button.danger:hover {
  background: rgba(220, 38, 38, 0.14);
  border-color: rgba(248, 113, 113, 0.4);
}

.danger-button {
  background: #dc2626;
}

.danger-button:hover {
  background: #b91c1c;
}

.chat-card {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: calc(100vh - 170px);
  max-height: calc(100vh - 170px);
  min-height: 520px;
}

.chat-log {
  flex: 1;
  min-height: 260px;
  max-height: none;
  overflow-y: auto;
  background: #0b1220;
  border: 1px solid #1f2937;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 0;
}

.chat-log.read-only {
  opacity: 0.88;
}

/* Chat messages */
.chat-message-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}

.chat-message-row.user {
  justify-content: flex-end;
}

.chat-message-row.bot {
  justify-content: flex-start;
}

.chat-message-avatar {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  text-transform: lowercase;
}

.chat-message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-bot {
  background: radial-gradient(circle at 30% 20%, #facc15, #f97316);
  color: #111827;
  font-size: 18px;
}

.avatar-admin {
  background: #0ea5e9;
  color: #0f172a;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.03em;
}

.avatar-user-fallback {
  background: #4b5563;
  color: #e5e7eb;
  font-weight: 600;
  font-size: 12px;
}

.chat-message-body {
  max-width: 78%;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-message-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #9ca3af;
}

.chat-message-row.user .chat-message-header {
  justify-content: flex-end;
  text-align: right;
}

.chat-message-row.user .chat-message-body {
  align-items: flex-end;
}

.chat-message-name {
  font-weight: 600;
  color: #e5e7eb;
}

.chat-message-meta {
  font-size: 11px;
  opacity: 0.9;
}

.chat-message-name-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.chat-message-name-badge .check-icon {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: #22c55e;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #0b1120;
  font-size: 10px;
}

.chat-bubble {
  padding: 8px 12px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.5;
}

.chat-bubble.user {
  background: #1e3a8a;
  color: #e5e7eb;
  border-bottom-left-radius: 4px;
}

.chat-bubble.bot {
  background: #020617;
  border: 1px solid #1e293b;
  color: #e5e7eb;
  border-bottom-right-radius: 4px;
}

.chat-mode-locked {
  opacity: 0.7;
  pointer-events: none;
}

.chat-form {
  margin-top: auto;
}

.chat-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #0b1220;
  border: 1px solid #334155;
  border-radius: 24px;
  padding: 8px 12px;
  position: relative;
}

.chat-input-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  transition: all 0.18s ease;
  flex-shrink: 0;
}

.chat-input-icon-button:hover {
  background: rgba(148, 163, 184, 0.1);
  color: #e2e8f0;
}

.chat-input-icon-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
.chat-input-text {
  flex: 1;
  resize: none;
  border: 0;
  background: transparent;
  color: #e2e8f0;
  font-size: 15px;
  line-height: 1.5;
  padding: 8px 4px;
  min-height: 36px;
  max-height: 120px;
  overflow-y: auto;
}

.chat-input-text:focus {
  outline: none;
}

.chat-input-text::placeholder {
  color: #64748b;
}

.chat-send-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  transition: all 0.18s ease;
  flex-shrink: 0;
}

.chat-send-button:hover {
  background: rgba(148, 163, 184, 0.1);
  color: #94a3b8;
}

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

.chat-send-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

pre {
  margin: 12px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.db-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
  max-height: 50vh;
  overflow-y: auto;
}

.database-list {
  margin-top: 0;
  max-height: none;
  overflow: visible;
}

.db-entry {
  background: #0b1220;
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 12px;
}

.db-entry-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: #94a3b8;
  font-size: 14px;
  cursor: pointer;
}

.db-entry-body {
  display: none;
  margin-top: 6px;
}

.db-entry.open .db-entry-body {
  display: block;
}

.db-entry-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  justify-content: flex-end;
}

.db-entry textarea {
  min-height: 140px;
  overflow: hidden;
  resize: none;
}

.usage-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.usage-metric {
  background: #0b1220;
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 12px;
}

.usage-metric-label {
  color: #94a3b8;
  font-size: 13px;
  margin-bottom: 6px;
}

.usage-metric-value {
  font-size: 18px;
  font-weight: 700;
}

.usage-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
  max-height: 55vh;
  overflow-y: auto;
}

.usage-entry {
  background: #0b1220;
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 12px;
}

.usage-entry-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.usage-entry-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.usage-entry pre {
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 10px;
  padding: 10px;
  max-height: 180px;
  overflow: auto;
}

.history-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
  max-height: 60vh;
  overflow-y: auto;
}

.history-conversation {
  background: #0b1220;
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 12px;
}

.history-conversation-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.history-conversation-meta {
  color: #94a3b8;
  font-size: 13px;
}

.history-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.history-message {
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 10px 12px;
}

.history-message.incoming {
  background: rgba(30, 58, 138, 0.55);
}

.history-message.outgoing {
  background: #111827;
}

.history-message-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 12px;
  color: #94a3b8;
}

.history-message-text {
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 900px) {
  .container {
    padding-top: 82px;
  }

  .workspace-layout {
    grid-template-columns: 1fr;
  }

  .workspace-title {
    grid-column: auto;
  }

  .history-sidebar {
    position: static;
    height: auto;
    max-height: none;
    min-height: auto;
  }

  .chat-card {
    min-height: auto;
    height: auto;
    max-height: none;
  }

  .chat-topbar {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 10px;
  }

  .chat-topbar-side {
    display: none;
  }

  .chat-topbar-actions {
    justify-self: center;
  }

  .chat-log {
    min-height: 280px;
    max-height: 44vh;
  }

  .usage-summary,
  .usage-entry-grid,
  .history-summary {
    grid-template-columns: 1fr;
  }

  .prompt-modal-body {
    grid-template-columns: 1fr;
  }

  .app-modal-header,
  .app-modal-header-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .database-modal-content {
    width: min(100vw - 16px, 1480px);
    height: min(92vh, 980px);
    margin-top: 2vh;
  }
}

