:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-muted: #eef2f5;
  --ink: #172026;
  --muted: #61717d;
  --line: #d8e0e6;
  --input: #eaf2ff;
  --accent: #0f766e;
  --accent-strong: #0a5f59;
  --login-blue: #1557d5;
  --login-blue-strong: #1046b0;
  --danger: #c2410c;
  --danger-strong: #9a3412;
  --online: #159947;
  --busy: #c2410c;
  --ringing: #b7791f;
  --offline: #87919a;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

[hidden] {
  display: none !important;
}

button,
select {
  font: inherit;
}

button {
  min-height: 2.5rem;
  border: 0;
  border-radius: 8px;
  padding: 0 1rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--accent-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button.secondary {
  background: var(--surface-muted);
  color: var(--ink);
}

button.secondary:hover:not(:disabled) {
  background: #dde6ec;
}

button.danger {
  background: var(--danger);
}

button.danger:hover:not(:disabled) {
  background: var(--danger-strong);
}

select {
  min-height: 2.5rem;
  min-width: 11rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 0.75rem;
  background: var(--surface);
  color: var(--ink);
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 28px;
}

.login-card {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 520px);
  align-items: center;
  gap: clamp(40px, 7vw, 112px);
  width: min(1280px, 100%);
  min-height: min(560px, calc(100vh - 56px));
  padding: clamp(42px, 5.4vw, 76px);
  background: var(--surface);
  border-radius: 28px;
}

.login-logo {
  display: block;
  width: 58px;
  height: auto;
  margin: 0 0 56px 10px;
}

.login-copy h1 {
  margin: 0;
  color: #24262a;
  font-size: clamp(2.4rem, 3.6vw, 3.35rem);
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1;
}

.login-copy p {
  margin: 26px 0 0;
  color: #000;
  font-size: clamp(1.2rem, 1.7vw, 1.55rem);
  letter-spacing: 0;
}

.login-form {
  display: grid;
  gap: 18px;
  align-items: end;
  margin-top: 72px;
}

.login-form label {
  display: grid;
  gap: 0.5rem;
}

.login-form label span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.login-form input {
  width: 100%;
  min-height: 60px;
  border: 1px solid #8792a0;
  border-radius: 6px;
  padding: 0 20px;
  background: var(--input);
  color: #000;
  font: inherit;
  font-size: 1.16rem;
}

.login-form button {
  justify-self: end;
  min-width: 108px;
  min-height: 56px;
  margin-top: 24px;
  border-radius: 28px;
  background: var(--login-blue);
  font-size: 1.12rem;
  font-weight: 700;
}

.login-form button:hover:not(:disabled) {
  background: var(--login-blue-strong);
}

.login-error {
  min-height: 1.25rem;
  margin: 0;
  color: var(--danger);
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 20px;
}

.topbar h1,
.panel-heading h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(1.65rem, 3vw, 2.25rem);
}

.topbar p {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

.identity {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

#currentUser {
  color: var(--muted);
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 20px;
  align-items: start;
}

.contacts-panel,
.call-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.contacts-panel {
  min-height: 580px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2 {
  font-size: 1rem;
}

#contactCount {
  color: var(--muted);
}

.contacts-list {
  display: grid;
}

.contact-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 1rem;
  min-height: 72px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.contact-row:last-child {
  border-bottom: 0;
}

.contact-name {
  display: block;
  font-weight: 700;
}

.contact-presence {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.2rem;
  color: var(--muted);
  text-transform: capitalize;
}

.presence-dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: var(--offline);
}

.presence-dot.online {
  background: var(--online);
}

.presence-dot.busy {
  background: var(--busy);
}

.presence-dot.ringing {
  background: var(--ringing);
}

.call-panel {
  overflow: hidden;
}

.videos {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  min-height: 360px;
  background: #11191f;
}

.videos:fullscreen {
  display: grid;
  width: 100vw;
  height: 100vh;
  aspect-ratio: auto;
  min-height: 0;
}

.videos:fullscreen .local-video {
  right: 24px;
  bottom: 24px;
  width: min(320px, 28vw);
}

video {
  display: block;
  background: #11191f;
}

.remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.local-video {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: min(220px, 32%);
  aspect-ratio: 16 / 10;
  height: auto;
  border: 2px solid #ffffff;
  border-radius: 8px;
  object-fit: cover;
}

.callbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 86px;
  padding: 18px;
  border-top: 1px solid var(--line);
}

.callbar strong,
.callbar span {
  display: block;
}

.callbar span {
  margin-top: 0.25rem;
  color: var(--muted);
}

.call-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

dialog {
  width: min(360px, calc(100% - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 72px rgb(23 32 38 / 0.18);
}

dialog::backdrop {
  background: rgb(17 25 31 / 0.45);
}

.incoming-card {
  padding: 20px;
}

.incoming-card p {
  margin: 0 0 18px;
  font-size: 1.1rem;
  font-weight: 700;
}

.incoming-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.history-dialog {
  width: min(720px, calc(100% - 32px));
}

.history-card {
  display: grid;
  gap: 14px;
  max-height: min(720px, calc(100vh - 48px));
  padding: 20px;
}

.history-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
}

.history-heading h2 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: 0;
}

.history-heading p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-weight: 700;
}

.history-error {
  min-height: 1.25rem;
  margin: 0;
  color: var(--danger);
}

.history-list {
  display: grid;
  max-height: min(520px, calc(100vh - 190px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.history-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 1rem;
  min-height: 68px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.history-row:last-child {
  border-bottom: 0;
}

.history-row strong,
.history-row span {
  display: block;
}

.history-row div > span {
  margin-top: 0.25rem;
  color: var(--muted);
}

.history-duration {
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.history-status {
  min-width: 6.5rem;
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  background: var(--surface-muted);
  color: var(--ink);
  text-align: center;
  text-transform: capitalize;
}

.history-status.ended {
  background: #dcfce7;
  color: #166534;
}

.history-status.missed,
.history-status.rejected,
.history-status.cancelled {
  background: #ffedd5;
  color: #9a3412;
}

.history-empty {
  margin: 0;
  padding: 20px;
  color: var(--muted);
}

@media (max-width: 820px) {
  .login-shell {
    padding: 16px;
  }

  .login-card {
    grid-template-columns: 1fr;
    gap: 36px;
    min-height: auto;
    padding: 32px 22px;
    border-radius: 24px;
  }

  .login-logo {
    width: 58px;
    margin: 0 0 42px 0;
  }

  .login-copy p {
    margin-top: 24px;
  }

  .login-form {
    margin-top: 0;
  }

  .login-form input {
    min-height: 62px;
    font-size: 1.1rem;
  }

  .login-form button {
    width: 100%;
    min-height: 56px;
    margin-top: 12px;
  }

  .shell {
    width: min(100% - 20px, 680px);
    padding-top: 12px;
  }

  .topbar,
  .callbar {
    align-items: stretch;
    flex-direction: column;
  }

  .identity,
  .call-actions {
    width: 100%;
  }

  .identity > *,
  .call-actions > * {
    flex: 1;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .contacts-panel {
    min-height: 0;
  }

  .videos {
    min-height: 300px;
  }

  .local-video {
    right: 10px;
    bottom: 10px;
    width: min(150px, 42%);
  }

  .history-row {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .history-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .history-status {
    min-width: 0;
    justify-self: start;
  }
}
