/* ==========================================================================
   CryptoChat – Design
   Ein Signalton (Teal) auf ruhigem Dunkelblau bzw. warmem Papier.
   Flächen statt Verläufen: Hierarchie entsteht durch Abstand, Kontrast
   und eine klare Primäraktion.
   ========================================================================== */

:root {
  color-scheme: dark;

  --bg: #0f1220;
  --surface: #151a2b;
  --surface-2: #1b2136;
  --border: #272f48;
  --border-strong: #38436a;
  --text: #e9ecf5;
  --text-dim: #8e98b3;
  --accent: #2dd4bf;
  --accent-strong: #5eead4;
  --accent-ink: #052a26;
  --accent-soft: #2dd4bf1f;
  --danger: #f87171;
  --success: #34d399;

  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 1px 0 #ffffff08 inset, 0 12px 32px -16px #00000099;

  --font: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;

  --bg: #f4efe4;
  --surface: #fffdf8;
  --surface-2: #f6f1e5;
  --border: #e4dcc9;
  --border-strong: #cdbf9f;
  --text: #1f2430;
  --text-dim: #6a6f7d;
  --accent: #0b7d70;
  --accent-strong: #09675c;
  --accent-ink: #ffffff;
  --accent-soft: #0b7d7018;
  --danger: #c2413a;
  --success: #0b7d70;

  --shadow: 0 1px 0 #ffffff inset, 0 10px 28px -18px #5b4b2a66;
}

* { box-sizing: border-box; }

