/* Private Chat desktop — visual aligned with the Android client.
   Dark-first, green primary (#25D366 / #1FA855), orange accent
   (#FF8C00 / #FF6D00), 14-24px rounded shapes, asymmetric chat bubbles. */
:root {
  --bg: #0e0e10;
  --bg-soft: #131316;
  --panel: #1c1c1e;
  --panel-strong: #2c2c2e;
  --panel-elevated: #3a3a3c;

  --green-primary: #25d366;
  --green-secondary: #1fa855;
  --green-soft: #143a24;
  --green-glow: rgba(37, 211, 102, 0.32);

  --orange-accent: #ff8c00;
  --orange-vivid: #ff6d00;
  --orange-soft: #3a2410;

  --text: #ffffff;
  --text-secondary: #8e8e93;
  --text-muted: #6e6e73;

  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --divider: rgba(255, 255, 255, 0.08);

  --danger: #e5484d;
  --danger-soft: #3a1518;
  --read-blue: #4cc9ff;

  --self-bubble-start: #25d366;
  --self-bubble-end: #1fa855;
  --peer-bubble: #2c2c2e;
  --notes-start: #ff8c00;
  --notes-end: #ff6d00;

  --shadow-card: 0 24px 48px rgba(0, 0, 0, 0.45);
  --shadow-bubble: 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-glow: 0 0 32px rgba(37, 211, 102, 0.18);

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-pill: 999px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
}

body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 600px at 18% 12%, rgba(37, 211, 102, 0.18), transparent 60%),
    radial-gradient(700px 500px at 92% 88%, rgba(255, 140, 0, 0.10), transparent 65%),
    linear-gradient(160deg, #0e0e10 0%, #131316 50%, #0e0e10 100%);
  -webkit-font-smoothing: antialiased;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-pill);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.16);
}

.app-shell {
  min-height: 100vh;
}

/* ---------- Ghost watermark (mirror of Android client) ---------- */
.auth-view,
.chat-panel,
.sidebar {
  position: relative;
  overflow: hidden;
}

.auth-view::before,
.chat-panel::before,
.sidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("static/ghost_chat_logo.png");
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: 0;
}

.auth-view::before {
  background-position: center;
  background-size: min(70vmin, 520px);
  opacity: 0.12;
}

.chat-panel::before {
  background-position: center 58%;
  background-size: min(58vmin, 620px);
  opacity: 0.07;
}

.sidebar::before {
  background-position: 50% 92%;
  background-size: min(220px, 60%);
  opacity: 0.05;
}

.auth-view > *,
.chat-panel > *,
.sidebar > * {
  position: relative;
  z-index: 1;
}

/* Messages list scrolls above the watermark */
.messages {
  z-index: 1;
}

/* ---------- Auth screen ---------- */
.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(440px, 100%);
  background: linear-gradient(180deg, rgba(28, 28, 30, 0.94), rgba(28, 28, 30, 0.86));
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card), var(--shadow-glow);
  padding: 32px;
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand.compact {
  gap: 10px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--green-primary), var(--green-secondary));
  color: #ffffff;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.5px;
  box-shadow: 0 8px 24px rgba(37, 211, 102, 0.32);
}

.brand.compact .brand-mark {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: 14px;
  font-size: 15px;
}

.brand h1,
.brand p {
  margin: 0;
  color: var(--text);
}

.brand h1 {
  font-size: 22px;
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: -0.25px;
}

.brand p {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 3px;
}

.auth-form {
  display: grid;
  gap: 16px;
  margin-top: 28px;
}

.auth-form label {
  display: grid;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.auth-form input,
.composer textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text);
  background: var(--panel-strong);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.auth-form input::placeholder,
.composer textarea::placeholder {
  color: var(--text-muted);
}

.auth-form input {
  height: 48px;
  padding: 0 16px;
  font-size: 15px;
}

.auth-form input:focus,
.composer textarea:focus {
  border-color: var(--green-primary);
  background: var(--panel);
  box-shadow: 0 0 0 4px rgba(37, 211, 102, 0.16);
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}

/* ---------- Buttons ---------- */
.primary-btn,
.secondary-btn,
.send-btn,
.icon-text-btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.primary-btn,
.send-btn {
  background: linear-gradient(135deg, var(--green-primary), var(--green-secondary));
  color: #ffffff;
  box-shadow: 0 8px 24px rgba(37, 211, 102, 0.28);
}

.primary-btn:hover,
.send-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(37, 211, 102, 0.38);
}

.primary-btn:active,
.send-btn:active {
  transform: translateY(0);
}

.secondary-btn,
.icon-text-btn {
  background: var(--panel-strong);
  color: var(--text);
  border-color: var(--border);
}

.secondary-btn:hover,
.icon-text-btn:hover {
  background: var(--panel-elevated);
  border-color: var(--border-strong);
}

.secondary-btn.active {
  border-color: var(--green-primary);
  background: var(--green-soft);
  color: var(--green-primary);
}

.error-text {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

/* ---------- Chat layout ---------- */
.chat-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
}

