:root {
  color-scheme: dark;
  --bg: #071015;
  --panel: #101c23;
  --panel-2: #17262f;
  --panel-3: #1d303a;
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef5f3;
  --muted: #92a6ac;
  --green: #24d18b;
  --green-dark: #0b8e61;
  --green-soft: rgba(36, 209, 139, 0.14);
  --outgoing: #075e54;
  --incoming: #1b2d36;
  --danger: #ef5b68;
  --warning: #ffc857;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: var(--green); }
[hidden] { display: none !important; }

.flash-stack {
  position: fixed;
  top: 16px;
  left: 50%;
  z-index: 200;
  width: min(92vw, 560px);
  transform: translateX(-50%);
}
.flash {
  margin-bottom: 8px;
  padding: 12px 16px;
  border: 1px solid rgba(36, 209, 139, .35);
  border-radius: 12px;
  background: #15332c;
  box-shadow: var(--shadow);
}
.flash-error { background: #421d24; border-color: rgba(239, 91, 104, .4); }

.auth-body {
  background:
    radial-gradient(circle at 20% 15%, rgba(36, 209, 139, .12), transparent 30rem),
    radial-gradient(circle at 85% 85%, rgba(40, 119, 138, .12), transparent 30rem),
    var(--bg);
}
.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 28px 18px;
}
.auth-card, .form-card, .control-card {
  width: min(100%, 430px);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(16, 28, 35, .94);
  box-shadow: var(--shadow);
}
.auth-card-wide { width: min(100%, 570px); }
.brand-mark, .empty-mark {
  display: grid;
  width: 56px;
  height: 56px;
  margin: 0 auto 18px;
  place-items: center;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--green), #128c7e);
  color: #03251a;
  font-size: 28px;
  font-weight: 800;
  box-shadow: 0 12px 30px rgba(36, 209, 139, .25);
}
.auth-card h1 { margin: 0; text-align: center; font-size: 27px; }
.auth-lead { margin: 8px 0 26px; text-align: center; color: var(--muted); line-height: 1.5; }
.privacy-note { margin: 20px 0 0; color: var(--muted); text-align: center; font-size: 13px; line-height: 1.45; }

