:root {
  --bg: #12141a;
  --panel: #191c24;
  --elevated: #232733;
  --border: #2a2f3c;
  --text: #eef0f4;
  --text-muted: #8b93a3;
  --accent: #e0a458;
  --accent-dim: #7a5c33;
  --bubble-mine: #2c3547;
  --bubble-theirs: #1f232d;
  --danger: #e07a6d;
  --overlay: rgba(255,255,255,0.04);
  --tick-unread: #4d5563;
  --tick-read: #4ade80;
  --radius: 14px;
  font-size: 16px;
}

:root[data-theme="light"] {
  --bg: #eef0f4;
  --panel: #ffffff;
  --elevated: #f4f5f8;
  --border: #dde1e8;
  --text: #1a1d24;
  --text-muted: #6b7280;
  --accent: #c9853f;
  --accent-dim: #ecd2ac;
  --bubble-mine: #fdead2;
  --bubble-theirs: #f1f2f5;
  --danger: #c0392b;
  --overlay: rgba(17,20,26,0.045);
  --tick-unread: #aab0ba;
  --tick-read: #1a9850;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.theme-toggle {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 50;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--elevated);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hidden { display: none !important; }

.screen {
  height: 100vh;
  height: 100dvh;
  width: 100%;
}

/* ---------- brand ---------- */

.brand-mark {
  font-family: "SF Mono", "JetBrains Mono", ui-monospace, Consolas, monospace;
  font-weight: 700;
  font-size: 28px;
  letter-spacing: 0.5px;
  color: var(--text);
}
.brand-mark::after {
  content: "";
}
.brand-mark small, .brand-mark.small {
  font-size: 18px;
}
/* the "!" gets the ember accent */
.brand-mark {
  position: relative;
}

/* ---------- auth screen ---------- */

#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 20% 15%, rgba(224,164,88,0.08), transparent 45%),
    var(--bg);
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
}

.brand { text-align: center; margin-bottom: 28px; display: flex; flex-direction: column; gap: 4px; }
.brand-sub { color: var(--text-muted); font-size: 13px; letter-spacing: 0.4px; text-transform: uppercase; }

.tabs {
  display: flex;
  background: var(--elevated);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 22px;
}
.tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 9px 0;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.tab.active {
  background: var(--bg);
  color: var(--text);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}
.auth-form input {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.auth-form input:focus {
  border-color: var(--accent);
}
.auth-form button[type="submit"] {
  margin-top: 4px;
  background: var(--accent);
  color: #1a1305;
  border: none;
  border-radius: 10px;
  padding: 11px 0;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.auth-form button[type="submit"]:active { transform: translateY(1px); }

.form-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
  margin: 0;
}

.form-hint {
  color: var(--text-muted);
  font-size: 12.5px;
  margin: 0;
}

.link-btn {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 12.5px;
  cursor: pointer;
  padding: 2px 0;
  text-align: left;
  align-self: flex-start;
}
.link-btn:disabled {
  color: var(--text-muted);
  cursor: default;
}

#reset-flow {
  gap: 10px;
}
#reset-flow form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- app screen ---------- */

#app-screen {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 0;
}

#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
#logout-btn, .icon-btn {
  background: var(--elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 34px; height: 34px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 15px;
}
.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.icon-btn.active {
  color: var(--accent);
  border-color: var(--accent);
}

.operator-panel {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}

.verify-banner {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--overlay);
}
.verify-banner p {
  margin: 0 0 8px;
  font-size: 12.5px;
  color: var(--text-muted);
}
#verify-email-form {
  display: flex;
  gap: 6px;
}
#verify-email-form input {
  flex: 1;
  min-width: 0;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
#verify-email-form input:focus { border-color: var(--accent); }
#verify-email-form button {
  background: var(--accent);
  color: #1a1305;
  border: none;
  border-radius: 8px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}
.verify-banner .link-btn {
  margin-top: 6px;
}
#install-app-btn {
  width: 100%;
  background: var(--accent);
  color: #1a1305;
  border: none;
  border-radius: 8px;
  padding: 8px 0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
