@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

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

:root {
  --navy:    #1a3a5c;
  --navy-dk: #112840;
  --navy-lt: #2a527e;
  --accent:  #2563a8;
  --bg:      #f0f2f5;
  --card:    #ffffff;
  --border:  #d1d9e0;
  --text:    #1e2d3d;
  --muted:   #5a7080;
  --user-bg: #e8f0f8;
  --bot-bg:  #ffffff;
  --red:     #c0392b;
  --green:   #27ae60;
  --shadow:  0 1px 4px rgba(0,0,0,.08);
}

html, body {
  height: 100%;
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  display: flex;
  flex-direction: column;
}

/* ─── THREE-COLUMN LAYOUT ────────────────────────────────────────────────── */

.main-grid {
  display: grid;
  grid-template-columns: 230px 1fr 250px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.chat-column {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

/* ─── SIDEBARS ───────────────────────────────────────────────────────────── */

.sidebar {
  overflow-y: auto;
  padding: 16px 14px;
  background: var(--card);
  -webkit-overflow-scrolling: touch;
}

.sidebar-title {
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* Left sidebar — recent questions */

.question-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.question-item {
  padding: 8px 10px;
  border-radius: 7px;
  font-size: .82rem;
  line-height: 1.4;
  color: var(--navy);
  background: var(--bg);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}

.question-item:hover {
  background: var(--user-bg);
  border-color: var(--border);
}

.question-item.muted {
  color: var(--muted);
  cursor: default;
  background: none;
}

.question-item.muted:hover {
  background: none;
  border-color: transparent;
}

/* Right sidebar — instructions */

.instructions {
  font-size: .82rem;
  line-height: 1.55;
  color: var(--text);
}

.instructions p {
  margin-bottom: 10px;
}

.instructions h3 {
  font-size: .78rem;
  font-weight: 600;
  color: var(--navy);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 14px 0 6px;
}

.instructions ul {
  padding-left: 14px;
  margin-bottom: 10px;
}

.instructions ul li {
  margin-bottom: 6px;
  color: var(--muted);
  font-style: italic;
}

.upload-invite {
  background: #eef4fb;
  border: 1px solid #c3d8f0;
  border-radius: 8px;
  padding: 12px;
  margin: 14px 0;
}

.upload-invite h3 {
  margin-top: 0 !important;
  color: var(--navy) !important;
  font-size: .8rem !important;
}

.upload-invite p {
  margin-bottom: 7px;
  color: var(--text);
}

.upload-invite p:last-child { margin-bottom: 0; }

.disclaimer {
  font-size: .75rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 14px !important;
}

/* ─── RESPONSIVE: hide sidebars on small screens ────────────────────────── */

@media (max-width: 900px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
  .sidebar { display: none; }
  .chat-column { border: none; }
}

/* ─── HEADER ─────────────────────────────────────────────────────────────── */

.site-header {
  background: var(--navy);
  color: #fff;
  padding: 18px 24px 14px;
  flex-shrink: 0;
}

.site-header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: .01em;
}

.site-header p {
  font-size: .82rem;
  opacity: .75;
  margin-top: 3px;
}

/* ─── CHAT AREA ──────────────────────────────────────────────────────────── */

.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  display: flex;
  gap: 10px;
  max-width: 92%;
  animation: fadein .2s ease;
}

.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.bot  { align-self: flex-start; }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 600;
  color: #fff;
}

.msg.user .msg-avatar { background: var(--navy-lt); }
.msg.bot  .msg-avatar { background: var(--accent); }

.msg-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.55;
  font-size: .9rem;
  box-shadow: var(--shadow);
}

.msg.user .msg-bubble {
  background: var(--user-bg);
  border-bottom-right-radius: 3px;
  color: var(--navy-dk);
}

.msg.bot .msg-bubble {
  background: var(--bot-bg);
  border-bottom-left-radius: 3px;
  border: 1px solid var(--border);
}

.summary-text { display: block; }

.full-text {
  display: none;
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
  color: var(--text);
  white-space: pre-wrap;
}

.full-text.open { display: block; }

.read-more {
  display: inline-block;
  margin-top: 6px;
  font-size: .8rem;
  color: var(--accent);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  text-decoration: underline;
}

.read-more:hover { color: var(--navy); }

/* ─── THINKING ───────────────────────────────────────────────────────────── */

.thinking {
  display: none;
  align-self: flex-start;
}

.thinking.active { display: flex; }

