/* SecureMsg — mobile-first, dark by default, no external fonts/CDNs. */

:root {
  --bg: #0b1416;
  --bg-elevated: #101c1f;
  --bg-card: #142428;
  --border: #1f3438;
  --teal: #1fb6a6;
  --teal-dim: #0d3a40;
  --text: #eaf4f3;
  --text-dim: #9fb6b4;
  --danger: #e8635a;
  --danger-bg: #2a1414;
  --success: #57c98a;
  --radius: 14px;
  --tap: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f7f7;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --border: #dde6e5;
    --teal-dim: #e3f4f2;
    --text: #10201f;
    --text-dim: #5a6f6d;
    --danger-bg: #fdeceb;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

a { color: var(--teal); }

button, input, select, textarea { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  min-height: var(--tap);
  padding: 0 16px;
  background: var(--teal);
  color: #04201d;
  font-weight: 600;
}
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.5; cursor: default; }

button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
button.danger {
  background: var(--danger);
  color: #2a0a08;
}
button.icon-btn {
  background: transparent;
  color: var(--text);
  min-width: var(--tap);
  padding: 0 10px;
  font-size: 1.2rem;
}

input, textarea {
  min-height: var(--tap);
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 10px 14px;
  width: 100%;
}
input:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
}
textarea { resize: none; min-height: var(--tap); max-height: 40vh; }

label { display: block; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 6px; }
.field { margin-bottom: 16px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 8px 12px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
.topbar h1 {
  font-size: 1.05rem;
  margin: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--text-dim);
  flex: none;
}
.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--danger); }
.status-dot.connecting { background: #d9b23c; }

/* ---------- Screens ---------- */
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.screen-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  padding: 24px 20px;
  max-width: 420px;
  width: 100%;
  margin: 0 auto;
}
.brand {
  text-align: center;
  margin-bottom: 28px;
}
.brand .lockmark {
  width: 56px; height: 56px;
  border-radius: 16px;
  background: var(--teal-dim);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px;
  font-size: 1.6rem;
}
.brand h1 { margin: 0 0 4px; font-size: 1.4rem; }
.brand p { margin: 0; color: var(--text-dim); font-size: 0.9rem; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.hint { color: var(--text-dim); font-size: 0.85rem; margin-top: 10px; }
.error-box {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.9rem;
}
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-dim);
  padding: 40px 20px;
  gap: 8px;
}
.empty-state .big { font-size: 2rem; }

.actions-row { display: flex; gap: 10px; margin-top: 18px; }
.actions-row > * { flex: 1; }

/* ---------- Conversation list ---------- */
.conv-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; }
.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 10px 16px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  text-align: left;
  border-radius: 0;
}
.conv-item:active { background: var(--bg-card); }
.avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--teal-dim);
  color: var(--teal);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  flex: none;
}
.conv-meta { flex: 1; min-width: 0; }
.conv-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: 0.78rem; color: var(--text-dim); }

.fab {
  position: fixed;
  right: calc(20px + var(--safe-right));
  bottom: calc(20px + var(--safe-bottom));
  width: 56px; height: 56px;
  border-radius: 50%;
  font-size: 1.6rem;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}

/* ---------- New conversation / user picker ---------- */
.user-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; }
.user-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: var(--tap);
  padding: 12px 16px;
  background: none; border: none;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.user-item:active { background: var(--bg-card); }

/* ---------- Thread ---------- */
.thread-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bubble-row { display: flex; }
.bubble-row.mine { justify-content: flex-end; }
.bubble-row.theirs { justify-content: flex-start; }
.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.bubble-row.mine .bubble {
  background: var(--teal);
  color: #04201d;
  border-bottom-right-radius: 4px;
}
.bubble-row.theirs .bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.bubble.system {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-dim);
  font-size: 0.82rem;
  margin: 0 auto;
}
.bubble-time { display: block; font-size: 0.7rem; opacity: 0.7; margin-top: 4px; }

.composer {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
}
.composer textarea { flex: 1; }
.composer button { flex: none; min-width: var(--tap); }

/* ---------- Utility ---------- */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.center-loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-dim);
}

.offline-banner {
  background: #3a2a0d;
  color: #e8c96a;
  text-align: center;
  font-size: 0.82rem;
  padding: 6px 10px;
}

.back-btn { font-size: 1.3rem; }

/* ---------- Wide / Fold-6 unfolded / desktop layout ---------- */
@media (min-width: 700px) {
  #app { align-items: center; }
  .screen {
    width: 100%;
    max-width: 720px;
  }
  .screen-center { max-width: 440px; }
}

@media (min-width: 840px) {
  .screen { max-width: 820px; }
}
