:root {
  --bg: #0e1621;
  --bg-panel: #17212b;
  --bg-sidebar: #0e1621;
  --bg-bubble: #182533;
  --bg-bubble-own: #2b5278;
  --text: #e5e9ee;
  --text-dim: #8a97a3;
  --accent: #4ea1f3;
  --danger: #e05c5c;
  --border: #1f2c39;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text);
}

/* ---------- login / per-chat unlock ---------- */
.login-screen {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box {
  background: var(--bg-panel);
  padding: 40px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(90vw, 320px);
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}
.login-box h1 {
  margin: 0 0 6px;
  font-size: 20px;
  text-align: center;
}
.login-box input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 15px;
}
.login-box button[type="submit"] {
  background: var(--accent);
  color: #fff;
  padding: 12px;
  border-radius: 8px;
  font-weight: 600;
}
.login-error {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  margin: 0;
}

/* ---------- app layout ---------- */
.app {
  height: 100%;
  display: flex;
}

.sidebar {
  width: 280px;
  min-width: 220px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.sidebar-header button {
  font-size: 20px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
}
.sidebar-header button:hover { background: var(--bg-panel); }

.chat-list {
  flex: 1;
  overflow-y: auto;
}
.chat-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.chat-item:hover { background: var(--bg-panel); }
.chat-item.active { background: var(--bg-panel); border-left: 3px solid var(--accent); }
.chat-item-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.chat-item-delete {
  opacity: 0;
  color: var(--text-dim);
  font-size: 14px;
}
.chat-item:hover .chat-item-delete { opacity: 1; }
.chat-item-delete:hover { color: var(--danger); }

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 15px;
}

.chat-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  background: var(--bg-panel);
}
.chat-header-actions button {
  font-size: 15px;
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--text-dim);
}
.chat-header-actions button:hover { background: var(--bg); color: var(--text); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  max-width: min(70%, 640px);
  align-self: flex-end;
  background: var(--bg-bubble-own);
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14.5px;
  line-height: 1.45;
  word-wrap: break-word;
}
.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-time {
  font-size: 11px;
  color: rgba(255,255,255,0.55);
  text-align: right;
  margin-top: 4px;
}

.msg pre {
  background: #0d1117;
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 6px 0;
  position: relative;
  font-size: 13px;
}
.msg pre code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
}
.code-copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(255,255,255,0.08);
  color: #ccc;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
}
.code-copy-btn:hover { background: rgba(255,255,255,0.18); }

.msg-file {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.06);
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 4px;
  cursor: pointer;
}
.msg-file-icon { font-size: 20px; }
.msg-file-name { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-file-size { font-size: 11.5px; color: rgba(255,255,255,0.6); }
.msg-image {
  max-width: 100%;
  border-radius: 8px;
  display: block;
  margin-bottom: 4px;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
}
.composer textarea {
  flex: 1;
  resize: none;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14.5px;
  font-family: inherit;
  max-height: 200px;
}
#attach-btn, #send-btn {
  font-size: 18px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
}
#attach-btn:hover, #send-btn:hover { background: var(--bg); }
#send-btn { color: var(--accent); }

.file-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  max-width: 220px;
}
.file-preview button {
  color: var(--danger);
  font-size: 14px;
}

/* ---------- modal dialogs (replace prompt/confirm) ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-box {
  background: var(--bg-panel);
  padding: 28px;
  border-radius: 16px;
  width: min(90vw, 360px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}
.modal-box h2 {
  margin: 0;
  font-size: 18px;
}
.modal-box p {
  margin: 0;
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.4;
}
.modal-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.modal-field label {
  font-size: 13px;
  color: var(--text-dim);
}
.modal-field input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14.5px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}
.modal-actions button {
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
}
.modal-btn-cancel {
  color: var(--text-dim);
}
.modal-btn-cancel:hover { background: var(--bg); color: var(--text); }
.modal-btn-confirm { background: var(--accent); color: #fff; }
.modal-btn-confirm:hover { filter: brightness(1.08); }
.modal-btn-confirm.danger { background: var(--danger); }

/* ---------- toasts (replace alert) ---------- */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  align-items: center;
}
.toast {
  background: var(--bg-panel);
  border: 1px solid var(--danger);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.35);
  animation: toast-in 0.15s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .msg { max-width: 88%; }
}