/* .hidden gewinnt immer – auch gegen spätere display-Regeln wie flex/grid. */
.hidden { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(60rem 28rem at 50% -8rem, #2dd4bf14, transparent 70%),
    radial-gradient(40rem 30rem at 100% 0, #7c5cff10, transparent 70%);
  background-repeat: no-repeat;
  min-height: 100vh;
  transition: background-color 0.2s ease, color 0.2s ease;
}

:root[data-theme="light"] body {
  background-image:
    radial-gradient(60rem 28rem at 50% -8rem, #0f8f8014, transparent 70%),
    radial-gradient(40rem 30rem at 100% 0, #e0b25a14, transparent 70%);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* --- Layout ------------------------------------------------------------- */

.app {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px 16px 56px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.app-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px var(--border);
}

.app-header h1 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.tagline {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.theme-toggle {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.theme-toggle:hover { color: var(--text); border-color: var(--border-strong); }

/* --- Tabs --------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: 4px;
  margin: 18px 0 16px;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  position: relative;
  padding: 12px 8px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active { color: var(--text); }

.tab-btn.active::after {
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: -1px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--accent);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* --- Karten & Formulare ------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

label {
  font-size: 0.82rem;
  color: var(--text-dim);
  font-weight: 600;
}

textarea,
input[type="password"],
input[type="text"],
input[type="email"],
select {
  width: 100%;
  min-height: 48px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 1rem; /* 16px verhindert Zoom auf iOS */
  font-family: inherit;
  resize: vertical;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea { min-height: 112px; line-height: 1.5; }

::placeholder { color: var(--text-dim); opacity: 0.75; }

textarea:focus,
input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="file"] {
  width: 100%;
  color: var(--text-dim);
  font-size: 0.88rem;
}

input[type="file"]::file-selector-button {
  margin-right: 12px;
  padding: 10px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

input[type="file"]::file-selector-button:hover { border-color: var(--accent); }

/* --- Bildquelle (segmentiert) ------------------------------------------ */

.source-choice {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.source-label { font-size: 0.82rem; color: var(--text-dim); font-weight: 600; }

.radio-row {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.radio-pill {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 6px;
  border-radius: 9px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-dim);
  text-align: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.radio-pill input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.radio-pill:hover { color: var(--text); }

.radio-pill:has(input:checked) {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--border-strong), 0 2px 6px -2px #00000066;
}

.radio-pill:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }

.source-controls.hidden { display: none; }

#camera-video {
  width: 100%;
  max-height: 320px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #05070d;
  object-fit: cover;
}

#camera-video.hidden { display: none; }

.camera-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.camera-buttons .btn-secondary.hidden { display: none; }

.preview-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

canvas {
  max-width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #05070d;
}

#preview-canvas-hide:not([width]) { display: none; }

.capacity-info {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
}

.capacity-info.ok { color: var(--success); }
.capacity-info.bad { color: var(--danger); }

/* --- Buttons ------------------------------------------------------------ */

.btn-primary,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 650;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    transform 0.1s ease, filter 0.15s ease;
}

.btn-primary {
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: scale(0.985); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; filter: none; transform: none; }

.btn-send { width: 100%; min-height: 52px; font-size: 1rem; }

.btn-secondary {
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
}

.btn-secondary:hover { border-color: var(--accent); color: var(--accent-strong); }
.btn-secondary:active { transform: scale(0.985); }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-link {
  background: none;
  border: none;
  color: var(--accent-strong);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 4px;
  transition: color 0.15s ease;
}

.btn-link:hover { text-decoration: underline; }

/* --- Rückmeldungen ------------------------------------------------------ */

.result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.result.hidden { display: none; }

.result img { max-width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--border); }

.success-msg {
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--success);
  font-weight: 650;
  font-size: 0.92rem;
}

.hint { color: var(--text-dim); font-size: 0.82rem; text-align: center; margin: 0; }
.hint.hidden { display: none; }

.error {
  margin: 0;
  color: var(--danger);
  font-size: 0.88rem;
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.error.hidden { display: none; }

.app-footer {
  text-align: center;
  margin-top: 28px;
  color: var(--text-dim);
  font-size: 0.76rem;
  line-height: 1.6;
}

.app-footer p { margin: 0 0 4px; }
.app-footer a { color: var(--accent-strong); }

/* --- Konto -------------------------------------------------------------- */

.account-box { padding: 16px; gap: 10px; }

.account-hint {
  color: var(--text-dim);
  font-size: 0.86rem;
  margin: 0;
}

.account-details {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 4px 14px;
}

.account-details[open] { padding-bottom: 14px; }

.account-details summary {
  cursor: pointer;
  font-weight: 650;
  font-size: 0.95rem;
  padding: 10px 0;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.account-details summary::-webkit-details-marker { display: none; }

.account-details summary::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-dim);
  border-bottom: 2px solid var(--text-dim);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}

.account-details[open] summary::after { transform: rotate(-135deg); }

.account-details input {
  margin-top: 10px;
  background: var(--surface);
}

.account-details button { margin-top: 10px; }
.account-details .btn-secondary { width: 100%; }

.account-signed-in-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

#account-signed-in p { margin: 0; font-size: 0.92rem; }

.account-avatar-box { flex-shrink: 0; }

.account-signed-in-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.account-signed-in-info label { font-size: 0.8rem; cursor: pointer; padding: 2px 0; width: fit-content; }

/* --- Senden an ---------------------------------------------------------- */

.send-to-user-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.send-to-user-box.hidden { display: none; }

.send-to-user-row { display: flex; gap: 8px; }
.send-to-user-row input { flex: 1; }

.friend-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.friend-chips.hidden { display: none; }

.friend-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 4px 12px 4px 5px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.friend-chip:hover { border-color: var(--accent); background: var(--accent-soft); }

/* --- Posteingang -------------------------------------------------------- */

#inbox-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.inbox-item {
  display: flex;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.inbox-item-unread {
  border-color: var(--border-strong);
  box-shadow: inset 3px 0 0 var(--accent);
}

.inbox-unread-badge {
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.02em;
  color: var(--accent-ink);
  background: var(--accent);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.inbox-thumb-wrap {
  position: relative;
  width: 72px;
  height: 72px;
  flex-shrink: 0;
}

.inbox-thumb {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.inbox-decrypt-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.inbox-decrypt-overlay.active { opacity: 1; }

.inbox-meta {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.inbox-from {
  margin: 0;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.inbox-add-friend { font-size: 0.78rem; font-weight: 600; padding: 2px 4px; }
.inbox-add-friend.hidden { display: none; }

.inbox-date { margin: -4px 0 0; font-size: 0.78rem; color: var(--text-dim); }

.inbox-password {
  min-height: 40px !important;
  padding: 8px 12px !important;
  font-size: 0.92rem !important;
  background: var(--surface) !important;
}

.inbox-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.inbox-actions .btn-secondary { min-height: 40px; padding: 0 16px; font-size: 0.88rem; }
.inbox-actions button { flex: none; }

.inbox-delete { display: inline-flex; align-items: center; justify-content: center; margin-left: auto; }

.inbox-plaintext {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0;
  font-family: inherit;
  font-size: 0.95rem;
}

.inbox-plaintext.hidden,
.inbox-error.hidden { display: none; }

/* --- Avatare ------------------------------------------------------------ */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.avatar-fallback { color: white; font-weight: 700; }

.avatar-xs { width: 20px; height: 20px; font-size: 0.65rem; }
.avatar-sm { width: 32px; height: 32px; font-size: 0.85rem; }
.avatar-md { width: 48px; height: 48px; font-size: 1.1rem; }

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  min-height: 0 !important;
  padding: 0 !important;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* --- GIF-Bildquelle ----------------------------------------------------- */

.gif-search-row { display: flex; gap: 8px; }
.gif-search-row input { flex: 1; }

.gif-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
}

.gif-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease;
}

.gif-thumb:hover { border-color: var(--border-strong); }
.gif-thumb.selected { border-color: var(--accent); }

/* --- Freunde ------------------------------------------------------------ */

#friends-signed-in {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.friends-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.friend-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.friend-username { flex: 1; font-weight: 650; }
.friend-item button { font-size: 0.85rem; }

.invite-friends-box {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  margin-top: 6px;
  padding: 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  text-align: center;
}

.invite-title { margin: 0; font-weight: 700; }

/* --- Schmale Displays --------------------------------------------------- */

@media (max-width: 420px) {
  .app { padding: 16px 12px 48px; }
  .card { padding: 16px; }
  .radio-pill { font-size: 0.8rem; }
  .inbox-item { flex-direction: column; }
  .inbox-thumb-wrap, .inbox-thumb { width: 100%; height: auto; aspect-ratio: 16 / 9; }
}