.thinking .msg-bubble {
  color: var(--muted);
  font-style: italic;
  font-size: .85rem;
}

.dot-anim::after {
  content: '';
  animation: dots 1.4s infinite;
}

@keyframes dots {
  0%   { content: ''; }
  33%  { content: '.'; }
  66%  { content: '..'; }
  100% { content: '...'; }
}

/* ─── INPUT AREA ─────────────────────────────────────────────────────────── */

.input-area {
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  flex-shrink: 0;
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: .9rem;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  max-height: 140px;
  overflow-y: auto;
  outline: none;
  transition: border-color .15s;
}

textarea:focus { border-color: var(--accent); }

.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-family: inherit;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}

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

.btn-primary:hover  { background: var(--navy-lt); }
.btn-primary:disabled { opacity: .5; cursor: default; }

.btn-secondary {
  background: var(--bg);
  color: var(--navy);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--border); }

.input-hint {
  font-size: .75rem;
  color: var(--muted);
  margin-top: 6px;
  text-align: center;
}

/* Upload feedback */
.upload-status {
  font-size: .8rem;
  margin-top: 6px;
  padding: 6px 10px;
  border-radius: 6px;
  display: none;
}

.upload-status.ok    { display: block; background: #eafaf1; color: var(--green); }
.upload-status.error { display: block; background: #fdf0ef; color: var(--red); }

/* ─── FOOTER ─────────────────────────────────────────────────────────────── */

.site-footer {
  background: var(--bg);
  border-top: 1px solid var(--border);
  text-align: center;
  padding: 8px 16px;
  font-size: .72rem;
  color: var(--muted);
  flex-shrink: 0;
}

/* ─── ANIMATIONS ─────────────────────────────────────────────────────────── */

@keyframes fadein {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── RESPONSIVE ─────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .site-header { padding: 14px 16px 10px; }
  .btn { padding: 9px 10px; }
}

/* ─── ADMIN ──────────────────────────────────────────────────────────────── */

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

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 10px;
}

.admin-header h1 {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--navy);
}

.stats-bar {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 18px;
  min-width: 110px;
  box-shadow: var(--shadow);
}

.stat-card .label {
  font-size: .72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.stat-card .value {
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--navy);
  line-height: 1.2;
}

.stat-card.dpc .value { color: var(--red); }

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--border);
}

.tab-btn {
  background: none;
  border: none;
  padding: 8px 18px;
  font-family: inherit;
  font-size: .9rem;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}

.tab-btn.active {
  color: var(--navy);
  font-weight: 600;
  border-bottom-color: var(--navy);
}

.filter-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.filter-row label { font-size: .8rem; color: var(--muted); display: block; margin-bottom: 3px; }

.filter-row input[type=text],
.filter-row input[type=date] {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: .85rem;
  color: var(--text);
  background: var(--bg);
}

.filter-row input[type=checkbox] { margin-right: 4px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .84rem;
  background: var(--card);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

thead { background: var(--navy); color: #fff; }
thead th { padding: 10px 12px; text-align: left; font-weight: 500; }
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f7f9fc; }
tbody td { padding: 9px 12px; vertical-align: top; }

.dpc-flag { font-size: 1rem; cursor: pointer; background: none; border: none; }

.expand-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: .8rem;
  text-decoration: underline;
  font-family: inherit;
  padding: 0;
}

.cell-overflow {
  max-width: 260px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
}

.cell-overflow.expanded {
  white-space: pre-wrap;
  max-width: none;
  overflow: visible;
}

.pagination {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 16px;
  font-size: .85rem;
}

.pagination a, .pagination span {
  padding: 4px 10px;
  border-radius: 5px;
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--navy);
}

.pagination a:hover { background: var(--navy); color: #fff; }
.pagination span.current { background: var(--navy); color: #fff; }

/* Login form */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 36px 40px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 4px 16px rgba(0,0,0,.08);
}

.login-card h2 {
  font-size: 1.1rem;
  color: var(--navy);
  margin-bottom: 20px;
}

.login-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-family: inherit;
  font-size: .9rem;
  margin-bottom: 12px;
  outline: none;
}

.login-card input:focus { border-color: var(--accent); }

.error-msg {
  color: var(--red);
  font-size: .83rem;
  margin-bottom: 10px;
}

.source-type {
  display: inline-block;
  font-size: .7rem;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--user-bg);
  color: var(--navy);
  margin-left: 6px;
}

.source-type.upload { background: #fef9e7; color: #7d6608; }
