/* === Reset & Base === */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #1c2333;
  --border: #30363d;
  --text: #e6edf3;
  --text2: #8b949e;
  --accent: #58a6ff;
  --accent2: #3fb950;
  --danger: #f85149;
  --audio: #d2a8ff;
  --summary-bg: #1a2332;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* === Login === */
.screen { height: 100vh; }
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0d1117 0%, #1a1f2e 100%);
}

.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3rem 2.5rem;
  text-align: center;
  width: 100%;
  max-width: 380px;
}

.login-icon { font-size: 3rem; margin-bottom: 1rem; }
.login-card h1 { font-size: 1.8rem; margin-bottom: 0.3rem; }
.login-card p { color: var(--text2); margin-bottom: 2rem; font-size: 0.95rem; }

.login-card input {
  width: 100%;
  padding: 0.8rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
.login-card input:focus { border-color: var(--accent); }

.login-card button {
  width: 100%;
  padding: 0.8rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}
.login-card button:hover { opacity: 0.9; }

.error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.8rem;
}

/* === Header === */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1.2rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 0.8rem; }
.header-left h1 { font-size: 1.2rem; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 0.8rem; }

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.3rem;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.icon-btn:hover { opacity: 1; }

.sync-badge {
  font-size: 0.7rem;
  color: var(--accent2);
  animation: pulse 2s infinite;
}
.sync-badge.offline { color: var(--danger); animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* === Search === */
.search-bar {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
}
.search-bar input {
  width: 100%;
  padding: 0.6rem 1rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}
.search-bar input:focus { border-color: var(--accent); }

/* === Room List === */
.panel { height: calc(100vh - 52px); }
.scrollable { overflow-y: auto; height: 100%; }

.room-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}
.room-item:hover { background: var(--bg2); }

.room-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  color: var(--accent);
  font-weight: 600;
}

.room-info { flex: 1; min-width: 0; }
.room-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-preview {
  color: var(--text2);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 0.15rem;
}

.room-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
  flex-shrink: 0;
}
.room-time {
  color: var(--text2);
  font-size: 0.75rem;
}
.room-badges { display: flex; gap: 0.3rem; }

.badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-weight: 600;
}
.badge.audio { background: rgba(210, 168, 255, 0.15); color: var(--audio); }
.badge.count { background: rgba(88, 166, 255, 0.15); color: var(--accent); }

/* === Room Detail === */
#room-detail {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.section {
  border-bottom: 1px solid var(--border);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1rem;
  background: var(--bg2);
}
.section-header h2 { font-size: 1rem; font-weight: 600; }

.section-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: var(--bg2);
  border-top: 1px solid var(--border);
}

.action-btn {
  padding: 0.5rem 1rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.action-btn:hover { border-color: var(--accent); color: var(--accent); }
.action-btn.small { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.action-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Period selector */
.period-selector { display: flex; gap: 0.3rem; }
.period-btn {
  padding: 0.3rem 0.7rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text2);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}
.period-btn:hover { color: var(--text); border-color: var(--accent); }
.period-btn.active {
  background: rgba(88, 166, 255, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

/* Summary box */
.summary-box {
  padding: 1rem;
  max-height: 300px;
  overflow-y: auto;
  background: var(--summary-bg);
  line-height: 1.6;
  font-size: 0.9rem;
}
.summary-box .placeholder { color: var(--text2); font-style: italic; }
.summary-box ul { padding-left: 1.2rem; }
.summary-box li { margin-bottom: 0.3rem; }
.summary-box strong { color: var(--accent); }

/* Messages */
#messages-section { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.messages { padding: 0.5rem; flex: 1; }

.message {
  display: flex;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  margin-bottom: 0.3rem;
  transition: background 0.1s;
}
.message:hover { background: var(--bg2); }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  flex-shrink: 0;
  font-weight: 600;
  color: var(--accent);
}
.msg-avatar.me { color: var(--accent2); }

.msg-content { flex: 1; min-width: 0; }
.msg-header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.15rem;
}
.msg-sender { font-weight: 600; font-size: 0.85rem; }
.msg-time { color: var(--text2); font-size: 0.7rem; }

.msg-text {
  font-size: 0.9rem;
  line-height: 1.5;
  word-break: break-word;
}

.msg-audio {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.7rem;
  background: rgba(210, 168, 255, 0.1);
  border: 1px solid rgba(210, 168, 255, 0.2);
  border-radius: 8px;
  color: var(--audio);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s;
}
.msg-audio:hover { background: rgba(210, 168, 255, 0.2); }
.msg-audio.transcribed {
  background: rgba(63, 185, 80, 0.1);
  border-color: rgba(63, 185, 80, 0.2);
  color: var(--accent2);
  cursor: default;
}

.msg-type-badge {
  font-size: 0.75rem;
  color: var(--text2);
  font-style: italic;
}

/* Loading / spinner */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--text2);
}
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 0.5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast notification */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.8rem 1.2rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  z-index: 1000;
  animation: slideIn 0.3s ease;
}
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--accent2); }

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

/* === Responsive === */
@media (max-width: 640px) {
  .login-card { padding: 2rem 1.5rem; margin: 1rem; }
  .section-header { flex-direction: column; gap: 0.5rem; align-items: flex-start; }
  .period-selector { flex-wrap: wrap; }
}
