* { box-sizing: border-box }

html, body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  background: #1a1d22;
  color: #e8eaed;
  overflow: hidden;     /* off-screen siblings (translateX) must not extend scroll area */
}

button {
  font: inherit;
  padding: .55rem 1.1rem;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  background: #3a3f45;
  color: #e8eaed;
}
button.primary   { background: #3a6ea5; color: white }
button.primary:hover   { background: #4685c7 }
button.secondary { background: #3a3f45 }
button.secondary:hover { background: #4a4f55 }
button.danger    { background: #b03030; color: white }
button.iconbtn   { background: transparent; padding: .3rem .55rem; font-size: 1.25rem }

input[type=text] {
  font: inherit; padding: .55rem .7rem;
  background: #1a1d22; color: #e8eaed;
  border: 1px solid #3a3f45; border-radius: 8px;
  width: 100%;
}
input[type=text]:focus { outline: none; border-color: #4685c7 }

/* ============================== screens ============================== */

.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  background: #1a1d22;
  overflow: hidden;
}
.screen.active { display: flex; }

.topbar {
  display: flex; align-items: center; gap: .5rem;
  padding: .6rem 1rem; background: #24272d;
  border-bottom: 1px solid #2f343a;
}
.topbar .title {
  flex: 1; font-weight: 600; font-size: 1.05rem;
  display: flex; align-items: center; gap: .4rem;
}
.muted-line {
  padding: .25rem 1rem; background: #20232a; color: #8a8f95;
  font-size: .8rem;
}
.muted { color: #8a8f95; font-size: .85rem }

.fatal {
  background: #5a2020; border-bottom: 1px solid #a44;
  padding: .8rem 1rem; color: #ffe0e0; font-weight: 500;
}

/* ============================== contacts ============================== */

.contacts {
  list-style: none; padding: 0; margin: 0;
  flex: 1; overflow-y: auto;
}
.contact {
  display: flex; align-items: center; gap: .75rem;
  padding: .85rem 1rem;
  border-bottom: 1px solid #20232a;
  cursor: pointer; user-select: none;
}
.contact:hover { background: #20232a }
.contact .avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: #3a6ea5; color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: .9rem; flex: 0 0 auto;
}
.contact .avatar.off { background: #3a3f45; color: #8a8f95 }
.contact .name { flex: 1; font-weight: 500 }
.contact .id   { color: #6a6f75; font-size: .8rem; font-family: ui-monospace, monospace; }
.contact .dot  { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto }

.dot-on  { background: #3c3; box-shadow: 0 0 5px #3c3 }
.dot-off { background: #555 }

.empty {
  padding: 2rem 1rem; color: #8a8f95; font-size: .9rem; text-align: center;
}

.bottombar {
  display: flex; gap: .5rem; padding: .75rem 1rem;
  background: #24272d; border-top: 1px solid #2f343a;
}
.bottombar button { flex: 1 }

/* ============================== call screen ============================== */

#screen-call .video-stage {
  position: relative; flex: 1;
  background: #000;
  min-height: 280px;
}
.peer-video {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: contain;
  background: #000;
}
.my-video {
  position: absolute; right: 12px; bottom: 12px;
  width: 30%; max-width: 180px; aspect-ratio: 3/4;
  border-radius: 8px; border: 2px solid #24272d;
  object-fit: cover; background: #111;
  z-index: 2;
}
#screen-call .controls {
  display: flex; gap: .5rem; padding: .75rem 1rem; flex-wrap: wrap;
  background: #24272d; border-top: 1px solid #2f343a;
}
#screen-call .controls button { flex: 1; min-width: 110px }

.chat-wrap {
  display: flex; flex-direction: column;
  max-height: 260px; min-height: 100px;
  background: #1a1d22;
  border-top: 1px solid #2f343a;
}
#chat {
  flex: 1; overflow-y: auto;
  padding: .5rem .75rem;
  display: flex; flex-direction: column; gap: .25rem;
}
.msg {
  max-width: 75%; padding: .35rem .6rem;
  border-radius: 12px; font-size: .9rem; word-wrap: break-word;
}
.msg.me   { background: #3a6ea5; align-self: flex-end }
.msg.them { background: #3a3f45; align-self: flex-start }
.chat-input {
  display: flex; gap: .5rem; padding: .5rem .75rem;
  border-top: 1px solid #2f343a;
}
.chat-input input { flex: 1 }
.chat-input button { flex: 0 0 auto }

/* ============================== dialogs ============================== */

.dialog {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(0,0,0,.6);
  display: none; align-items: center; justify-content: center;
  padding: 1rem;
}
.dialog:not([hidden]) { display: flex; }
.dialog-box {
  background: #24272d; border-radius: 12px;
  padding: 1.25rem; max-width: 420px; width: 100%;
  display: flex; flex-direction: column; gap: .5rem;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.dialog-title { font-size: 1.1rem; font-weight: 600; margin-bottom: .25rem }
.dialog-text  { color: #b8bdc3; font-size: .9rem }
.dialog-box label { font-size: .8rem; color: #8a8f95; margin-top: .25rem }
.dialog-error { background: #5a2020; color: #ffe0e0; padding: .5rem .75rem; border-radius: 6px; font-size: .85rem }
.dialog-buttons {
  display: flex; gap: .5rem; justify-content: flex-end; margin-top: .75rem;
}

/* ============================== toasts ============================== */

.toasts {
  position: fixed; bottom: 1rem; right: 1rem; z-index: 20;
  display: flex; flex-direction: column; gap: .5rem;
}
.toast {
  background: #2f343a; color: #e8eaed;
  padding: .6rem 1rem; border-radius: 8px;
  border-left: 3px solid #3a6ea5;
  font-size: .9rem; min-width: 200px; max-width: 360px;
  animation: toast-in .2s ease-out;
}
.toast.error   { border-left-color: #b03030 }
.toast.success { border-left-color: #3a9a3a }
@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0 }
  to   { transform: translateX(0);    opacity: 1 }
}

@media (max-width: 600px) {
  .my-video { width: 35%; max-width: 140px }
  .contact .id { display: none }
}