.sidebar {
  background: linear-gradient(180deg, rgba(28, 28, 30, 0.92), rgba(20, 20, 22, 0.92));
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(12px);
}

.sidebar-header {
  padding: 20px;
  display: grid;
  gap: 18px;
  border-bottom: 1px solid var(--border);
}

.users-panel {
  padding: 18px;
  overflow-y: auto;
}

.users-panel h2 {
  margin: 0 0 12px;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 1.2px;
  font-weight: 600;
}

.users-list {
  display: grid;
  gap: 6px;
}

.group-create-btn {
  width: 100%;
  min-height: 40px;
  margin-bottom: 12px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-strong);
  background: linear-gradient(135deg, rgba(255, 140, 0, 0.18), rgba(255, 109, 0, 0.10));
  color: var(--orange-accent);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.2px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.group-create-btn:hover {
  background: linear-gradient(135deg, rgba(255, 140, 0, 0.28), rgba(255, 109, 0, 0.16));
  border-color: var(--orange-accent);
}

/* Conversation rows in the sidebar */
.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-lg);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}

.user-row:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
}

.user-row strong {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
}

.user-row small {
  color: var(--text-muted);
  font-size: 12px;
}

.conversation-row {
  min-height: 56px;
}

.conversation-row strong {
  flex: 1;
}

.conversation-row.active {
  background: linear-gradient(135deg, rgba(37, 211, 102, 0.16), rgba(31, 168, 85, 0.06));
  border-color: rgba(37, 211, 102, 0.35);
  box-shadow: inset 3px 0 0 var(--green-primary);
}

.conversation-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--green-primary), var(--green-secondary));
  color: #ffffff;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
  box-shadow: 0 6px 18px rgba(37, 211, 102, 0.28);
}

/* Small presence indicator next to a contact name */
.dot {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  border-radius: 50%;
  background: #4a4a4c;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.04);
}

.dot.online {
  background: var(--green-primary);
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.22), 0 0 12px rgba(37, 211, 102, 0.55);
}

/* ---------- Chat panel ---------- */
.chat-panel {
  height: 100vh;
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background:
    radial-gradient(800px 600px at 80% 8%, rgba(37, 211, 102, 0.10), transparent 60%),
    linear-gradient(180deg, rgba(14, 14, 16, 0.96), rgba(14, 14, 16, 1));
}

.chat-panel.screen-active {
  grid-template-rows: auto minmax(52vh, 58vh) minmax(0, 1fr) auto;
}

.chat-header {
  min-height: 76px;
  padding: 16px 24px;
  background: rgba(28, 28, 30, 0.72);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.chat-header h2,
.chat-header p {
  margin: 0;
}

.chat-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.2px;
}

.chat-header p,
.notice {
  color: var(--text-secondary);
  font-size: 13px;
}

.notice {
  min-width: 120px;
  text-align: right;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

#remoteAudio {
  width: 180px;
  height: 34px;
}

.compact-btn {
  min-height: 38px;
  padding: 0 14px;
  white-space: nowrap;
  font-size: 13px;
}

.danger-btn {
  color: var(--danger);
}

/* ---------- Screen sharing ---------- */
.screen-panel {
  padding: 12px 16px 0;
  background: transparent;
}

.chat-panel.screen-active .screen-panel {
  padding: 12px 16px;
  background: rgba(20, 20, 22, 0.65);
  border-bottom: 1px solid var(--border);
}

.screen-frame-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.screen-frame-title strong {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--green-primary);
  letter-spacing: 1.2px;
  font-weight: 600;
}

.screen-frame-title span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

.annotation-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.tool-btn,
.color-tool {
  min-height: 36px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--panel-strong);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.tool-btn:hover {
  background: var(--panel-elevated);
  border-color: var(--border-strong);
}

.tool-btn.active {
  border-color: var(--green-primary);
  background: var(--green-soft);
  color: var(--green-primary);
}

.color-tool input {
  width: 28px;
  height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
}

.screen-stage {
  position: relative;
  min-height: 260px;
  max-height: 45vh;
  background: #0a0a0c;
  border: 1px solid rgba(37, 211, 102, 0.45);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(37, 211, 102, 0.10), 0 24px 48px rgba(0, 0, 0, 0.45);
}

.chat-panel.screen-active .screen-stage {
  height: 100%;
  min-height: 52vh;
  max-height: 58vh;
}

.screen-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 1;
  color: rgba(255, 255, 255, 0.55);
  font-size: 14px;
  font-weight: 500;
  pointer-events: none;
  letter-spacing: 0.3px;
}

.screen-stage video {
  width: 100%;
  height: 100%;
  min-height: 260px;
  max-height: 45vh;
  object-fit: contain;
  display: block;
}

.chat-panel.screen-active .screen-stage video {
  min-height: 52vh;
  max-height: 58vh;
}

#annotationCanvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.screen-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 4;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.screen-control-btn {
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: rgba(28, 28, 30, 0.92);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.35);
}

.screen-control-btn:hover {
  background: rgba(58, 58, 60, 0.95);
}

.screen-control-btn.danger-btn {
  color: var(--danger);
  border-color: rgba(229, 72, 77, 0.5);
}

