:root {
  --bg: #e9edf3;
  --ink: #171b22;
  --muted: #667084;
  --line: #e6e9f0;
  --card: #ffffff;
  --field: #f4f6f9;
  --green: #0f8f5b;
  --green-deep: #0c7349;
  --red: #c43b3b;
  --shadow: 0 24px 60px rgba(23, 27, 34, 0.08);
  color-scheme: light;
  font-family: "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
}

* { box-sizing: border-box; border-radius: 0; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 0% -10%, #d7e4ff 0%, transparent 60%),
    radial-gradient(760px 380px at 100% 0%, #d8f3e6 0%, transparent 55%),
    var(--bg);
}

h1, h2, p { margin: 0; }

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

button {
  cursor: pointer;
  border: 0;
  padding: 12px 16px;
  background: var(--ink);
  color: #fff;
  font-weight: 600;
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

input, select {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid transparent;
  background: var(--field);
}

input:focus, select:focus {
  outline: 3px solid #d5e3ff;
  background: #fff;
  border-color: #c5d4f2;
}

.container {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 20px 56px;
}

.card {
  background: var(--card);
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 15px;
  letter-spacing: 0.02em;
  margin-bottom: 8px;
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.links a {
  color: var(--ink);
  text-decoration: none;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.72);
}

.links a[aria-current="page"] {
  background: var(--ink);
  color: #fff;
}

ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

li {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

li:last-child { border-bottom: 0; }

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo {
  display: block;
  height: 28px;
  width: auto;
}

.brand-name {
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.brand-sub {
  color: var(--muted);
  font-size: 13px;
}

.page-login {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--card);
  padding: 36px 32px 28px;
  box-shadow: var(--shadow);
}

.login-card .brand { margin-bottom: 28px; }

.login-card form {
  display: grid;
  gap: 14px;
}

.login-card label,
.devices label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.login-card button[type="submit"] {
  margin-top: 6px;
  padding: 14px 16px;
  background: var(--green);
}

.login-card button[type="submit"]:hover { background: var(--green-deep); }

.form-status {
  min-height: 1.2em;
  margin-top: 14px;
  color: var(--red);
  font-size: 14px;
}

.form-status:empty { display: none; }

.shell {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 22px 16px 48px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.topbar .links { margin-left: auto; }

.btn-quiet {
  background: rgba(255, 255, 255, 0.8);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
}

.dialer { padding: 26px; }

.dial-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.timer {
  font-size: 52px;
  font-weight: 650;
  letter-spacing: -0.05em;
  font-variant-numeric: tabular-nums;
  line-height: 0.95;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  max-width: 360px;
}

.status-strip p {
  margin: 0;
  padding: 6px 10px;
  background: var(--field);
  color: #4d5668;
  font-size: 12px;
}

.dial-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

#dial-number {
  font-size: 22px;
  letter-spacing: 0.02em;
  padding: 16px 18px;
}

.btn-call {
  background: var(--green);
  padding: 16px 22px;
  font-size: 16px;
}

.btn-call:hover { background: var(--green-deep); }

.btn-hangup {
  background: #fff5f5;
  color: var(--red);
  box-shadow: inset 0 0 0 1px #f3d0d0;
  padding: 16px 18px;
}

.call-state {
  border-left: 4px solid #69758a;
  background: var(--field);
  padding: 16px 18px;
  margin-bottom: 18px;
  color: #465065;
  line-height: 1.5;
}
.call-state-title { font-size: 20px; font-weight: 650; color: var(--ink); }
.call-state-peer { font-size: 18px; font-variant-numeric: tabular-nums; margin: 4px 0; overflow-wrap: anywhere; }
.call-state[data-phase="ready"] { border-color: var(--green); background: #f0f8f3; }
.call-state[data-phase="active"], .call-state[data-phase="incoming"] { border-color: var(--green); background: #e6f5ec; }
.call-state[data-phase="recovery"], .call-state[data-phase="dialing"] { border-color: #a9660b; background: #fff5e4; }
.call-state[data-phase="error"] { border-color: var(--red); background: #fff0f0; }
.call-state .btn-hangup {
  margin-top: 12px;
  background: var(--red);
  color: #fff;
}

.btn-resume {
  width: 100%;
  margin-top: 8px;
  background: #eef6ff;
  color: #1d4f91;
}

.btn-resume[hidden] { display: none; }

.tool-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}

.tool-row > button,
.dtmf button {
  background: var(--field);
  color: var(--ink);
}

#availability-controls {
  display: grid;
  grid-template-columns: minmax(0, 18rem) minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

#availability-controls label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

#availability-message {
  height: 3em;
  overflow: auto;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

#availability-controls.availability-alert label,
#availability-controls.availability-alert #availability-message {
  color: var(--red);
}

#availability-controls.availability-alert select {
  color: var(--red);
  -webkit-text-fill-color: var(--red);
  opacity: 1;
  background: #fff0f0;
  border: 1px solid var(--red);
  font-weight: 700;
}

#mute-btn.is-on {
  background: var(--ink);
  color: #fff;
}

[hidden] {
  display: none !important;
}

.dtmf {
  width: 100%;
}

.dtmf summary { cursor: pointer; padding: 8px 0; }
.page-supervisor #dial-number,
.page-supervisor #dial-btn,
.page-supervisor #echo-btn { display: none; }
.dtmf-keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 280px; margin: 8px 0; }
.dtmf-keypad button { font-size: 22px; background: var(--field); color: var(--ink); }

.dtmf input {
  width: 92px;
}

.devices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: start;
  gap: 12px;
  margin-top: 18px;
}

.sound-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.sound-hint {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.quality {
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}

.quality summary { cursor: pointer; }

.quality p { margin-top: 8px; }

.journal h2 { margin-bottom: 4px; }

#calls-list:empty::before {
  content: "Пока пусто";
  display: block;
  padding: 18px 0 6px;
  color: var(--muted);
}

.incoming-call {
  position: fixed;
  left: 50%;
  top: 20px;
  transform: translateX(-50%);
  z-index: 100;
  box-sizing: border-box;
  width: min(680px, calc(100% - 24px));
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(23, 27, 34, 0.18);
}

.incoming-call[hidden] { display: none; }

.incoming-icon {
  width: 52px;
  height: 52px;
  flex: none;
  background:
    radial-gradient(circle at 50% 58%, transparent 28%, #0f8f5b 29% 34%, transparent 35%),
    radial-gradient(circle at 50% 42%, #0f8f5b 18%, transparent 19%),
    #e8f7ef;
  animation: incoming-pulse 1.4s ease-in-out infinite;
}

.incoming-info { flex: 1; min-width: 0; }

.incoming-info p { margin: 2px 0; }

.incoming-label {
  color: var(--green-deep);
  font-size: 13px;
  font-weight: 700;
}

.incoming-caller {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.03em;
  overflow-wrap: anywhere;
}

#incoming-detail { color: var(--muted); font-size: 14px; }

.incoming-actions {
  display: flex;
  gap: 8px;
}

.answer-call {
  background: var(--green);
  color: #fff;
  padding: 14px 18px;
}

.reject-call {
  background: #fff5f5;
  color: var(--red);
  padding: 14px 18px;
}

.diagnostic {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto 32px;
}

.diagnostic[hidden] { display: none; }

#diagnostic-output {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin-top: 12px;
  padding: 12px;
  background: var(--field);
  font-size: 12px;
}

@keyframes incoming-pulse {
  50% { transform: scale(1.06); }
}

@media (prefers-reduced-motion: reduce) {
  .incoming-icon { animation: none; }
}

@media (max-width: 720px) {
  #availability-controls { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .topbar .links { margin-left: 0; order: 3; width: 100%; }
  .dial-head { flex-direction: column; }
  .status-strip { justify-content: flex-start; max-width: none; }
  .timer { font-size: 42px; }
  .dial-row,
  .tool-row,
  .devices { grid-template-columns: 1fr; }
  .incoming-call { flex-wrap: wrap; }
  .incoming-actions { width: 100%; }
  .incoming-actions button { flex: 1; }
}

.microphone-level {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 8px 0 0;
  padding: 8px 10px;
  background: var(--field);
  border-left: 3px solid var(--muted);
  font-size: 13px;
}
.microphone-level label { font-weight: 600; }
.microphone-level meter { width: 150px; height: 16px; accent-color: var(--green); }
.microphone-level meter::-webkit-meter-bar { background: var(--line); border: 0; }
.microphone-level meter::-webkit-meter-optimum-value { background: var(--green); }
.microphone-level meter::-moz-meter-bar { background: var(--green); }
.microphone-level[data-state="ready"] { border-color: var(--green); }
.microphone-level[data-state="silent"],
.microphone-level[data-state="error"],
.microphone-level[data-state="muted"] {
  border-color: #d49a00;
  background: #fff5cc;
  color: #735000;
}
.microphone-warning { display: none; font-size: 20px; line-height: 1; }
.microphone-level[data-state="silent"] .microphone-warning,
.microphone-level[data-state="error"] .microphone-warning,
.microphone-level[data-state="muted"] .microphone-warning { display: inline; }
.microphone-level button { padding: 6px 10px; font-size: 13px; }

.microphone-device { min-width: 0; }

.btn-audio-report {
  background: transparent;
  color: #a65b00;
  border: 1px solid #c57912;
}
.btn-audio-report:hover { background: #fff8ed; }
.btn-audio-report span { margin-right: 4px; font-size: 18px; }
