/* CipherCore – light glassmorphism security-ops aesthetic */

:root {
  --bg: #e8eef5;
  --bg-accent: #d0dce8;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #ffffff;
  --border: rgba(255, 255, 255, 0.55);
  --border-strong: rgba(30, 58, 95, 0.18);
  --text: #0f1c2e;
  --text-muted: #5a6b7d;
  --primary: #1a6cff;
  --primary-hover: #0d56d9;
  --primary-soft: rgba(26, 108, 255, 0.12);
  --success: #0d9f6e;
  --success-soft: rgba(13, 159, 110, 0.12);
  --danger: #d9364a;
  --danger-soft: rgba(217, 54, 74, 0.12);
  --warning: #c47d00;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 32px rgba(15, 28, 46, 0.08);
  --shadow-lg: 0 16px 48px rgba(15, 28, 46, 0.12);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(26, 108, 255, 0.18), transparent),
    radial-gradient(ellipse 60% 40% at 90% 10%, rgba(13, 159, 110, 0.12), transparent),
    radial-gradient(ellipse 50% 30% at 50% 100%, rgba(26, 108, 255, 0.08), transparent);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
}
.glass {
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
#app { min-height: 100dvh; display: flex; flex-direction: column; }
.page { display: none; flex: 1; flex-direction: column; }
.page.active { display: flex; }
.auth-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.auth-card { width: 100%; max-width: 420px; padding: 2rem; }
.logo-row { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.5rem; }
.logo-row img, .logo-row svg { width: 40px; height: 40px; }
.logo-row h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }
.badge-e2e {
  display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--success); background: var(--success-soft);
  padding: 0.25rem 0.6rem; border-radius: 999px; margin-bottom: 1.25rem;
}
.badge-e2e::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--success); }
.auth-card h2 { font-size: 1.25rem; margin-bottom: 0.35rem; }
.auth-card .subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.5rem; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.35rem; }
.form-group input, .form-group textarea, .form-group select {
  width: 100%; padding: 0.7rem 0.9rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-solid); font-size: 0.95rem; color: var(--text); font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.7rem 1.2rem; border: none; border-radius: var(--radius-sm);
  font-size: 0.95rem; font-weight: 600; font-family: inherit; cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border-strong); }
.btn-ghost:hover { background: var(--primary-soft); color: var(--primary); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.8rem; }
.auth-switch { text-align: center; margin-top: 1.25rem; font-size: 0.9rem; color: var(--text-muted); }
.auth-switch a { color: var(--primary); font-weight: 600; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }
.error-msg, .success-msg {
  padding: 0.65rem 0.9rem; border-radius: var(--radius-sm); font-size: 0.85rem; margin-bottom: 1rem; display: none;
}
.error-msg { background: var(--danger-soft); color: var(--danger); }
.success-msg { background: var(--success-soft); color: var(--success); }
.error-msg.show, .success-msg.show { display: block; }
.cf-turnstile { margin: 1rem 0; display: flex; justify-content: center; }
.app-header {
  display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border-strong); background: var(--surface); backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 50;
}
.app-header .brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; font-size: 1.05rem; }
.app-header .brand svg { width: 28px; height: 28px; }
.header-actions { display: flex; align-items: center; gap: 0.5rem; }
.user-chip {
  font-size: 0.8rem; color: var(--text-muted); padding: 0.3rem 0.6rem; background: var(--primary-soft);
  border-radius: 999px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.app-body { flex: 1; display: grid; grid-template-columns: 300px 1fr; min-height: 0; }
@media (max-width: 768px) {
  .app-body { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .sidebar.mobile-open { display: flex; position: fixed; inset: 0; z-index: 100; background: var(--bg); }
}
.sidebar {
  border-right: 1px solid var(--border-strong); display: flex; flex-direction: column;
  background: var(--surface); min-height: 0;
}
.sidebar-header { padding: 1rem; display: flex; gap: 0.5rem; border-bottom: 1px solid var(--border-strong); }
.sidebar-header .btn { flex: 1; }
.conv-list { flex: 1; overflow-y: auto; padding: 0.5rem; }
.conv-item {
  padding: 0.75rem 0.9rem; border-radius: var(--radius-sm); cursor: pointer;
  transition: background 0.12s; margin-bottom: 0.25rem;
}
.conv-item:hover { background: var(--primary-soft); }
.conv-item.active { background: var(--primary-soft); border: 1px solid rgba(26, 108, 255, 0.25); }
.conv-item .title { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .meta { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.15rem; }
.chat-panel { display: flex; flex-direction: column; min-height: 0; background: transparent; }
.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-muted); padding: 2rem; text-align: center;
}
.chat-empty svg { width: 64px; height: 64px; opacity: 0.4; margin-bottom: 1rem; }
.chat-header {
  padding: 0.85rem 1.25rem; border-bottom: 1px solid var(--border-strong); background: var(--surface);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.chat-header .info h3 { font-size: 1rem; font-weight: 600; }
.chat-header .info .members { font-size: 0.75rem; color: var(--text-muted); }
.lock-indicator {
  display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.7rem; font-weight: 600;
  color: var(--success); background: var(--success-soft); padding: 0.2rem 0.5rem; border-radius: 999px;
}
.messages { flex: 1; overflow-y: auto; padding: 1.25rem; display: flex; flex-direction: column; gap: 0.75rem; }
.msg {
  max-width: 75%; padding: 0.7rem 0.95rem; border-radius: 14px; font-size: 0.92rem;
  line-height: 1.45; position: relative;
}
.msg.mine { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg.theirs {
  align-self: flex-start; background: var(--surface-solid); border: 1px solid var(--border-strong);
  border-bottom-left-radius: 4px;
}
.msg .sender { font-size: 0.7rem; font-weight: 600; opacity: 0.75; margin-bottom: 0.2rem; }
.msg .time { font-size: 0.65rem; opacity: 0.65; margin-top: 0.3rem; text-align: right; }
.msg.decrypt-fail { font-style: italic; opacity: 0.7; }
.compose {
  padding: 0.85rem 1.25rem; border-top: 1px solid var(--border-strong); background: var(--surface);
  display: flex; flex-direction: column; gap: 0.5rem;
}
.compose-row { display: flex; gap: 0.5rem; align-items: flex-end; }
.compose textarea {
  flex: 1; resize: none; min-height: 44px; max-height: 120px; padding: 0.65rem 0.9rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-family: inherit;
  font-size: 0.95rem; background: var(--surface-solid);
}
.compose textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.compose-opts { display: flex; align-items: center; gap: 1rem; font-size: 0.8rem; color: var(--text-muted); }
.compose-opts label { display: flex; align-items: center; gap: 0.35rem; cursor: pointer; }
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(15, 28, 46, 0.45);
  backdrop-filter: blur(4px); z-index: 200; align-items: center; justify-content: center; padding: 1rem;
}
.modal-overlay.show { display: flex; }
.modal { width: 100%; max-width: 440px; padding: 1.5rem; max-height: 90dvh; overflow-y: auto; }
.modal h3 { margin-bottom: 0.5rem; }
.modal .hint { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.5rem; margin-top: 1.25rem; justify-content: flex-end; }
.modal-actions .btn { width: auto; }
.settings-panel { max-width: 480px; margin: 2rem auto; padding: 1.5rem; }
.settings-panel h2 { margin-bottom: 1rem; }
.settings-panel .row {
  display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-strong); font-size: 0.9rem;
}
.hidden { display: none !important; }
