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

body {
  font-family: Arial, sans-serif;
  background: #eef2f7;
  color: #1f2937;
}

/* Login page */
.login-page {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #111827;
}

.login-card {
  background: white;
  width: 360px;
  padding: 30px;
  border-radius: 14px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
  text-align: center;
}

.login-card h1 {
  color: #2563eb;
  margin-bottom: 8px;
}

.login-card h2 {
  margin-bottom: 20px;
}

.login-card input {
  width: 100%;
  padding: 12px;
  margin-bottom: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
}

.login-card button {
  width: 100%;
  padding: 12px;
  background: #2563eb;
  border: none;
  border-radius: 8px;
  color: white;
  font-weight: bold;
  cursor: pointer;
}

#errorMessage {
  color: #dc2626;
  margin-top: 12px;
  font-size: 14px;
}

/* Dashboard layout */
body:not(.login-page) {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 230px;
  background: #111827;
  color: white;
  padding: 24px 18px;
}

.sidebar h2 {
  font-size: 20px;
  margin-bottom: 30px;
  color: #38bdf8;
}

.nav-item {
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 8px;
  color: #d1d5db;
  font-size: 15px;
  cursor: pointer;
}

.nav-item:hover {
  background: #1f2937;
  color: white;
}

.nav-item.active {
  background: #2563eb;
  color: white;
}

.logout-btn {
  margin-top: 30px;
  width: 100%;
  padding: 10px;
  background: #dc2626;
  border: none;
  border-radius: 8px;
  color: white;
  cursor: pointer;
}

.logout-btn:hover {
  background: #b91c1c;
}

.main {
  flex: 1;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.status-pill {
  background: #dcfce7;
  color: #166534;
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: bold;
  font-size: 14px;
}

.hidden {
  display: none;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 20px;
}

.content-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
}

.single-card {
  margin-bottom: 20px;
}

.kb-docs-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.kb-docs-header h3 { margin: 0; }
.kb-docs-header button {
  width: auto;
  padding: 6px 14px;
  margin: 0;
  background: #e5e7eb;
  color: #1f2937;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.kb-docs-header button.delete-all-btn {
  background: #dc2626;
  color: white;
}
.kb-docs-header button.delete-all-btn:hover {
  background: #b91c1c;
}

.card {
  background: white;
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.card h3 {
  margin-bottom: 12px;
}

.card p {
  margin-bottom: 8px;
}

.big-value {
  font-size: 28px;
  font-weight: bold;
}

.card button {
  width: 100%;
  padding: 10px;
  margin-bottom: 10px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.card button:hover {
  background: #1d4ed8;
}

.section-description {
  margin-bottom: 14px;
  line-height: 1.4;
}

/* Knowledge base upload */
#kbUploadForm {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#kbUploadForm label {
  font-weight: bold;
  font-size: 14px;
}

#kbUploadForm input {
  padding: 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}

#kbUploadStatus {
  margin-top: 10px;
  font-weight: bold;
}

.status-message {
  color: #1f2937;
}

.success-message {
  color: #166534;
}

.error-message {
  color: #dc2626;
}

/* Document list */
#kbDocumentsList {
  margin-top: 12px;
}

.document-item {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
  background: #f9fafb;
}

.document-item p {
  margin-bottom: 6px;
  font-size: 14px;
}

.document-item span {
  font-weight: bold;
}

.document-item .delete-btn {
  margin-top: 8px;
  background: #dc2626;
}

.document-item .delete-btn:hover {
  background: #b91c1c;
}

/* Basic responsive support */
@media (max-width: 900px) {
  body:not(.login-page) {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
  }

  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .content-grid {
    grid-template-columns: 1fr;
  }
}

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

.session-summary-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.session-summary-box {
  padding: 12px;
  border-radius: 10px;
  background: #f1f5f9;
  border: 1px solid #dbe3ea;
}

.session-summary-box strong {
  display: block;
  margin-bottom: 6px;
  color: #334155;
}

