:root {
  /* Palette premium/masculine : charbon + bronze, ni violet ni bleu royal. */
  --bg: #f3f1ec;
  --card: #16181a;
  --card-recessed: #0c0d0e;
  --panel: #202225;
  --panel-hover: #2a2c2f;
  --line: #35383b;
  --accent: #a97c3f;
  --accent-hover: #c39355;
  --accent-dark: #7c5a2c;
  --text: #f1ede4;
  --muted: #96918a;
  --ok: #4a7a5c;
  --danger: #9c4038;
  --danger-hover: #b6534a;
  --warning: #c2922f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding: 24px 16px 60px;
}

.tabs {
  width: 100%;
  max-width: 460px;
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  justify-content: center;
}
.tabs button {
  flex: 1 1 auto;
  min-width: 80px;
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
}
.tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.card {
  background-color: var(--card);
  border-radius: 16px;
  padding: 28px 24px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.card.wide { max-width: 640px; }

.view { display: none; }
.view.active { display: block; }

h1.title { font-size: 20px; margin: 0 0 4px; text-align: center; }
.subtitle { color: var(--muted); font-size: 14px; text-align: center; margin-bottom: 22px; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; margin-top: 14px; }
label:first-of-type { margin-top: 0; }

input[type="text"], input[type="password"], input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card-recessed);
  color: var(--text);
  font-size: 15px;
}

button.primary {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  margin-top: 18px;
}
button.primary:hover { background: var(--accent-hover); }
button.primary:disabled { opacity: 0.5; cursor: not-allowed; }

.link-btn {
  display: block;
  text-align: center;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  width: 100%;
}

.error-text { color: var(--danger-hover); font-size: 13px; margin-top: 10px; text-align: center; min-height: 16px; }

.number-badge {
  display: inline-block;
  background: var(--card-recessed);
  border: 1px solid var(--line);
  color: var(--accent-hover);
  font-weight: 700;
  letter-spacing: 1px;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 15px;
}

.own-number-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-recessed);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 18px;
  font-size: 13px;
  color: var(--muted);
}

