/* ===========================================================
   INNO Assistant — modern single-page chat styles
   =========================================================== */

:root {
  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-50: #eef2ff;
  --bg: #f8fafc;
  --bg-grad: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-soft: #94a3b8;
  --danger: #dc2626;
  --success: #16a34a;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.10);
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; }
input, textarea { font-family: inherit; font-size: inherit; color: inherit; }

/* =================== Auth page =================== */
body.auth {
  background: radial-gradient(ellipse at top, #e0e7ff 0%, #f1f5f9 50%, #f8fafc 100%);
  min-height: 100vh;
  display: flex;
}
.auth-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}
.auth-card {
  background: var(--surface);
  width: 380px;
  max-width: 100%;
  padding: 32px 28px 28px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.auth-header {
  text-align: center;
  margin-bottom: 24px;
}
.auth-logo {
  width: 112px;
  height: 112px;
  object-fit: contain;
  border-radius: 20px;
  margin-bottom: 16px;
}
.auth-card h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.auth-tagline {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}
.field {
  margin-bottom: 14px;
}
.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  font-size: 14px;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}
.btn-primary {
  width: 100%;
  padding: 11px 14px;
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-600); }
.btn-primary:active:not(:disabled) { transform: scale(0.99); }
.btn-primary:disabled { background: #a5b4fc; cursor: not-allowed; }
.error {
  color: var(--danger);
  min-height: 18px;
  margin-top: 10px;
  font-size: 13px;
  text-align: center;
}
.auth-note {
  margin: 12px 4px 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  text-align: center;
}
.step-info {
  background: var(--primary-50);
  color: var(--text);
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 10px;
  margin: 0 0 16px;
  line-height: 1.5;
}
.step-info strong {
  font-weight: 600;
  color: var(--primary);
}
.btn-link {
  width: 100%;
  background: none;
  border: 0;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  padding: 10px;
  margin-top: 4px;
}
.btn-link:hover { color: var(--primary); }
input[name="code"] {
  text-align: center;
  letter-spacing: 0.6em;
  font-size: 18px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 600;
}
.auth-footer {
  margin-top: 24px;
  font-size: 12px;
  color: var(--text-soft);
}

/* =================== Chat page =================== */
body.chat {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg-grad);
}

/* --- Top bar --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.topbar-logo {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 8px;
  flex-shrink: 0;
}
.topbar-brand {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-right {
  display: flex;
  gap: 10px;
  align-items: center;
}
.user-pill {
  background: var(--primary-50);
  color: var(--primary);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
}
.user-info-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
  min-width: 0;
}
.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}
.user-dept {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}
.user-dept:empty { display: none; }
.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}
.btn-refresh,
.btn-clear {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-clear:hover {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--danger);
}
.btn-clear-icon {
  font-size: 14px;
  line-height: 1;
  display: inline-block;
}
.btn-refresh-icon {
  font-size: 14px;
  line-height: 1;
  display: inline-block;
}
.btn-refresh.is-loading .btn-refresh-icon {
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 16px);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  max-width: 90vw;
}
.toast-in { opacity: 1; transform: translate(-50%, 0); }
.toast-ok { background: var(--success); }
.toast-error { background: var(--danger); }

/* --- Messages container --- */
.chat-shell {
  flex: 1;
  overflow-y: auto;
  padding: 28px 16px 16px;
  width: 100%;
}
.chat-shell > * {
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
}

/* --- Welcome screen --- */
.welcome {
  text-align: center;
  padding: 48px 16px 32px;
  color: var(--text-muted);
}
.welcome-logo {
  width: 140px;
  height: 140px;
  object-fit: contain;
  border-radius: 24px;
  margin-bottom: 20px;
}
.welcome h2 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}
.welcome p {
  margin: 0;
  font-size: 14px;
}
.welcome-desc {
  margin: 18px auto 0;
  max-width: 580px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px 14px 18px;
  box-shadow: var(--shadow-sm);
}
.welcome-desc-title {
  margin: 0 0 8px !important;
  font-size: 13px !important;
  font-weight: 600;
  color: var(--text);
}
.welcome-list {
  margin: 0;
  padding-left: 20px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-muted);
}
.welcome-list li {
  margin: 4px 0;
}
.welcome-list strong {
  color: var(--text);
  font-weight: 600;
}
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 24px;
}
.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
}
.chip:hover {
  background: var(--primary-50);
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

/* --- Messages --- */
.msg {
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  animation: msg-in 0.18s ease-out;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg.user { align-items: flex-end; }
.msg.assistant { align-items: flex-start; }

.bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user .bubble {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-600) 100%);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.25);
}
.msg.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-sm);
}
.msg.assistant .bubble strong { color: var(--text); }