.session-summary-box div {
  font-weight: 700;
  color: #0f172a;
  word-break: break-word;
}

.session-log-area {
  margin-top: 20px;
}

.session-messages-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.session-message-card {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  cursor: pointer;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.session-message-card:hover {
  border-color: #94a3b8;
}

.session-message-selected {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.35);
}

.session-message-user {
  background: #dbeafe;
}

.session-message-bot {
  background: #f1f5f9;
}

.session-message-label {
  font-weight: 700;
  margin-bottom: 4px;
  color: #0f172a;
}

.session-message-text {
  color: #334155;
  line-height: 1.4;
  white-space: pre-wrap;
}

.admin-session-history-list {
  margin-bottom: 20px;
}

.admin-session-history-list h3 {
  margin-bottom: 10px;
}

.admin-session-tab {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid #ccc;
  border-radius: 8px;
  background: #f7f7f7;
  cursor: pointer;
}

.admin-session-tab:hover {
  background: #eeeeee;
}

.admin-session-tab.active {
  border-color: #2563eb;
  background: #e8f0ff;
}

.admin-session-tab strong {
  display: block;
  margin-bottom: 4px;
}

.admin-session-tab span {
  font-size: 0.85rem;
  opacity: 0.75;
}

/* Analytics dashboard */
.analytics-stat-card .big-value {
  color: #2563eb;
}

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

.card button.small-btn {
  width: auto;
  padding: 8px 14px;
  margin-bottom: 0;
}

.daily-usage-chart {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.usage-bar-row {
  display: grid;
  grid-template-columns: 70px 1fr 34px;
  align-items: center;
  gap: 10px;
}

.usage-bar-label {
  font-size: 13px;
  color: #475569;
  font-weight: 700;
}

.usage-bar-track {
  height: 18px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

.usage-bar-fill {
  height: 100%;
  min-width: 4px;
  background: #2563eb;
  border-radius: 999px;
  transition: width 0.25s ease;
}

.usage-bar-value {
  font-size: 13px;
  font-weight: 700;
  color: #334155;
  text-align: right;
}

.analytics-list {
  margin-top: 12px;
  padding-left: 20px;
}

.analytics-list li {
  margin-bottom: 10px;
  line-height: 1.4;
}

.analytics-list li strong {
  float: right;
  background: #dbeafe;
  color: #1d4ed8;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  margin-left: 8px;
}

.analytics-list small {
  display: block;
  margin-top: 3px;
  color: #64748b;
  font-size: 12px;
}

@media (max-width: 900px) {
  .usage-bar-row {
    grid-template-columns: 56px 1fr 28px;
  }

  .analytics-header-row {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* Mobile-friendly admin layout */
@media (max-width: 700px) {
  body:not(.login-page) {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    white-space: nowrap;
  }

  .sidebar h2 {
    display: none;
  }

  .nav-item {
    margin-bottom: 0;
    flex: 0 0 auto;
    font-size: 14px;
    padding: 10px 12px;
  }

  .logout-btn {
    margin-top: 0;
    width: auto;
    flex: 0 0 auto;
    padding: 10px 12px;
  }

  .main {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    gap: 10px;
    flex-direction: column;
    margin-bottom: 16px;
  }

  .topbar h1,
  #pageTitle {
    font-size: 26px;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .content-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .card {
    padding: 16px;
    border-radius: 12px;
  }

  .session-summary-grid {
    grid-template-columns: 1fr;
  }

  .session-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .session-header button {
    width: 100%;
  }

  .kb-docs-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .kb-docs-header button {
    width: 100%;
  }

  .usage-bar-row {
    grid-template-columns: 54px 1fr 28px;
    gap: 8px;
  }

  .analytics-list li strong {
    float: none;
    display: inline-block;
    margin-left: 6px;
  }

  .login-card {
    width: calc(100% - 28px);
    padding: 24px;
  }
}