/* Design notes from readme.md:
   - flat, minimal, no gradients/shadows beyond subtle borders
   - sentence case everywhere, including buttons
   - two bubble colors only (sender vs receiver) — used in step 4
   - calm, factual tone
*/

/* Slack "Ochin" — locked palette:
   #1264A3 #0B4C8C #E0EAF2 #F6F6F6 #FFFFFF #000000 */
:root {
  --bg:         #1264a3;   /* page background */
  --card:       #f6f6f6;   /* card surface */
  --card-2:     #e0eaf2;   /* chat shell, received bubbles, soft surfaces */
  --ink:        #000000;
  --ink-on-dark:#ffffff;
  --muted:      rgba(0, 0, 0, 0.62);
  --muted-2:    rgba(0, 0, 0, 0.42);
  --border:     rgba(0, 0, 0, 0.10);
  --accent:     #137700;   /* lock icon — encrypted / live */
  --highlight:  #0b4c8c;   /* warn — same deep blue (calm, single-hue theme) */
  --danger:     #0b4c8c;   /* end-state — still calm, never red */
  --send-bg:    #1264a3;
  --send-ink:   #ffffff;
  --recv-bg:    #e0eaf2;
  --recv-ink:   #000000;
  --primary-bg: #1264a3;
  --primary-bg-hover: #0b4c8c;
  --radius:    16px;
  --radius-sm:  8px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

#app {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
  max-width: 360px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.icon-lg {
  font-size: 28px;
  color: var(--muted);
  margin: 0 auto;
}

.ti-lock.icon-lg { color: var(--accent); }

/* ─── Icon semantics ────────────────────────────────────────────────────────
   Give each Tabler icon a meaning-tied colour so they read at a glance,
   following the same rule as the padlock = green/encrypted. State-specific
   overrides (e.g. .chat-header-status.warn i) win via higher specificity.
*/
.ti-lock          { color: var(--accent); }       /* security · green */
.ti-circle-check  { color: var(--accent); }       /* calm success · green */
.ti-refresh       { color: var(--primary-bg); }   /* activity · blue */
.ti-copy          { color: var(--primary-bg); }   /* action · blue */
.ti-qrcode        { color: var(--primary-bg); }   /* action · blue */
.ti-arrow-right   { color: var(--primary-bg); }   /* send · blue */
.ti-logout        { color: #b54141;             }   /* leave · red */

.title {
  font-size: 16px;
  font-weight: 500;
  margin: 0 0 4px;
}

.subtitle {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
  line-height: 1.6;
}

.small {
  font-size: 12px;
  color: var(--muted-2);
  margin: 0;
}

.terms-link {
  margin-top: -4px;
}
.terms-link a {
  color: var(--primary-bg);
  text-decoration: none;
}
.terms-link a:hover { text-decoration: underline; }

.code-display {
  font-size: 32px;
  font-weight: 500;
  letter-spacing: 2px;
  margin: 0;
}

.code-display.sm {
  font-size: 24px;
}

.btn-primary {
  background: var(--primary-bg);
  color: #ffffff;
  border: none;
  padding: 10px;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  justify-content: center;
}

.btn-primary:hover { background: var(--primary-bg-hover); }

button {
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

button:hover { background: var(--card-2); }

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
button:disabled:hover { background: var(--card); }

.row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted-2);
  display: inline-block;
}

.dot.live    { background: var(--accent); }
.dot.warn    { background: var(--highlight); }
.dot.dead    { background: var(--danger); }

.divider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 0.5px;
  background: var(--border);
}
.divider span {
  font-size: 12px;
  color: var(--muted-2);
}

input[type="text"] {
  text-align: center;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--border);
  background: #ffffff;
  color: var(--ink);
  padding: 0 10px;
  font-size: 14px;
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 1px;
  width: 100%;
}

input[type="text"]::placeholder {
  color: var(--muted-2);
  text-transform: none;
  letter-spacing: normal;
}

form { margin: 0; }

.error {
  font-size: 12px;
  color: var(--danger);
  margin: 0;
}

/* ─── Live chat screen ──────────────────────────────────────────────────── */

.chat-shell {
  background: var(--card-2);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 420px;
  width: 100%;
  color: var(--ink);
}

.chat-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 0.5px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--border);
}

.chat-header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.chat-header-status i { font-size: 16px; color: var(--accent); }
.chat-header-status.warn i { color: var(--highlight); }
.chat-header-status.dead i { color: var(--danger); }

.chat-thread {
  padding: 16px;
  min-height: 320px;
  max-height: 60vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.18) transparent;
}

.chat-thread::-webkit-scrollbar {
  width: 8px;
}
.chat-thread::-webkit-scrollbar-track {
  background: transparent;
}
.chat-thread::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.18);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.chat-thread::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.32);
  background-clip: padding-box;
  border: 2px solid transparent;
}

.chat-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 0.5px solid var(--border);
  margin: 0;
}

.chat-input input {
  flex: 1;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--border);
  background: #ffffff;
  color: var(--ink);
  padding: 0 10px;
  font-size: 14px;
  font-family: inherit;
  text-align: left;
  text-transform: none;
  letter-spacing: normal;
}

.chat-input button {
  padding: 0;
  height: 36px;
  width: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-input button i { font-size: 18px; }

.chat-footer {
  font-size: 12px;
  color: var(--muted-2);
  text-align: center;
  margin: 12px 0 0;
}

.bubble {
  max-width: 78%;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.5;
}

.bubble.me   { align-self: flex-end;   background: var(--send-bg); color: var(--send-ink); }
.bubble.them { align-self: flex-start; background: var(--recv-bg); color: var(--recv-ink); }

.bubble.sys {
  align-self: center;
  background: transparent;
  color: var(--muted-2);
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 8px;
}

.reconnecting {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted-2);
  margin: 6px 0;
}

.reconnecting i {
  font-size: 14px;
  animation: spin 1.4s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── QR modal ──────────────────────────────────────────────────────────── */

#qr-dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  max-width: 320px;
  width: 90vw;
}

#qr-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

#qr-dialog [data-qr-target] {
  background: #ffffff;
  padding: 12px;
  border-radius: var(--radius-sm);
}

/* ─── Terms modal ───────────────────────────────────────────────────────── */

#terms-dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  max-width: 560px;
  width: 92vw;
  max-height: 82vh;
}
#terms-dialog::backdrop { background: rgba(0, 0, 0, 0.55); }

.terms-dialog-body {
  display: flex;
  flex-direction: column;
  max-height: 82vh;
}
.terms-dialog-body .terms {
  overflow-y: auto;
  padding: 1.5rem 1.75rem 1rem;
  line-height: 1.65;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.18) transparent;
}
.terms-dialog-body .terms::-webkit-scrollbar       { width: 8px; }
.terms-dialog-body .terms::-webkit-scrollbar-track { background: transparent; }
.terms-dialog-body .terms::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.18);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.terms-dialog-body .terms h1 { font-size: 18px; font-weight: 500; margin: 0 0 8px; }
.terms-dialog-body .terms h2 { font-size: 14px; font-weight: 500; margin: 1.25em 0 4px; }
.terms-dialog-body .terms p  { margin: 0 0 0.9em; font-size: 13px; color: var(--ink); }

.terms-dialog-body .btn-primary {
  margin: 0 1.5rem 1.5rem;
}

.qr-dialog-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
  text-align: center;
}

.qr-dialog-body [data-qr-target] {
  width: 240px;
  height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-dialog-body [data-qr-target] svg {
  width: 100%;
  height: 100%;
}

.qr-dialog-body .btn-primary {
  width: 100%;
}
