/* 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;
  min-height: 100vh;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

body {
  /* Radial halo centered above the card. Scales with the viewport via the
     default farthest-corner ellipse sizing. Solid fallback applied first
     so older renderers still show the right base colour. */
  background-color: var(--bg);
  background-image: radial-gradient(ellipse at 50% 30%, #1a3a6b 0%, #0b1c33 35%, #061122 90%);
}

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

/* ─── App header (persistent above every screen) ─────────────────────────── */

/* Header proportions mirror the OG image (1200×630):
   - badge ratio   120 ≈ 1.43× name → 48 / 32 = 1.5 (close enough)
   - tagline ratio  34 / 84 ≈ 0.40 → 13 / 32 ≈ 0.41
   - badge corner   26 / 120 = 21.7% → 11 / 48 ≈ 22.9%                         */
.app-header {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  padding: 0 4px;
}

.app-header-icon {
  width: 48px;
  height: 48px;
  background: var(--primary-bg);
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.app-header-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

.app-header-text { min-width: 0; }

.app-header-name {
  font-size: 32px;
  font-weight: 600;
  margin: 0;
  color: #ffffff;
  line-height: 1.05;
  letter-spacing: -0.01em;
}

.app-header-tagline {
  margin: 4px 0 0;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
}

.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;
}

/* ─── Lucide icon base ──────────────────────────────────────────────────────
   Icons are inline-SVG with stroke="currentColor"; size follows the parent's
   font-size via the 1em width/height below. Wrap each instance in an SVG
   element with .icon plus a per-icon class for colour semantics.
*/
.icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: none;
  stroke: currentColor;
  flex-shrink: 0;
}

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

/* Meaning-tied colours so each icon reads at a glance. State-specific
   overrides (e.g. .chat-header-status.warn .icon) win via higher specificity. */
.icon-lock          { color: var(--accent); }       /* security · green */
.icon-circle-check  { color: var(--accent); }       /* calm success · green */
.icon-refresh-cw    { color: var(--primary-bg); }   /* activity · blue */
.icon-copy          { color: var(--primary-bg); }   /* action · blue */
.icon-qr-code       { color: var(--primary-bg); }   /* action · blue */
.icon-arrow-right   { color: var(--primary-bg); }   /* send · blue */
.icon-log-out       { color: #b54141; }             /* leave · red */
.icon-paperclip     { color: var(--primary-bg); }   /* attach · blue */

.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;
  position: relative;
  transition: outline-color 120ms ease;
  outline: 2px dashed transparent;
  outline-offset: -4px;
}

.chat-card.drag-over { outline-color: var(--primary-bg); }

.chat-card.drag-over::after {
  content: "Drop to send";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 500;
  color: var(--primary-bg);
  background: rgba(18, 100, 163, 0.06);
  pointer-events: none;
  border-radius: var(--radius);
}

.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 .icon { font-size: 16px; color: var(--accent); }
.chat-header-status.warn .icon { color: var(--highlight); }
.chat-header-status.dead .icon { 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-error {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 12px 0;
  padding: 8px 10px;
  background: #fdecec;
  border: 0.5px solid #f3c7c7;
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.4;
}
.chat-error .icon-circle-alert { font-size: 16px; color: var(--danger); }
.chat-error [data-error-text] { flex: 1; }
.chat-error-dismiss {
  background: transparent;
  border: none;
  padding: 2px;
  cursor: pointer;
  color: var(--danger);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chat-error-dismiss:hover { background: rgba(181, 65, 65, 0.08); }
.chat-error-dismiss .icon { font-size: 16px; color: var(--danger); }

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

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

.chat-input textarea {
  resize: none;
  overflow-y: auto;
}

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

.chat-input button .icon { 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       { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble a     { color: inherit; text-decoration: underline; }
.bubble code  {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: rgba(0, 0, 0, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
}
.bubble.me code { background: rgba(255, 255, 255, 0.18); }
.bubble pre {
  margin: 4px 0 2px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 6px;
  overflow-x: auto;
  white-space: pre;
  font-size: 12.5px;
}
.bubble.me pre { background: rgba(255, 255, 255, 0.18); }
.bubble pre code { background: transparent; padding: 0; }

.bubble-image {
  padding: 4px;
  max-width: 240px;
}
.bubble-image img {
  display: block;
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  border-radius: 6px;
  cursor: zoom-in;
}
.bubble-caption {
  margin: 6px 4px 2px;
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.bubble.me   .bubble-caption { color: var(--send-ink); }
.bubble.them .bubble-caption { color: var(--recv-ink); }

/* Attachment preview strip — sits between the thread and the input row */

.chat-attachment {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 12px 0;
  padding: 6px 8px;
  background: var(--card-2);
  border-radius: var(--radius-sm);
}
.chat-attachment-thumb {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}
.chat-attachment-name {
  flex: 1;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-attachment-remove {
  background: transparent;
  border: none;
  padding: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--muted);
}
.chat-attachment-remove:hover { background: rgba(0, 0, 0, 0.04); }
.chat-attachment-remove .icon { font-size: 16px; color: var(--muted); }

/* ─── Image viewer modal ────────────────────────────────────────────────── */

#image-viewer {
  border: none;
  padding: 0;
  background: transparent;
  max-width: 96vw;
  max-height: 96vh;
}
#image-viewer::backdrop {
  background: rgba(0, 0, 0, 0.85);
}
#image-viewer img {
  display: block;
  max-width: 96vw;
  max-height: 96vh;
  border-radius: var(--radius-sm);
  cursor: zoom-out;
}

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

/* Three-dot peer-typing bubble. Same colour family as the receiver
   bubble so it reads as "they are about to say something". */
.typing-indicator {
  padding: 10px 12px !important;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-3px); }
}

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

.reconnecting .icon {
  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%;
}
