:root {
  color-scheme: light;
  --brand-primary: #2563eb;
  --brand-primary-dark: #1d4ed8;
  --brand-accent: #a855f7;
  --color-bg: #f5f7fb;
  --color-surface: #ffffff;
  --color-surface-elevated: #fdfdfd;
  --color-border: rgba(15, 23, 42, 0.08);
  --color-muted: #64748b;
  --color-text: #0f172a;
  --shadow-soft: 0 10px 30px rgba(15, 23, 42, 0.08);
  --shadow-card: 0 20px 60px rgba(15, 23, 42, 0.08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --brand-primary: #60a5fa;
  --brand-primary-dark: #3b82f6;
  --brand-accent: #c084fc;
  --color-bg: #0b1120;
  --color-surface: #111827;
  --color-surface-elevated: #1f2937;
  --color-border: rgba(148, 163, 184, 0.12);
  --color-muted: #94a3b8;
  --color-text: #e2e8f0;
  --shadow-soft: 0 10px 40px rgba(0, 0, 0, 0.55);
  --shadow-card: 0 30px 80px rgba(0, 0, 0, 0.65);
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  line-height: 1.6;
}

a {
  color: var(--brand-primary);
  text-decoration: none;
}

a:hover {
  color: var(--brand-primary-dark);
}

.app-shell {
  min-height: 100vh;
  background-image: radial-gradient(circle at 20% 20%, rgba(37, 99, 235, 0.12), transparent 45%),
    radial-gradient(circle at 80% 0%, rgba(168, 85, 247, 0.12), transparent 40%);
  background-color: var(--color-bg);
}

.app-navbar {
  background: var(--color-surface);
  box-shadow: var(--shadow-soft);
  border-bottom: 1px solid var(--color-border);
}

.app-navbar .navbar-brand {
  font-weight: 600;
  letter-spacing: 0.02em;
}

.nav-link,
.navbar-text {
  color: var(--color-muted) !important;
}

.nav-link.active,
.nav-link:hover {
  color: var(--brand-primary) !important;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 0.25rem 0.85rem;
  font-size: 0.9rem;
  background: var(--color-surface-elevated);
  color: var(--color-text);
  transition: all 0.2s ease;
}

.theme-toggle:hover {
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}

.theme-toggle .icon {
  font-size: 0.95rem;
}

.app-content {
  padding: 2rem 0 4rem;
}

.app-card {
  background: var(--color-surface);
  border-radius: 1.25rem;
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-card);
  padding: 1.5rem;
}

.bg-gradient {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.15), rgba(168, 85, 247, 0.15));
}

.metric-card {
  border-radius: 1.25rem;
  padding: 1.5rem;
  background: var(--color-surface);
  border: 1px solid transparent;
  box-shadow: var(--shadow-soft);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.metric-card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  height: 100%;
}

.metric-card-link .metric-card {
  height: 100%;
}

.metric-card:hover {
  transform: translateY(-4px);
  border-color: var(--brand-primary);
}

.metric-label {
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: var(--color-muted);
}

.metric-value {
  font-size: 2rem;
  font-weight: 600;
  margin-top: 0.3rem;
}

.badge-outline {
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-muted);
}

.feature-list {
  list-style: none;
  padding-left: 0;
}

.feature-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.feature-list li::before {
  content: "•";
  color: var(--brand-primary);
}

.text-muted {
  color: var(--color-muted) !important;
}

.list-group {
  border-radius: 1rem;
}

.list-group-item {
  background: var(--color-surface-elevated);
  border-color: var(--color-border);
  color: var(--color-text);
  transition: background 0.2s ease, color 0.2s ease;
}

.list-group-flush .list-group-item {
  border-left: 0;
  border-right: 0;
}

.list-group-item .text-muted,
.list-group-item small {
  color: var(--color-muted) !important;
}

.history-link {
  color: var(--color-text);
  text-decoration: none;
  display: block;
}

.history-link:hover .history-preview {
  color: var(--brand-primary);
}

.table-modern {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.table-modern thead {
  background: var(--color-surface-elevated);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
}

.table-modern th,
.table-modern td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--color-border);
}

.table-modern tbody tr:hover {
  background: rgba(37, 99, 235, 0.04);
}

.btn-soft {
  border-radius: 999px;
  padding: 0.45rem 1.6rem;
  font-weight: 500;
  border: none;
  background: var(--brand-primary);
  color: #fff;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 10px 30px rgba(37, 99, 235, 0.25);
}

.btn-soft:hover {
  transform: translateY(-2px);
  background: var(--brand-primary-dark);
}

