/* ============================================================
   Inquiry Institute — Faculty Chat
   Static chat UI, dark theme, responsive
   ============================================================ */

/* ---------- Reset & variables ---------- */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}

:root {
  --bg:        #212121;
  --bg-alt:    #2f2f2f;
  --sidebar:   #171717;
  --border:    #424242;
  --text:      #ececec;
  --text-dim:  #9e9e9e;
  --accent:    #c9a227;
  --accent-hover: #d4b340;
  --user-bg:   #2f2f2f;
  --assist-bg: #212121;
  --input-bg:  #2f2f2f;
  --danger:    #ef4444;
  --radius:    8px;
  --sidebar-w: 260px;
  --topbar-h:  52px;
  --font:      -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
}

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

body {
  display: flex;
}

/* Screen-reader only */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100%;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left .2s ease;
  z-index: 20;
}
.sidebar.collapsed {
  margin-left: calc(-1 * var(--sidebar-w));
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

.btn-new-chat {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: background .15s;
}
.btn-new-chat:hover { background: var(--bg-alt); }

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-icon:hover { background: var(--bg-alt); color: var(--text); }

/* Chat list */
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-dim);
  transition: background .15s, color .15s;
  position: relative;
}
.chat-item:hover { background: var(--bg-alt); color: var(--text); }
.chat-item.active { background: var(--bg-alt); color: var(--text); }

.chat-item-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-faculty {
  font-size: 11px;
  color: var(--accent);
  white-space: nowrap;
}

.chat-item-delete {
  display: none;
  position: absolute;
  right: 6px;
  padding: 2px 6px;
  font-size: 16px;
  color: var(--text-dim);
  background: var(--sidebar);
  border: none;
  cursor: pointer;
  border-radius: 4px;
}
.chat-item:hover .chat-item-delete { display: block; }
.chat-item-delete:hover { color: var(--danger); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.sidebar-link {
  display: block;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  transition: color .15s;
}
.sidebar-link:hover { color: var(--accent); }

/* ---------- Main area ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  position: relative;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--topbar-h);
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.topbar-spacer { flex: 1; }

.topbar-login {
  padding: 6px 12px;
  border-radius: var(--radius);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 14px;
  transition: background .15s, color .15s;
}
.topbar-login:hover { background: var(--bg-alt); color: var(--accent); }

/* Faculty selector dropdown */
.faculty-selector-wrapper {
  position: relative;
  flex: 1;
  max-width: 400px;
}

.faculty-selector-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: border-color .15s;
}
.faculty-selector-btn:hover {
  border-color: var(--accent);
}

.selector-btn-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
  margin-right: 4px;
  border: 1px solid var(--border);
}

.dropdown-arrow {
  font-size: 10px;
  color: var(--text-dim);
}

.faculty-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 400px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 100;
  display: none;
  flex-direction: column;
}
.faculty-dropdown:not(.hidden) {
  display: flex;
}

.faculty-search {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-alt);
}

.faculty-search input {
  width: 100%;
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
}
.faculty-search input:focus {
  outline: none;
  border-color: var(--accent);
}

.faculty-list {
  display: flex;
  flex-direction: row;
  overflow: hidden;
  width: 100%;
  flex: 1;
  min-height: 0;
}

.faculty-divisions-list {
  width: 200px;
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.faculty-members-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.faculty-members-list.visible {
  display: block;
}

@media (max-width: 480px) {
  .faculty-members-list.visible {
    display: flex;
    flex-direction: column;
  }
}

.faculty-division {
  border-bottom: 1px solid var(--border);
}
.faculty-division:last-child {
  border-bottom: none;
}

.faculty-division-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  cursor: pointer;
  transition: background .15s;
}
.faculty-division-header:hover,
.faculty-division-header.active {
  background: var(--bg);
}

.faculty-division-arrow {
  font-size: 10px;
  color: var(--text-dim);
  visibility: hidden;
}

.faculty-division-name {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.faculty-division-count {
  font-size: 12px;
  color: var(--text-dim);
}

.faculty-item {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background .15s;
  border-bottom: 1px solid rgba(255,255,255,.04);
  display: flex;
  align-items: center;
  gap: 10px;
}
.faculty-item:hover {
  background: var(--bg-alt);
  color: var(--accent);
}
.faculty-item:last-child {
  border-bottom: none;
}

.faculty-item-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg);
  border: 1px solid var(--border);
}

.faculty-item-initials {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

.faculty-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}


.faculty-select {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  cursor: pointer;
  max-width: 280px;
}
.faculty-select:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---------- Messages ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  display: none; /* hidden when welcome is shown */
  flex-direction: column;
}
.messages.visible {
  display: flex;
}

.message {
  padding: 20px 0;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.message:last-child { border-bottom: none; }

.message-inner {
  max-width: 768px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  gap: 16px;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 2px;
}
.message.user .message-avatar {
  background: #6366f1;
  color: #fff;
}
.message.assistant .message-avatar {
  background: var(--accent);
  color: #1a1a1a;
}

.message-body {
  flex: 1;
  min-width: 0;
}

.message-role {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text);
}

