:root {
  --primary: #0065BD;       /* ČVUT blue */
  --primary-dark: #003D72;
  --primary-light: #E6F0FA;
  --accent: #00A3E0;
  --bg: #F4F7FB;
  --surface: #FFFFFF;
  --text: #1A2233;
  --muted: #5B6470;
  --border: #E2E8F0;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 16px rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* --- Top bar --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.logo {
  width: 44px;
  height: 44px;
  background: #fff;
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  flex-shrink: 0;
}

.brand-text h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-text .subtitle {
  margin: 2px 0 0;
  font-size: 13px;
  opacity: 0.85;
  font-weight: 400;
}

.meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  gap: 2px;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.10);
  backdrop-filter: blur(6px);
}

.meta-label {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10.5px;
  opacity: 0.8;
}

.meta-value {
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.meta.status-failed .meta-value::before {
  content: "⚠ ";
  color: #FFD66B;
}

/* --- Login overlay --- */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.login-overlay.hidden { display: none; }

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px 28px;
  width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.login-logo {
  width: 56px;
  height: 56px;
  background: var(--primary);
  border-radius: 12px;
  padding: 6px;
}

.login-box h2 {
  margin: 0;
  font-size: 20px;
  color: var(--primary-dark);
}

.login-box input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 120ms;
}

.login-box input:focus {
  border-color: var(--primary);
}

.login-box button {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms;
}

.login-box button:hover { background: var(--primary-dark); }
.login-box button:disabled { background: #B0BEC5; cursor: not-allowed; }

.login-error {
  margin: 0;
  font-size: 13px;
  color: #991B1B;
  min-height: 1.3em;
}

.hidden { display: none !important; }

/* --- Chat area --- */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px 16px;
  min-height: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 16px;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  max-width: 100%;
}

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

.message.assistant {
  justify-content: flex-start;
}

.bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.message.user .bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message.assistant.error .bubble {
  background: #FFF5F5;
  border-color: #FECACA;
  color: #991B1B;
}

.citations {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  font-size: 13px;
}

.citations-title {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
  margin-bottom: 6px;
}

.citations ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.citations a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.citations a:hover {
  text-decoration: underline;
  color: var(--primary-dark);
}

.citations a::before {
  content: "🔗 ";
  text-decoration: none;
  display: inline-block;
  margin-right: 4px;
}

/* Typing indicator */
.message.assistant.thinking .bubble {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.dots {
  display: inline-flex;
  gap: 4px;
}

.dots span {
  width: 6px;
  height: 6px;
  background: var(--primary);
  border-radius: 50%;
  animation: dot 1.2s infinite ease-in-out;
}

.dots span:nth-child(2) { animation-delay: 0.15s; }
.dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes dot {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* --- Composer --- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface);
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.composer textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.45;
  max-height: 180px;
  padding: 8px 4px;
  color: var(--text);
  background: transparent;
}

.composer textarea::placeholder {
  color: var(--muted);
}

.composer button {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms ease, transform 120ms ease;
}

.composer button:hover:not(:disabled) {
  background: var(--primary-dark);
}

.composer button:active:not(:disabled) {
  transform: scale(0.95);
}

.composer button:disabled {
  background: #B0BEC5;
  cursor: not-allowed;
}

/* --- Responsive --- */
@media (max-width: 640px) {
  .topbar {
    padding: 12px 14px;
    gap: 10px;
  }
  .brand-text h1 { font-size: 16px; }
  .brand-text .subtitle { display: none; }
  .meta { padding: 4px 8px; }
  .meta-label { display: none; }
  .bubble { max-width: 90%; }
  .chat { padding: 14px 10px 10px; }
}