.markdown-body {
  white-space: normal;
}
.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body p {
  margin: 0 0 10px;
}
.markdown-body h3,
.markdown-body h4,
.markdown-body h5 {
  margin: 14px 0 8px;
  font-size: 15px;
  line-height: 1.35;
  font-weight: 700;
}
.markdown-body h4 { font-size: 14px; }
.markdown-body h5 { font-size: 13px; }
.markdown-body ul,
.markdown-body ol {
  margin: 8px 0 10px;
  padding-left: 22px;
}
.markdown-body li {
  margin: 5px 0;
  padding-left: 2px;
}
.markdown-body code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}
.markdown-body pre {
  margin: 10px 0;
  padding: 10px 12px;
  overflow-x: auto;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 10px;
}
.markdown-body pre code {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
}
.markdown-body .table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 12px 0;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  min-width: 420px;
  background: var(--surface);
}
.markdown-body th,
.markdown-body td {
  padding: 9px 11px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.markdown-body th {
  background: var(--surface-2);
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}
.markdown-body tr:last-child td {
  border-bottom: 0;
}
.markdown-body td {
  color: var(--text);
}

.thinking {
  color: var(--text-soft);
  font-style: italic;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.thinking::after {
  content: "";
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--text-soft);
  margin-left: 4px;
  animation: blink 1.2s ease-in-out infinite;
}
@keyframes blink {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 1; }
}
.error-msg { color: var(--danger); }

.continue-hint {
  align-self: flex-start;
  margin-top: 8px;
  max-width: 85%;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--primary-50);
  border: 1px dashed var(--primary);
  color: var(--primary);
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.continue-hint:hover {
  background: var(--primary);
  color: #fff;
  border-style: solid;
}
.continue-hint:active { transform: scale(0.98); }

/* --- Source pill (compact single-line citation) --- */
.answer-sources {
  margin-top: 8px;
  max-width: 85%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.src-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.answer-sources-label {
  font-size: 11px;
  color: var(--text-soft);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 2px;
}
.src-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-muted);
  transition: all 0.15s ease;
  cursor: default;
  max-width: 100%;
}
.src-pill:hover {
  border-color: var(--primary);
  color: var(--text);
  background: var(--primary-50);
}
.src-pill-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
}
.src-pill-section {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

/* --- Composer (input) --- */
.composer {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--border);
  padding: 12px 16px 14px;
}
.composer #chatForm {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 6px 6px 6px 14px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer #chatForm:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.10);
}
#msg {
  flex: 1;
  resize: none;
  padding: 10px 0;
  border: 0;
  outline: none;
  background: transparent;
  max-height: 180px;
  line-height: 1.5;
}
#sendBtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: 12px;
  padding: 0 14px;
  height: 38px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}
#sendBtn:hover:not(:disabled) { background: var(--primary-600); }
#sendBtn:active:not(:disabled) { transform: scale(0.97); }
#sendBtn:disabled { background: #a5b4fc; cursor: not-allowed; }
#sendBtn svg { display: block; }

.composer-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-soft);
  margin: 8px 0 0;
}

.system-note {
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #fde68a;
  padding: 10px 14px;
  border-radius: 10px;
  margin: 10px auto;
  font-size: 13px;
  max-width: 760px;
}

/* --- Mobile --- */
@media (max-width: 600px) {
  .topbar { padding: 10px 14px; }
  .brand-sub { display: none; }
  .user-name { max-width: 140px; font-size: 12px; }
  .user-dept { max-width: 140px; font-size: 10px; }
  .topbar-logo { width: 32px; height: 32px; }
  .btn-refresh span:last-child,
  .btn-clear span:last-child { display: none; }
  .btn-refresh,
  .btn-clear { padding: 5px 9px; }
  .chat-shell { padding: 18px 12px 12px; }
  .composer { padding: 10px 12px 12px; }
  .bubble { max-width: 92%; }
  .answer-sources { max-width: 92%; }
  .composer-hint { display: none; }
  .welcome { padding: 32px 12px 16px; }
  .welcome-logo { width: 100px; height: 100px; }
  .welcome h2 { font-size: 20px; }
  .src-pill-section { max-width: 180px; }
}