.dial-row { display: flex; gap: 8px; margin-bottom: 18px; }
.dial-row input { flex: 1; letter-spacing: 1px; }
.dial-row button { background: var(--ok); border: none; color: #fff; border-radius: 10px; padding: 0 18px; font-size: 18px; cursor: pointer; }

.contact { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 10px; }
.contact:hover { background: var(--panel); }

.avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--accent-dark); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; flex-shrink: 0; position: relative;
}
.dot { width: 10px; height: 10px; border-radius: 50%; position: absolute; bottom: -1px; right: -1px; border: 2px solid var(--card); }
.dot.online { background: var(--ok); }
.dot.offline { background: #566475; }

.contact-name { font-weight: 600; font-size: 14.5px; }
.contact-number { color: var(--muted); font-size: 12.5px; }
.contact-status { margin-left: auto; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

.icon-btn {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 15px; margin-left: 8px;
}
.icon-btn.call { background: var(--ok); border-color: var(--ok); color: #06331a; }
.icon-btn.msg { background: var(--accent); border-color: var(--accent); color: #fff; position: relative; }
.icon-btn.msg.has-unread::after {
  content: "";
  position: absolute;
  top: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger-hover);
  border: 2px solid var(--card);
}
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.call-screen { text-align: center; padding: 10px 0 0; }
.call-avatar {
  width: 96px; height: 96px; border-radius: 50%; background: var(--accent-dark); color: #fff;
  font-size: 34px; font-weight: 700; display: flex; align-items: center; justify-content: center;
  margin: 6px auto 18px; position: relative;
}
.call-avatar.ringing::before {
  content: ""; position: absolute; inset: -10px; border-radius: 50%;
  border: 2px solid var(--accent); animation: pulse 1.6s ease-out infinite;
}
@keyframes pulse { 0% { transform: scale(0.9); opacity: 0.9; } 100% { transform: scale(1.5); opacity: 0; } }
.call-name { font-size: 19px; font-weight: 700; margin-bottom: 2px; }
.call-number { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.call-status { color: var(--muted); font-size: 14px; margin-bottom: 26px; }
.call-status.live { color: var(--ok); font-weight: 600; }
.e2ee-badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ok);
  background: rgba(46,204,113,0.12); border: 1px solid rgba(46,204,113,0.35);
  padding: 4px 10px; border-radius: 999px; margin-bottom: 22px;
}
.call-actions { display: flex; justify-content: center; gap: 22px; }
.round-btn { width: 62px; height: 62px; border-radius: 50%; border: none; font-size: 24px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.round-btn.accept { background: var(--ok); color: #06331a; }
.round-btn.decline, .round-btn.hangup { background: var(--danger); color: #3a0a0d; }
.round-btn.mute { background: var(--panel); color: var(--text); border: 1px solid var(--line); }
.round-btn.mute.active { background: var(--warning); color: #4a3800; }
.round-btn-label { font-size: 11px; color: var(--muted); margin-top: 6px; }
.call-action-col { display: flex; flex-direction: column; align-items: center; }
.in-call-row { display: flex; gap: 22px; justify-content: center; margin-bottom: 26px; }

.sms-header { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.sms-header .who { flex: 1; }
.sms-thread { display: flex; flex-direction: column; gap: 8px; padding: 16px 2px; min-height: 220px; max-height: 320px; overflow-y: auto; }
.bubble { max-width: 75%; padding: 9px 13px; border-radius: 14px; font-size: 14px; line-height: 1.35; transition: opacity 0.6s ease; }
.bubble.them { background: var(--panel); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.me { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble.fading { opacity: 0; }
.bubble.pending .img-meta, .bubble.pending .queued-tag { color: var(--warning); }
.queued-tag { display: block; font-size: 10px; margin-top: 3px; opacity: 0.8; }
.bubble.image-bubble { padding: 6px; max-width: 68%; }
.bubble.image-bubble img { display: block; max-width: 100%; border-radius: 9px; }
.bubble.image-bubble .img-meta { font-size: 10.5px; opacity: 0.75; margin: 5px 3px 1px; }

.ephemeral-banner { font-size: 11.5px; color: var(--muted); text-align: center; margin: 4px 0 10px; }
.sms-input-row { display: flex; gap: 8px; margin-top: 8px; }
.sms-input-row input { flex: 1; }
.sms-input-row button { background: var(--accent); border: none; color: #fff; border-radius: 10px; padding: 0 16px; font-size: 14px; cursor: pointer; }
.attach-btn { background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 10px; width: 42px; font-size: 16px; cursor: pointer; }
.compressing-note { font-size: 11px; color: var(--muted); text-align: center; margin-top: 6px; }
.end-session-btn {
  width: 100%; margin-top: 14px; background: none; border: 1px dashed var(--danger); color: var(--danger-hover);
  border-radius: 10px; padding: 9px; font-size: 12.5px; cursor: pointer;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 22px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
tr.suspended td { opacity: 0.45; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.active { background: rgba(46,204,113,0.15); color: var(--ok); }
.badge.suspended { background: rgba(224,85,95,0.15); color: var(--danger-hover); }
.badge.admin { background: rgba(108,99,224,0.2); color: var(--accent-hover); margin-left: 6px; }
.small-btn { background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 7px; padding: 5px 10px; font-size: 12px; cursor: pointer; }
.section-heading { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin: 22px 0 10px; }
.section-heading:first-of-type { margin-top: 0; }
.limits-grid { display: grid; grid-template-columns: 1fr 100px; gap: 10px 14px; align-items: center; font-size: 13px; }
.limits-grid .lbl { color: var(--muted); }

.create-box {
  background: var(--card-recessed);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px 16px;
  margin-bottom: 22px;
}
.create-box-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
}
.create-box label { margin-top: 10px; font-size: 12px; }
.create-box label:first-of-type { margin-top: 0; }
.create-box button.primary { margin-top: 14px; }
.create-result {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
  text-align: center;
}
.create-result-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.lang-switch {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 14px;
}
.lang-switch button {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  opacity: 0.55;
}
.lang-switch button.active { opacity: 1; border-color: var(--accent); background: var(--panel-hover); }

.badge.disabled { background: rgba(150,145,138,0.18); color: var(--muted); }
.badge.blocked { background: rgba(156,64,56,0.18); color: var(--danger-hover); }
.badge.super { background: rgba(169,124,63,0.2); color: var(--accent-hover); margin-left: 6px; }

/* Mode detresse (acces d'urgence Master) - impossible a confondre avec une
   session normale : ecran rouge global + bandeau pulsant. */
body.emergency-mode {
  background: #4a0e0e;
}
body.emergency-mode .card {
  background-color: #2c0a0a;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
}
body.emergency-mode .lang-switch button.active,
body.emergency-mode .tabs button.active {
  background: var(--danger);
  border-color: var(--danger);
}

.emergency-banner {
  background: var(--danger);
  border: 1px solid #e07068;
  color: #fff;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 14px;
  animation: emergency-pulse 1.6s ease-in-out infinite;
}
@keyframes emergency-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(156,64,56,0.55); }
  50% { box-shadow: 0 0 0 8px rgba(156,64,56,0); }
}

.contact-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  margin: 10px 0;
}
.contact-picker label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 7px 9px;
  border-radius: 8px;
  background: var(--card-recessed);
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text);
}
.participant-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  margin: 3px;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 4px;
}

@media (max-width: 640px) {
  body { padding: 16px 10px 40px; }
  .card, .card.wide { padding: 20px 16px; border-radius: 12px; max-width: 100%; }
  .lang-switch { margin-bottom: 10px; }
  .tabs button { font-size: 12.5px; padding: 8px 8px; min-width: 0; }
  .contact { flex-wrap: wrap; row-gap: 8px; }
  .contact-status { flex-wrap: wrap; justify-content: flex-end; row-gap: 6px; margin-left: 0; }
  .own-number-row { flex-wrap: wrap; row-gap: 8px; }
  table { font-size: 12px; }
  th, td { padding: 7px 6px; }
  .table-scroll table { min-width: 540px; }
  .limits-grid { grid-template-columns: 1fr 78px; gap: 8px 10px; }
  .call-actions, .in-call-row { gap: 14px; }
  .round-btn { width: 56px; height: 56px; font-size: 20px; }
  .call-avatar { width: 80px; height: 80px; font-size: 28px; }
}

@media (max-width: 380px) {
  .number-badge { font-size: 13px; padding: 6px 10px; }
  .success-numero, #success-numero { font-size: 24px !important; }
}