#generate-invite-btn {
  width: 100%;
  background: var(--elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 0;
  border-radius: 10px;
  font-size: 13.5px;
  cursor: pointer;
}
.invite-code-display {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}
.invite-code-display code {
  flex: 1;
  font-family: "SF Mono", ui-monospace, Consolas, monospace;
  font-size: 13px;
  letter-spacing: 0.4px;
  color: var(--accent);
  overflow-x: auto;
  white-space: nowrap;
}
#copy-invite-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  flex-shrink: 0;
}
.invite-code-timer {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-box {
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
}
.search-box input {
  flex: 1;
  min-width: 0;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 13.5px;
  outline: none;
}
.search-box input:focus { border-color: var(--accent); }
.search-box .icon-btn {
  width: auto;
  padding: 0 12px;
  font-size: 17px;
  flex-shrink: 0;
}

.contacts {
  overflow-y: auto;
  flex: 1;
}
.contact {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.contact:hover { background: var(--elevated); }
.contact.active {
  background: var(--elevated);
  border-left-color: var(--accent);
}
.avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--elevated);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: 14px;
  color: var(--accent);
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.contact-meta { min-width: 0; flex: 1; }
.contact-name { font-size: 14.5px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-preview { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contacts-empty { padding: 18px; color: var(--text-muted); font-size: 13.5px; }

#chat-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }

.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
}

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

#chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  font-weight: 600;
}

.back-btn {
  display: none; /* only relevant on the narrow mobile layout - see media query below */
}

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

.msg-row { display: flex; }
.msg-row.mine { justify-content: flex-end; }

.bubble {
  max-width: min(520px, 78%);
  padding: 4px 11px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.35;
  word-wrap: break-word;
  white-space: pre-wrap;
  background: var(--bubble-theirs);
}
.msg-row.mine .bubble {
  background: var(--bubble-mine);
  border-bottom-right-radius: 4px;
}
.msg-row:not(.mine) .bubble {
  border-bottom-left-radius: 4px;
}

.bubble .time {
  display: block;
  margin-top: 0;
  font-size: 10.5px;
  color: var(--text-muted);
  text-align: right;
}

.ticks {
  margin-left: 5px;
  color: var(--tick-unread);
  font-weight: 700;
}
.ticks.read {
  color: var(--tick-read);
}

.edited-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-right: 5px;
  font-style: italic;
}

.msg-edit-input {
  display: block;
  width: 100%;
  min-width: 160px;
  background: var(--elevated);
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 14.5px;
  padding: 6px 8px;
  margin-bottom: 4px;
  outline: none;
  box-sizing: border-box;
}

.context-menu {
  position: fixed;
  z-index: 60;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  padding: 6px;
  min-width: 150px;
}
.context-menu.hidden { display: none; }
.context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 13.5px;
  cursor: pointer;
}
.context-menu button:hover { background: var(--elevated); }
.context-menu button[data-action="delete"] { color: var(--danger); }

.bubble .file-attachment {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--overlay);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 6px;
  text-decoration: none;
  color: var(--text);
}
.bubble .file-attachment .file-icon { color: var(--accent); font-size: 16px; }
.bubble .file-attachment .file-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.bubble .file-attachment .file-size { font-size: 11px; color: var(--text-muted); }
.bubble img.inline-media,
.bubble video.inline-media {
  max-width: 280px;
  max-height: 320px;
  min-width: 140px;
  min-height: 100px;
  border-radius: 10px;
  display: block;
  margin-bottom: 6px;
  background: var(--overlay);
  cursor: pointer;
}

