:root {
  --bg: #0e1116;
  --panel: #151a21;
  --panel-2: #1b222c;
  --line: #2a3441;
  --text: #f4f7fb;
  --muted: #9aa8b8;
  --accent: #4f9cf9;
  --accent-2: #2d7fe4;
  --danger: #ff6b6b;
  --bubble: #153f69;
  --shadow: 0 22px 70px rgba(0,0,0,.36);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 5%, rgba(79,156,249,.10), transparent 30rem),
    linear-gradient(180deg, #0d1116 0%, #11161d 100%);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

.login-view {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card, .setup-card {
  width: min(100%, 430px);
  padding: 34px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 26px;
  background: rgba(21,26,33,.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}
.lock-mark, .setup-icon {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  margin-bottom: 22px;
  border-radius: 18px;
  background: linear-gradient(145deg, #276fc7, #4f9cf9);
  font-size: 30px;
  font-weight: 800;
  box-shadow: 0 10px 30px rgba(79,156,249,.22);
}
.eyebrow {
  margin: 0 0 9px;
  color: #70affb;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .16em;
}
h1 { margin: 0; font-size: clamp(30px, 7vw, 40px); letter-spacing: -.035em; }
.login-copy, .setup-intro, .setup-card > p { color: var(--muted); line-height: 1.55; }
.login-form, .setup-form { display: grid; gap: 14px; margin-top: 28px; }
label { color: #c9d3df; font-size: 13px; font-weight: 650; }
.password-wrap { position: relative; }
input, textarea {
  width: 100%;
  color: var(--text);
  background: #0f141a;
  border: 1px solid var(--line);
  outline: none;
  transition: .18s ease;
}
input:focus, textarea:focus { border-color: #5ba4fa; box-shadow: 0 0 0 3px rgba(79,156,249,.12); }
input { height: 50px; padding: 0 14px; border-radius: 13px; }
.password-wrap input { padding-right: 52px; }
.icon-btn {
  position: absolute;
  inset: 5px 5px 5px auto;
  width: 42px;
  border: 0;
  border-radius: 10px;
  color: #ccd6e2;
  background: transparent;
  cursor: pointer;
}
.primary-btn {
  min-height: 50px;
  display: inline-grid;
  place-items: center;
  padding: 0 20px;
  border: 0;
  border-radius: 13px;
  color: white;
  background: linear-gradient(145deg, var(--accent-2), var(--accent));
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(79,156,249,.18);
}
.primary-btn:disabled { opacity: .55; cursor: default; }
.form-error { min-height: 18px; margin: 0; color: #ff8585; font-size: 13px; }

.app-view { min-height: 100vh; min-height: 100dvh; padding-bottom: 92px; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 68px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(8px, env(safe-area-inset-top)) 16px 8px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  background: rgba(14,17,22,.82);
  backdrop-filter: blur(20px);
}
.avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(145deg, #2c78d1, #65aefc);
  font-weight: 850;
}
.topbar-copy { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.topbar-copy strong { font-size: 15px; }
.topbar-copy span { color: var(--muted); font-size: 11px; }
.topbar-btn {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 12px;
  color: #d9e3ed;
  background: #171d24;
  cursor: pointer;
}
.messages {
  width: min(100%, 860px);
  min-height: calc(100vh - 160px);
  margin: 0 auto;
  padding: 28px 16px 130px;
  display: flex;
  flex-direction: column;
  gap: 13px;
}
.message { display: flex; justify-content: flex-end; }
.bubble {
  width: fit-content;
  max-width: min(78%, 620px);
  min-width: 150px;
  padding: 11px 12px 7px;
  border-radius: 18px 18px 5px 18px;
  background: linear-gradient(145deg, #174873, var(--bubble));
  box-shadow: 0 7px 24px rgba(0,0,0,.16);
}
.message-text { line-height: 1.45; word-break: break-word; white-space: normal; }
.message-meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
  color: rgba(255,255,255,.64);
  font-size: 10px;
}
.delete-message {
  width: 26px;
  height: 22px;
  border: 0;
  border-radius: 7px;
  color: rgba(255,255,255,.7);
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  line-height: 10px;
}
.attachments { display: grid; gap: 8px; margin-top: 8px; }
.attachment { overflow: hidden; border-radius: 13px; background: rgba(0,0,0,.22); }
.image-attachment img { display: block; max-width: 100%; max-height: 390px; object-fit: contain; background: rgba(0,0,0,.2); }
.image-link { display: block; }
.attachment-bar { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.attachment-bar span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.download-link, .file-action { color: #d7ebff; text-decoration: none; font-weight: 800; }
.pdf-attachment { display: flex; align-items: center; gap: 10px; padding: 10px; }
.pdf-icon { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 10px; background: #da4d55; color: white; font-size: 11px; font-weight: 900; }
.pdf-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.pdf-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.pdf-copy small { color: rgba(255,255,255,.62); }
.file-action { padding: 7px 8px; border-radius: 8px; background: rgba(255,255,255,.08); font-size: 11px; }
.empty-state { margin: auto; text-align: center; color: var(--muted); }
.empty-icon { font-size: 44px; opacity: .85; }
.empty-state h2 { margin: 14px 0 6px; color: #e8eef5; font-size: 19px; }
.empty-state p { margin: 0; font-size: 14px; }

.composer {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 30;
  width: min(100%, 860px);
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(14,17,22,0), rgba(14,17,22,.98) 22%);
}
.composer textarea {
  min-height: 48px;
  max-height: 140px;
  resize: none;
  padding: 13px 15px;
  border-radius: 18px;
  line-height: 1.35;
}
.composer-btn, .send-btn {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 16px;
  color: white;
  cursor: pointer;
}
.composer-btn { background: #202832; font-size: 26px; }
.send-btn { background: linear-gradient(145deg, var(--accent-2), var(--accent)); font-size: 20px; }
.upload-tray {
  position: fixed;
  left: 50%;
  bottom: 74px;
  z-index: 29;
  width: min(calc(100% - 28px), 832px);
  transform: translateX(-50%);
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(21,26,33,.97);
  box-shadow: var(--shadow);
}
.selected-files { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 3px; }
.file-chip {
  min-width: 180px;
  max-width: 260px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  padding: 8px 9px;
  border-radius: 11px;
  background: #222a34;
}
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.file-chip small { color: var(--muted); font-size: 10px; }
.file-chip button { grid-row: 1 / span 2; grid-column: 2; border: 0; color: #cbd5df; background: transparent; cursor: pointer; font-size: 20px; }
.text-btn { margin-top: 7px; border: 0; color: #9ac6fb; background: transparent; cursor: pointer; font-size: 11px; }
.busy-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  background: rgba(7,10,13,.72);
  backdrop-filter: blur(6px);
}
.spinner { width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.18); border-top-color: white; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed;
  left: 50%;
  bottom: 105px;
  z-index: 60;
  transform: translateX(-50%);
  max-width: min(90vw, 440px);
  padding: 10px 14px;
  border-radius: 12px;
  background: #e8f3ff;
  color: #102030;
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 700;
}
.toast.error { background: #ffdcdc; color: #5b1717; }

.setup-body { padding: 30px 16px; }
.setup-shell { min-height: calc(100vh - 60px); display: grid; place-items: center; }
.setup-card { width: min(100%, 680px); }
.setup-card h1 { margin-bottom: 12px; }
.setup-form fieldset { margin: 0; padding: 18px; display: grid; gap: 14px; border: 1px solid var(--line); border-radius: 16px; }
.setup-form legend { padding: 0 7px; color: #e8eef5; font-weight: 800; }
.setup-form label { display: grid; gap: 7px; }
.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.setup-error { margin: 20px 0; padding: 12px 14px; border: 1px solid rgba(255,107,107,.35); border-radius: 12px; color: #ffadad; background: rgba(255,107,107,.09); }
.setup-note { margin-top: 18px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.setup-link { margin-top: 18px; }
code { color: #cfe6ff; }

@media (max-width: 700px) {
  .login-card, .setup-card { padding: 26px 22px; border-radius: 22px; }
  .messages { padding-left: 10px; padding-right: 10px; }
  .bubble { max-width: 88%; }
  .setup-grid { grid-template-columns: 1fr; }
  .pdf-attachment:not(.generic-attachment) .file-action:first-of-type {
  display: none;
}
}
.file-icon {
    width: auto;
    min-width: 42px;
    padding: 0 7px;
    background: rgba(255,255,255,.12);
}

.generic-attachment .file-action {
    white-space: nowrap;
}