#localScreen {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 3;
  width: 180px;
  height: 105px;
  min-height: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-md);
  background: #0a0a0c;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.45);
}

.chat-panel.screen-active #localScreen {
  width: 220px;
  height: 130px;
  min-height: 0;
}

/* ---------- Messages ---------- */
.messages {
  position: relative;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-panel.screen-active .messages {
  padding-top: 14px;
}

.chat-panel.drag-over .messages::after {
  content: "Dépose le fichier, le lien ou le texte";
  position: absolute;
  inset: 18px;
  display: grid;
  place-items: center;
  z-index: 5;
  border: 2px dashed var(--green-primary);
  border-radius: var(--radius-xl);
  background: rgba(20, 60, 36, 0.55);
  color: var(--green-primary);
  font-weight: 700;
  font-size: 18px;
  pointer-events: none;
  letter-spacing: 0.3px;
  backdrop-filter: blur(4px);
}

.message {
  max-width: min(560px, 78%);
  display: grid;
  gap: 6px;
  padding: 10px 14px 8px;
  border-radius: 22px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-bubble);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  color: var(--text);
}

.message.mine {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--self-bubble-start), var(--self-bubble-end));
  border-color: rgba(255, 255, 255, 0.10);
  border-bottom-right-radius: 6px;
  color: #ffffff;
}

.message.theirs {
  align-self: flex-start;
  background: var(--peer-bubble);
  border-color: var(--border);
  border-bottom-left-radius: 6px;
}

/* Self notes (when mine and conversation is "Notes personnelles") — orange */
.message.mine.notes,
.conversation-row.notes .conversation-icon {
  background: linear-gradient(135deg, var(--notes-start), var(--notes-end));
}

.message.deleted {
  color: rgba(255, 255, 255, 0.55);
  font-style: italic;
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
}

.message-text {
  margin: 0;
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.45;
  letter-spacing: 0.1px;
}

.message-text a {
  color: #ffffff;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.message.theirs .message-text a {
  color: var(--green-primary);
  text-decoration: none;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.7);
}

.message.theirs .message-meta {
  color: var(--text-muted);
}

.delete-btn,
.copy-btn {
  border: 0;
  background: transparent;
  color: inherit;
  opacity: 0.7;
  padding: 0;
  font-size: 11px;
  transition: opacity 0.12s ease, color 0.12s ease;
}

.delete-btn:hover {
  opacity: 1;
  color: #ffe1e3;
}

.copy-btn:hover {
  opacity: 1;
}

.message.theirs .delete-btn:hover {
  color: var(--danger);
}

.message.theirs .copy-btn:hover {
  color: var(--green-primary);
}

/* ---------- Attachments ---------- */
.attachment {
  display: grid;
  gap: 6px;
}

.attachment img {
  max-width: 320px;
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.file-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  min-width: 220px;
  color: var(--text);
  text-decoration: none;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.message.theirs .file-link {
  background: var(--panel-elevated);
}

.file-link:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: var(--border-strong);
}

.file-icon {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--green-primary), var(--green-secondary));
  color: #ffffff;
  font-weight: 700;
  flex: 0 0 36px;
}

.message.mine .file-icon {
  background: rgba(255, 255, 255, 0.22);
}

/* ---------- Composer ---------- */
.composer {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 110px;
  gap: 10px;
  align-items: end;
  padding: 14px 16px 18px;
  background: rgba(28, 28, 30, 0.72);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.attach-btn {
  height: 48px;
  width: 48px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  display: grid;
  place-items: center;
  background: var(--panel-strong);
  color: var(--green-primary);
  font-size: 26px;
  line-height: 1;
  font-weight: 400;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
}

.attach-btn:hover {
  background: var(--panel-elevated);
  border-color: var(--green-primary);
  transform: rotate(45deg);
}

.attach-btn input {
  display: none;
}

.composer textarea {
  min-height: 48px;
  max-height: 140px;
  resize: none;
  padding: 12px 16px;
  line-height: 1.4;
  font-size: 15px;
  border-radius: var(--radius-lg);
}

.composer .send-btn {
  height: 48px;
  border-radius: var(--radius-pill);
  font-weight: 700;
  letter-spacing: 0.3px;
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .chat-view {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-header {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .users-panel {
    padding: 10px 14px;
  }

  .users-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chat-panel {
    height: calc(100vh - 220px);
  }

  .chat-panel.screen-active {
    height: calc(100vh - 220px);
    grid-template-rows: auto minmax(45vh, 52vh) minmax(0, 1fr) auto;
  }

  .chat-panel.screen-active .screen-stage,
  .chat-panel.screen-active .screen-stage video {
    min-height: 45vh;
    max-height: 52vh;
  }

  .messages {
    padding: 16px 12px;
  }

  .message {
    max-width: 88%;
  }

  .composer {
    grid-template-columns: 44px minmax(0, 1fr) 92px;
    padding: 12px;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  #localScreen {
    width: 112px;
    height: 72px;
  }

  .chat-panel.screen-active #localScreen {
    width: 132px;
    height: 82px;
  }

  .auth-actions {
    grid-template-columns: 1fr;
  }
}