.video-thumb {
  position: relative;
  display: inline-block;
  cursor: pointer;
}
.video-thumb .inline-media {
  pointer-events: none; /* clicks go to the wrapper, not the native video controls */
}
.video-thumb .play-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  padding-left: 3px; /* optically center the triangle */
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(6,7,10,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 56px 24px;
}
.lightbox.hidden { display: none; }
.lightbox-content {
  max-width: 100%;
  max-height: 100%;
  display: flex;
}
.lightbox-content img,
.lightbox-content video {
  max-width: 100%;
  max-height: 84vh;
  border-radius: 8px;
  display: block;
  margin: auto;
}
.lightbox-btn {
  position: fixed;
  top: 16px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  text-decoration: none;
}
.lightbox-close { right: 16px; }
.lightbox-download { right: 66px; }

.recovery-code-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  max-width: 420px;
  width: 100%;
  text-align: center;
}
.recovery-code-card h3 {
  margin: 0 0 10px;
  font-size: 17px;
}
.recovery-code-card p {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  text-align: left;
}
.recovery-code-card code {
  display: block;
  font-family: "SF Mono", ui-monospace, Consolas, monospace;
  font-size: 15px;
  letter-spacing: 0.5px;
  color: var(--accent);
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 10px;
  word-break: break-all;
  margin-bottom: 12px;
}
.recovery-code-card > button {
  width: 100%;
  background: var(--elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 0;
  border-radius: 10px;
  font-size: 13.5px;
  cursor: pointer;
  margin-bottom: 16px;
}
.recovery-confirm-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: left;
  margin-bottom: 16px;
  cursor: pointer;
}
#recovery-code-continue-btn {
  width: 100%;
  background: var(--accent);
  color: #1a1305;
  border: none;
  border-radius: 10px;
  padding: 11px 0;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
}
#recovery-code-continue-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.file-btn {
  cursor: pointer;
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  background: var(--elevated);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
#message-input {
  flex: 1;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 14.5px;
  outline: none;
}
#message-input:focus { border-color: var(--accent); }
.composer button[type="submit"] {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #1a1305;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
}

.upload-progress {
  padding: 6px 20px 10px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- mobile ---------- */

@media (max-width: 720px) {
  #app-screen { grid-template-columns: 1fr; }
  #sidebar {
    position: fixed;
    inset: 0;
    z-index: 5;
    transition: transform 0.2s ease;
  }
  #app-screen.chat-open #sidebar { transform: translateX(-100%); }
  #app-screen:not(.chat-open) #chat-pane { display: none; }
  #chat-header { display: flex; align-items: center; gap: 10px; }
  .back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--elevated);
    border: 1px solid var(--border);
    color: var(--text);
    width: 30px; height: 30px;
    border-radius: 8px;
    cursor: pointer;
  }
}

/* ---------- group chats ---------- */

.modal-card-left {
  text-align: left;
}
.modal-card-left h3 {
  text-align: center;
}
.modal-card-left label {
  display: block;
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.modal-card-left label input {
  display: block;
  width: 100%;
  margin-top: 6px;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 13.5px;
  outline: none;
  box-sizing: border-box;
}
.modal-card-left label input:focus { border-color: var(--accent); }
.input-with-btn {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.input-with-btn input {
  margin-top: 0 !important;
}
#new-group-add-member-btn {
  flex-shrink: 0;
  background: var(--elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 0 14px;
  font-size: 13px;
  cursor: pointer;
}
.input-with-btn select {
  flex: 1;
  min-width: 0;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 13.5px;
  outline: none;
}
.input-with-btn select:disabled {
  opacity: 0.5;
}
#new-group-add-member-btn:hover:not(:disabled) { border-color: var(--accent); }
#new-group-add-member-btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.modal-card-left .form-error {
  color: #e05a5a;
  font-size: 12px;
  margin: -6px 0 12px;
  min-height: 1em;
}
.modal-card-left #new-group-create-btn {
  width: 100%;
  background: var(--accent);
  color: #1a1305;
  border: none;
  border-radius: 10px;
  padding: 11px 0;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 10px;
}

.member-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: -6px 0 14px;
}
.member-chip {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.member-chip:hover { border-color: var(--accent); }

.avatar.group-avatar {
  background: var(--accent);
  color: #1a1305;
  font-size: 15px;
}

.sender-label {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 2px;
}