.message-content {
  color: var(--text);
  line-height: 1.7;
  word-wrap: break-word;
}

/* Markdown inside messages */
.message-content p { margin: 0 0 12px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content ul, .message-content ol { margin: 0 0 12px 20px; }
.message-content li { margin-bottom: 4px; }
.message-content blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 16px;
  margin: 8px 0;
  color: var(--text-dim);
  font-style: italic;
}
.message-content code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: rgba(255,255,255,.08);
  padding: 2px 5px;
  border-radius: 4px;
}
.message-content pre {
  background: #1e1e1e;
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: 12px 0;
  overflow-x: auto;
}
.message-content pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.5;
}
.message-content h1,.message-content h2,.message-content h3,
.message-content h4,.message-content h5,.message-content h6 {
  margin: 16px 0 8px;
  line-height: 1.3;
}
.message-content h1 { font-size: 1.4em; }
.message-content h2 { font-size: 1.2em; }
.message-content h3 { font-size: 1.1em; }
.message-content a { color: var(--accent); }
.message-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}
.message-content table {
  border-collapse: collapse;
  margin: 12px 0;
  width: 100%;
}
.message-content th, .message-content td {
  border: 1px solid var(--border);
  padding: 6px 12px;
  text-align: left;
}
.message-content th { background: rgba(255,255,255,.05); }

/* Streaming cursor */
.streaming .message-content::after {
  content: "▋";
  animation: blink .7s infinite;
  color: var(--accent);
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

/* ---------- Welcome screen ---------- */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  text-align: center;
}
.welcome.hidden { display: none; }

.welcome-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}
.welcome-subtitle {
  color: var(--text-dim);
  margin-bottom: 32px;
  font-size: 16px;
}

.welcome-grid {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.welcome-card {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid var(--border);
  transition: border-color .2s, transform .2s;
  position: relative;
}
.welcome-card:hover {
  border-color: var(--accent);
  transform: scale(1.05);
}
.welcome-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.welcome-card-initials {
  background: var(--bg-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
}

/* ---------- Input area ---------- */
.input-area {
  padding: 12px 24px 16px;
  flex-shrink: 0;
}

.input-form {
  max-width: 768px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  transition: border-color .15s;
}
.input-form:focus-within {
  border-color: var(--accent);
}

.chat-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  max-height: 200px;
  outline: none;
}
.chat-input::placeholder { color: var(--text-dim); }

.btn-send {
  width: 36px; height: 36px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity .15s;
  flex-shrink: 0;
}
.btn-send:disabled {
  opacity: .3;
  cursor: not-allowed;
}
.btn-send:not(:disabled):hover {
  background: var(--accent-hover);
}

.input-disclaimer {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 8px;
  max-width: 768px;
  margin-left: auto;
  margin-right: auto;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100%;
  }
  .sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-w));
  }
  .sidebar-close-btn { display: flex; }

  .message-inner { padding: 0 16px; }
  .input-area { padding: 8px 12px 12px; }
  .welcome-title { font-size: 1.5rem; }

  /* Mobile dropdown improvements */
  .faculty-dropdown {
    max-height: min(500px, 70vh);
  }

  .faculty-divisions-list {
    width: 140px;
    min-width: 140px;
  }

  .faculty-division-header {
    padding: 14px 10px;
    min-height: 48px;
  }

  .faculty-division-name {
    font-size: 12px;
  }

  .faculty-item {
    padding: 10px 12px;
    min-height: 48px;
    font-size: 14px;
  }

  .faculty-item-avatar {
    width: 36px;
    height: 36px;
  }

  .faculty-search input {
    padding: 10px;
    min-height: 44px;
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  /* Single column layout for very small screens */
  .faculty-selector-wrapper {
    max-width: none;
  }

  .faculty-dropdown {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    bottom: 0;
    max-height: none;
    border-radius: 0;
    border-left: none;
    border-right: none;
    flex-direction: column;
  }

  .faculty-list {
    flex-direction: column;
    flex: 1;
    overflow: hidden;
  }

  .faculty-divisions-list {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: none;
    flex-shrink: 0;
  }

  .faculty-divisions-list.hidden-mobile {
    display: none;
  }

  .faculty-members-list {
    width: 100%;
    flex: 1;
  }

  .faculty-members-back {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    background: var(--bg-alt);
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
  }
  .faculty-members-back:hover {
    background: var(--bg);
  }

  .faculty-division-header {
    padding: 16px;
    min-height: 52px;
  }

  .faculty-division-name {
    font-size: 14px;
  }

  .faculty-item {
    padding: 16px;
    min-height: 52px;
    font-size: 15px;
  }
}

@media (min-width: 769px) {
  .sidebar-close-btn { display: none; }
}