.stack-form { display: grid; gap: 17px; }
.field { display: grid; gap: 7px; color: #dbe7e4; font-size: 14px; }
.field > span { font-weight: 650; }
.field input, .field textarea, .field select, .mini-form input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, .11);
  border-radius: 11px;
  outline: none;
  background: #0a161c;
  color: var(--text);
  padding: 12px 13px;
  transition: border-color .18s, box-shadow .18s;
}
.field input:focus, .field textarea:focus, .mini-form input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(36, 209, 139, .12);
}
.field small, .field em { color: var(--muted); font-size: 12px; font-style: normal; line-height: 1.4; }
.field em { color: #ff8e97; }
.check-field { display: flex; gap: 10px; align-items: center; }
.form-error {
  padding: 10px 12px;
  border: 1px solid rgba(239, 91, 104, .3);
  border-radius: 10px;
  background: rgba(239, 91, 104, .09);
  color: #ffabb2;
  font-size: 13px;
}
.form-error ul { margin: 0; padding-left: 18px; }
.primary-button, .secondary-button, .danger-button {
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  padding: 0 20px;
  font-weight: 750;
  transition: transform .15s, filter .15s;
}
.primary-button { background: var(--green); color: #06241b; }
.secondary-button { background: var(--panel-3); color: var(--text); }
.danger-button { background: var(--danger); color: #fff; }
.primary-button:hover, .secondary-button:hover, .danger-button:hover { filter: brightness(1.08); }
.primary-button:active, .secondary-button:active, .danger-button:active { transform: translateY(1px); }
.wide { width: 100%; }
.compact { min-height: 38px; padding: 0 14px; font-size: 13px; }
.button-link { display: grid; place-items: center; text-decoration: none; }
.notice {
  margin: 0 0 20px;
  padding: 13px 14px;
  border-radius: 12px;
  background: var(--green-soft);
  color: #c7e7dc;
  line-height: 1.5;
}
.danger-zone { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); text-align: center; }
.danger-zone a { color: #ff8791; }
.qr-code {
  display: block;
  width: min(280px, 90%);
  margin: 0 auto 18px;
  padding: 12px;
  border-radius: 16px;
  background: #fff;
}
.manual-key { margin: 0 0 22px; color: var(--muted); }
.manual-key summary { cursor: pointer; color: var(--text); }
.manual-key code { display: block; overflow-wrap: anywhere; margin-top: 12px; color: var(--green); }
.manual-key p { font-size: 12px; }
.recovery-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 22px 0; }
.recovery-grid code { padding: 10px; border: 1px solid var(--line); border-radius: 9px; background: #071116; text-align: center; }

.page-body { background: #091217; }
.page-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  min-height: 66px;
  align-items: center;
  gap: 18px;
  padding: 10px max(18px, calc((100vw - 1160px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(16, 28, 35, .96);
  backdrop-filter: blur(14px);
}
.page-topbar h1 { flex: 1; margin: 0; font-size: 20px; }
.icon-link {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 50%;
  text-decoration: none;
  color: var(--text);
  font-size: 25px;
}
.icon-link:hover { background: var(--panel-3); }
.page-container { display: grid; place-items: start center; padding: 34px 18px; }
.form-card { width: min(100%, 620px); }
.control-container { display: grid; width: min(1180px, calc(100% - 32px)); margin: 26px auto 50px; gap: 22px; }
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.stat-card { padding: 20px; border: 1px solid var(--line); border-radius: 17px; background: var(--panel); }
.stat-card strong { display: block; font-size: 25px; }
.stat-card span { color: var(--muted); font-size: 13px; }
.control-card { width: 100%; padding: 0; overflow: hidden; }
.section-heading { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.section-heading h2 { margin: 0 0 4px; font-size: 18px; }
.section-heading p { margin: 0; color: var(--muted); font-size: 13px; }
.table-scroll { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 14px 18px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 13px; }
th { color: var(--muted); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
td strong, td small { display: block; }
td small { margin-top: 4px; color: var(--muted); }
.status-pill { display: inline-block; padding: 5px 9px; border-radius: 20px; font-size: 11px; font-weight: 750; }
.status-pill.active { color: var(--green); background: var(--green-soft); }
.status-pill.paused { color: var(--warning); background: rgba(255, 200, 87, .12); }
.status-pill.owner { color: #8fd7ff; background: rgba(62, 166, 224, .12); }
.action-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.action-row form { margin: 0; }
.text-button, .inline-details summary {
  border: 0;
  background: none;
  color: var(--green);
  padding: 3px 0;
  cursor: pointer;
  font-size: 12px;
}
.danger-text { color: #ff7d88; }
.inline-details { position: relative; }
.inline-details summary { list-style: none; }
.mini-form {
  position: absolute;
  z-index: 10;
  display: grid;
  width: 220px;
  gap: 8px;
  right: 0;
  top: 27px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0b171d;
  box-shadow: var(--shadow);
}
.mini-form input { padding: 8px 9px; font-size: 12px; }
.mini-form button { border: 0; border-radius: 8px; padding: 8px; background: var(--green); color: #05251b; font-weight: 700; cursor: pointer; }

.messenger-body { overflow: hidden; }
.messenger-shell {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  height: 100dvh;
  max-width: 1720px;
  margin: 0 auto;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.enable-call-sound {
  position: fixed;
  z-index: 50;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  border: 0;
  border-radius: 999px;
  padding: 9px 16px;
  color: #fff;
  background: #087f5b;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.28);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
.sidebar { min-width: 0; border-right: 1px solid var(--line); background: #0c171d; }
.sidebar-header, .chat-header {
  display: flex;
  min-height: 66px;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--panel);
}
.self-summary, .chat-person { min-width: 0; flex: 1; }
.self-summary strong, .self-summary small, .chat-person strong, .chat-person small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.self-summary small, .chat-person small { margin-top: 3px; color: var(--muted); font-size: 12px; }
.avatar {
  position: relative;
  display: grid;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  background: linear-gradient(135deg, #39515e, #23343d);
  color: #d6e6e2;
  font-weight: 800;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.small-avatar { flex-basis: 40px; width: 40px; height: 40px; }
.header-actions, .chat-actions { display: flex; gap: 3px; align-items: center; }
.header-actions form { display: flex; margin: 0; }
.round-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #b7c8cc;
  cursor: pointer;
  text-decoration: none;
  font-size: 19px;
}
.round-button:hover { background: rgba(255, 255, 255, .07); color: var(--text); }
.call-button { color: var(--green); }
.contact-tools { padding: 10px 12px 12px; border-bottom: 1px solid var(--line); }
.search-box { display: flex; height: 38px; align-items: center; gap: 8px; padding: 0 12px; border-radius: 10px; background: var(--panel-2); color: var(--muted); }
.search-box input, .number-add input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}
.number-add { display: flex; margin-top: 8px; height: 38px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.number-add input { padding: 0 12px; }
.number-add button { width: 42px; border: 0; background: var(--green-soft); color: var(--green); cursor: pointer; font-size: 20px; }
.inline-error { margin: 8px 2px 0; color: #ff8a94; font-size: 12px; }
.contact-list { height: calc(100dvh - 164px); overflow-y: auto; overscroll-behavior: contain; }
.contact-item {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, .045);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.contact-item:hover, .contact-item.active { background: var(--panel-2); }
.contact-copy { min-width: 0; flex: 1; }
.contact-copy strong, .contact-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-copy small { margin-top: 4px; color: var(--muted); font-size: 12px; }
.contact-meta { display: grid; justify-items: end; gap: 5px; color: var(--muted); font-size: 11px; }
.unread {
  display: grid;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  place-items: center;
  border-radius: 12px;
  background: var(--green);
  color: #04271c;
  font-weight: 800;
}
.online-dot {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 10px;
  height: 10px;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: var(--green);
}
.list-placeholder { padding: 30px 20px; color: var(--muted); text-align: center; line-height: 1.5; }

.chat-panel { position: relative; min-width: 0; background: #09151b; }
.empty-chat { display: grid; height: 100%; place-content: center; justify-items: center; padding: 30px; text-align: center; }
.empty-chat h1 { margin: 4px 0 7px; font-size: 31px; }
.empty-chat p { margin: 0; color: var(--muted); }
.empty-chat small { margin-top: 25px; color: #60767d; }
.active-chat { display: grid; height: 100%; grid-template-rows: auto 1fr auto; }
.chat-header { border-bottom: 1px solid var(--line); }
.mobile-back { display: none; border: 0; background: none; color: var(--text); font-size: 25px; cursor: pointer; }
.message-list {
  overflow-y: auto;
  padding: 22px clamp(16px, 5vw, 78px);
  background:
    linear-gradient(rgba(8, 20, 26, .92), rgba(8, 20, 26, .92)),
    radial-gradient(circle at 10px 10px, rgba(255,255,255,.055) 1px, transparent 1.5px);
  background-size: auto, 23px 23px;
  overscroll-behavior: contain;
}
.message-row { display: flex; margin: 4px 0; }
.message-row.mine { justify-content: flex-end; }
.message-bubble {
  position: relative;
  max-width: min(78%, 680px);
  padding: 8px 11px 6px;
  border-radius: 8px 8px 8px 2px;
  background: var(--incoming);
  box-shadow: 0 1px 1px rgba(0,0,0,.16);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.42;
}
.message-row.mine .message-bubble { border-radius: 8px 8px 2px 8px; background: var(--outgoing); }
.message-time { margin-left: 8px; color: rgba(226, 239, 235, .62); font-size: 10px; white-space: nowrap; float: right; transform: translateY(4px); }
.composer { display: flex; align-items: flex-end; gap: 9px; padding: 10px 14px; border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea {
  min-height: 42px;
  max-height: 128px;
  flex: 1;
  resize: none;
  border: 0;
  border-radius: 12px;
  outline: 0;
  background: var(--panel-3);
  color: var(--text);
  padding: 11px 14px;
  line-height: 1.4;
}
.send-button {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border: 0;
  border-radius: 50%;
  background: var(--green);
  color: #073022;
  cursor: pointer;
  font-size: 20px;
}

.modal-backdrop, .call-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
}
.modal-backdrop { display: grid; place-items: center; padding: 20px; background: rgba(2, 8, 11, .74); backdrop-filter: blur(10px); }
.incoming-card {
  width: min(92vw, 360px);
  padding: 34px 28px 27px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
}
.call-avatar { width: 88px; height: 88px; margin: 0 auto; font-size: 31px; }
.call-avatar.large { width: 130px; height: 130px; font-size: 46px; }
.incoming-card p { margin: 20px 0 6px; color: var(--green); }
.incoming-card h2 { margin: 0; }
.incoming-actions { display: flex; justify-content: center; gap: 45px; margin-top: 30px; }
.call-control {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.14);
  color: #fff;
  cursor: pointer;
  font-size: 21px;
  backdrop-filter: blur(10px);
}
.call-control.off { background: #fff; color: #1e2d33; }
.danger-control { background: var(--danger); }
.accept-control { background: var(--green); color: #05261b; }
.call-screen { overflow: hidden; background: #050b0e; }
#remoteMedia { width: 100%; height: 100%; object-fit: cover; background: #050b0e; }
.audio-call-bg { position: absolute; inset: 0; display: grid; place-items: center; background: radial-gradient(circle at 50% 38%, #244652, #081116 60%); }
#localMedia {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  right: 18px;
  width: min(25vw, 230px);
  aspect-ratio: 3 / 4;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 18px;
  object-fit: cover;
  background: #111;
  box-shadow: 0 10px 35px rgba(0,0,0,.35);
}
.call-info { position: absolute; top: max(22px, env(safe-area-inset-top)); left: 22px; max-width: calc(100% - 300px); text-shadow: 0 2px 10px #000; }
.call-info h2 { margin: 0 0 6px; }
.call-info p { margin: 0; color: #d2e4df; }
.call-toolbar {
  position: absolute;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  display: flex;
  gap: 14px;
  transform: translateX(-50%);
}
.audio-output {
  position: absolute;
  right: 20px;
  bottom: 92px;
  max-width: 280px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  padding: 10px;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 300;
  max-width: min(90vw, 480px);
  transform: translateX(-50%);
  border-radius: 12px;
  background: rgba(5, 15, 19, .94);
  color: var(--text);
  padding: 11px 16px;
  box-shadow: var(--shadow);
}

@media (max-width: 760px) {
  .messenger-shell { display: block; }
  .sidebar { height: 100dvh; border-right: 0; }
  .chat-panel {
    position: fixed;
    inset: 0;
    z-index: 30;
    transform: translateX(100%);
    transition: transform .2s ease;
  }
  .messenger-shell.chat-open .chat-panel { transform: translateX(0); }
  .mobile-back { display: block; }
  .self-summary small { display: none; }
  .contact-list { height: calc(100dvh - 164px); }
  .message-list { padding: 16px 11px; }
  .message-bubble { max-width: 87%; }
  .chat-actions { gap: 0; }
  .round-button { width: 36px; height: 36px; }
  .call-toolbar { width: 100%; justify-content: center; gap: 9px; padding: 0 10px; }
  .call-control { width: 48px; height: 48px; }
  #localMedia { width: 28vw; min-width: 100px; right: 12px; }
  .call-info { left: 15px; max-width: calc(100% - 150px); }
  .stats-row { grid-template-columns: 1fr; }
  .page-topbar { padding: 10px 14px; }
  .page-topbar .compact { display: none; }
}

@media (max-width: 430px) {
  .auth-card, .form-card { padding: 23px 18px; border-radius: 18px; }
  .recovery-grid { grid-template-columns: 1fr; }
  .self-summary { display: none; }
  .sidebar-header { justify-content: space-between; }
}

@media print {
  body { background: #fff; color: #000; }
  .auth-card { box-shadow: none; border: 0; background: #fff; }
  .secondary-button, .primary-button, .auth-lead, .brand-mark { display: none !important; }
  .recovery-grid code { color: #000; border-color: #aaa; background: #fff; }
}