.btn-soft.btn-danger {
  border-radius: 999px;
  padding: 0.48rem 1.7rem;
  font-weight: 600;
  border: none;
  background: linear-gradient(135deg, #ff9090, #ff5c5c) !important;
  color: #fff !important;
  box-shadow: 0 12px 32px rgba(255, 92, 92, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.btn-soft.btn-danger:hover,
.btn-soft.btn-danger:focus-visible {
  transform: translateY(-2px);
  background: linear-gradient(135deg, #ff6a6a, #ff3b3b) !important;
  box-shadow: 0 14px 34px rgba(255, 92, 92, 0.45);
  color: #fff !important;
}

.btn-outline-soft {
  border-radius: 999px;
  padding: 0.45rem 1.6rem;
  font-weight: 500;
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text);
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.btn-outline-soft.btn-outline-soft-danger {
  color: #dc3545;
  border-color: rgba(220, 53, 69, 0.4);
}

.btn-outline-soft.btn-outline-soft-danger:hover,
.btn-outline-soft.btn-outline-soft-danger:focus {
  color: #b02a37;
  border-color: rgba(220, 53, 69, 0.7);
  background: rgba(220, 53, 69, 0.1);
}

.auth-container {
  width: 100%;
  max-width: none;
  padding: 0;
  margin: 0 auto;
}

.auth-shell {
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem 1rem;
  background: radial-gradient(circle at 20% 20%, rgba(37, 99, 235, 0.12), transparent 45%),
    radial-gradient(circle at 80% 0%, rgba(168, 85, 247, 0.15), transparent 50%);
  border-radius: 2rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.96);
  border-radius: 1.5rem;
  border: 1px solid rgba(37, 99, 235, 0.08);
  box-shadow: 0 35px 70px rgba(15, 23, 42, 0.18);
  padding: 2.75rem 2.25rem;
}

.auth-card__header h1 {
  font-size: 1.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.auth-card__header p {
  color: var(--color-muted);
  margin-bottom: 0;
}

.auth-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(37, 99, 235, 0.12);
  color: var(--brand-primary);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.25rem 1.1rem;
  margin-bottom: 1rem;
}

.auth-form {
  margin-top: 2.2rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.auth-form__field {
  display: flex;
  flex-direction: column;
}

.auth-form__field label {
  font-weight: 500;
  display: block;
  margin-bottom: 0.35rem;
}

.auth-form input {
  width: 100%;
  border-radius: 0.95rem;
  border: 1px solid rgba(15, 23, 42, 0.15);
  padding: 0.85rem 1rem;
  background: rgba(248, 250, 255, 0.9);
  color: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.auth-form input:focus {
  border-color: var(--brand-primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
  outline: none;
}

.auth-error {
  font-size: 0.8rem;
  color: #dc3545;
  margin-top: 0.35rem;
}

.auth-submit {
  margin-top: 0.7rem;
  padding: 0.85rem 1.5rem;
  font-size: 1rem;
  border-radius: 0.95rem;
}

.auth-card__footer {
  margin-top: 1.6rem;
}

.auth-card__footer a {
  font-weight: 500;
}

.auth-alert {
  background: rgba(220, 53, 69, 0.12);
  border: 1px solid rgba(220, 53, 69, 0.3);
  color: #9f1239;
  border-radius: 1rem;
  padding: 0.85rem 1rem;
  font-size: 0.9rem;
  margin-top: 1.5rem;
}

.agent-form .form-switch .form-check-input {
  width: 3.2rem;
  height: 1.6rem;
  margin-top: 0;
}

@media (max-width: 576px) {
  .auth-card {
    padding: 2.2rem 1.6rem;
  }
}

.chat-window {
  display: flex;
  flex-direction: column;
  min-height: 420px;
  border-radius: 1.25rem;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  box-shadow: var(--shadow-soft);
}

.chat-messages {
  flex: 1;
  padding: 1.2rem;
  overflow-y: auto;
}

.chat-message {
  max-width: 85%;
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 1rem;
  background: var(--color-surface-elevated);
  box-shadow: inset 0 0 0 1px var(--color-border);
}

.chat-loader {
  width: 100px;
  height: 40px;
  --g: radial-gradient(
      farthest-side,
      transparent calc(95% - 3px),
      #fff calc(100% - 3px) 98%,
      transparent 101%
    )
    no-repeat;
  background: var(--g), var(--g), var(--g);
  background-size: 30px 30px;
  animation: chat-loader-pulse 1s infinite alternate;
  margin: 0 auto;
  display: block;
}

.chat-bubble.typing-indicator {
  opacity: 0.9;
  background: rgba(82, 70, 86, 0.08);
}

.chat-bubble.typing-indicator .bubble-content {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 78px;
}

.chat-bubble.typing-indicator .chat-loader {
  width: 85%;
  max-width: 210px;
}

@keyframes chat-loader-pulse {
  0% {
    background-position: 0 50%, 50% 50%, 100% 50%;
  }
  20% {
    background-position: 0 0, 50% 50%, 100% 50%;
  }
  40% {
    background-position: 0 100%, 50% 0, 100% 50%;
  }
  60% {
    background-position: 0 50%, 50% 100%, 100% 0;
  }
  80% {
    background-position: 0 50%, 50% 50%, 100% 100%;
  }
  100% {
    background-position: 0 50%, 50% 50%, 100% 50%;
  }
}

.chat-message.agent {
  margin-left: auto;
  background: rgba(37, 99, 235, 0.1);
  color: var(--color-text);
}

.chat-message.user {
  border-top-left-radius: 0.3rem;
}

.chat-footer {
  border-top: 1px solid var(--color-border);
  padding: 1rem 1.25rem;
  background: var(--color-surface-elevated);
}

.chat-footer textarea {
  width: 100%;
  border-radius: 0.9rem;
  border: 1px solid var(--color-border);
  min-height: 110px;
  padding: 0.95rem 1.1rem;
  background: transparent;
  color: inherit;
}

.chat-footer textarea:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select {
  border-radius: 0.9rem;
  border: 1px solid var(--color-border);
  padding: 0.75rem 1rem;
  background: transparent;
  color: inherit;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand-primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.chatgpt-board {
  display: flex;
  min-height: calc(100vh - 150px);
  border-radius: 1.5rem;
  border: 1px solid var(--color-border);
  overflow: hidden;
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
}

.chatgpt-sidebar {
  width: 320px;
  background: var(--color-surface-elevated);
  border-right: 1px solid var(--color-border);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.chatgpt-sidebar__history {
  overflow-y: auto;
  max-height: calc(100vh - 260px);
  padding-right: 0.25rem;
}

.agent-chip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.history-item {
  border: 1px solid var(--color-border);
  border-radius: 1rem;
  padding: 0.75rem;
  background: var(--color-surface);
}

.history-item form {
  margin: 0;
}

.history-trash {
  border: none;
  background: rgba(220, 53, 69, 0.12);
  color: #dc3545;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.history-trash i {
  pointer-events: none;
}

.history-trash:hover,
.history-trash:focus-visible {
  background: #dc3545;
  color: #fff;
}

.history-time {
  font-size: 0.75rem;
  color: var(--color-muted);
}

.history-preview {
  margin: 0.3rem 0 0;
  font-size: 0.9rem;
}

.chatgpt-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
}

.chatgpt-main__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid var(--color-border);
}

.chat-stream {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  background: var(--color-surface);
  scroll-behavior: smooth;
}

.chat-input {
  border-top: 1px solid var(--color-border);
  padding: 1rem 1.5rem 1.5rem;
  background: var(--color-surface-elevated);
}

.chat-input textarea {
  width: 100%;
  min-height: 140px;
  border-radius: 1rem;
  border: 1px solid var(--color-border);
  background: transparent;
  color: inherit;
  padding: 1rem 1.2rem;
  resize: vertical;
}

.chat-input__actions {
  margin-top: 0.75rem;
  text-align: right;
}

.chat-bubble {
  max-width: 820px;
  padding: 1rem 1.2rem;
  border-radius: 1.25rem;
  border: 1px solid var(--color-border);
  background: var(--color-surface-elevated);
  box-shadow: var(--shadow-soft);
  margin-bottom: 1.2rem;
}

.chat-bubble.agent {
  border-top-left-radius: 0.5rem;
}

.chat-bubble.user {
  margin-left: auto;
  background: linear-gradient(120deg, var(--brand-primary), var(--brand-accent));
  color: #fff;
  border: none;
}

.bubble-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  margin-bottom: 0.35rem;
  color: var(--color-muted);
}

.chat-bubble.user .bubble-meta {
  color: rgba(255, 255, 255, 0.8);
}

.bubble-content {
  font-size: 1rem;
  word-break: break-word;
}

.chat-bubble.user .bubble-content {
  color: #fff;
}

.chat-bubble.agent .bubble-content {
  color: var(--color-text);
}

.chat-bubble.is-typing .bubble-content::after {
  content: "▋";
  display: inline-block;
  margin-left: 4px;
  animation: blink-cursor 0.8s steps(2, start) infinite;
  color: var(--brand-primary);
}

.empty-state {
  text-align: center;
  color: var(--color-muted);
  padding: 3rem 0;
}

@keyframes blink-cursor {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@media (max-width: 992px) {
  .chatgpt-board {
    flex-direction: column;
  }

  .chatgpt-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    max-height: none;
  }

  .chatgpt-sidebar__history {
    max-height: 240px;
  }
}

.status-pill {
  padding: 0.15rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.status-pill.active {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}

.status-pill.inactive {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

@media (max-width: 768px) {
  .app-content {
    padding: 1.5rem 0 3rem;
  }

  .metric-card,
  .app-card {
    padding: 1.25rem;
  }

  .chat-message {
    max-width: 100%;
  }

  .theme-toggle {
    display: none;
  }
}
