.sp-phone {
  --sp-w: 340px;
  position: fixed;
  z-index: 8010;
  width: var(--sp-w);
  left: calc(var(--sidebar-w) + 16px);
  top: 72px;
  display: none;
  flex-direction: column;
  background: var(--bg-sidebar);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  user-select: none;
  animation: sp-rise .2s ease both;
  max-height: calc(100dvh - 24px);
}
.sp-phone.is-open { display: flex; }
.sp-phone.is-pinned { box-shadow: var(--shadow), 0 0 0 1px rgba(106,179,243,0.35); }
.sp-phone.is-dragging { opacity: .96; cursor: grabbing; }
.sp-phone.is-compact { --sp-w: 300px; }
.sp-phone.is-mini {
  --sp-w: auto;
  width: auto;
  min-width: 268px;
  max-width: min(420px, calc(100vw - 24px));
  border-radius: 14px;
  max-height: none;
}
.sp-phone.is-compact .sp-pad,
.sp-phone.is-compact .sp-fav-row,
.sp-phone.is-compact .sp-account { display: none !important; }
.sp-phone.is-compact .sp-incall { grid-template-columns: repeat(4, 1fr); }
.sp-phone.is-compact .sp-body {
  padding: 12px 14px 14px;
  gap: 8px;
}
.sp-phone.is-mini .sp-head {
  padding: 8px 10px;
  border-bottom: none;
  gap: 8px;
  align-items: center;
}
.sp-phone.is-mini .sp-head-text,
.sp-phone.is-mini #sp-settings-btn { display: none !important; }
.sp-phone.is-mini .sp-status-dot { display: none; }
.sp-phone.is-mini .sp-body,
.sp-phone.is-mini .sp-settings { display: none !important; }
.sp-phone.is-mini .sp-mini-bar {
  display: flex;
  flex: 1;
  min-width: 0;
  align-items: center;
  gap: 8px;
}
.sp-phone.is-settings.is-mini {
  --sp-w: 340px;
  width: var(--sp-w);
  min-width: var(--sp-w);
}
.sp-phone.is-settings.is-mini .sp-mini-bar { display: none !important; }
.sp-phone.is-settings.is-mini .sp-head-text { display: block !important; }
.sp-phone.is-settings.is-mini .sp-settings { display: flex !important; }
.sp-phone.is-settings.is-mini #sp-settings-btn { display: grid !important; }

.sp-sip-log-wrap {
  width: 100%;
  max-width: 292px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0,0,0,0.22);
  overflow: hidden;
}
.sp-sip-log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.sp-sip-log {
  max-height: 110px;
  overflow-y: auto;
  padding: 6px 8px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .68rem;
  line-height: 1.35;
  text-align: left;
}
.sp-sip-line { color: var(--muted); margin: 0 0 3px; word-break: break-word; }
.sp-sip-line.is-ok { color: #7dcf7c; }
.sp-sip-line.is-err { color: #ff8a80; }
.sp-sip-line.is-sip { color: #9ec9ef; }
.sp-phone.is-compact .sp-sip-log { max-height: 72px; }
.sp-phone.is-mini .sp-sip-log-wrap { display: none; }
@keyframes sp-rise {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.sp-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 10px 14px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--line);
  cursor: grab;
  touch-action: none;
  flex-shrink: 0;
}
.sp-phone.is-mini .sp-head {
  padding: 8px 10px;
  border-bottom: none;
  gap: 10px;
}
.sp-phone.is-dragging .sp-head { cursor: grabbing; }
.sp-head-text { flex: 1; min-width: 0; }
.sp-head-text strong {
  display: block;
  font-size: .92rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.sp-head-text span {
  display: block;
  font-size: .72rem;
  color: var(--muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sp-phone.is-mini .sp-head-text { display: none; }
.sp-phone.is-mini .sp-settings-btn,
.sp-phone.is-mini #sp-settings-btn { display: none; }

.sp-status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #7f8b99;
  box-shadow: 0 0 0 3px rgba(127,139,153,0.2);
  flex-shrink: 0;
}
.sp-status-dot.is-ok { background: #4fae4e; box-shadow: 0 0 0 3px rgba(79,174,78,0.2); }
.sp-status-dot.is-offline { background: #e53935; box-shadow: 0 0 0 3px rgba(229,57,53,0.2); }
.sp-status-dot.is-ring { background: #ffd54f; box-shadow: 0 0 0 3px rgba(255,213,79,0.25); animation: sp-pulse 1s ease-in-out infinite; }
.sp-head-actions { display: flex; gap: 2px; flex-shrink: 0; }
.sp-ico {
  width: 34px; height: 34px; border: none; border-radius: 10px;
  background: transparent; color: var(--muted);
  display: grid; place-items: center; cursor: pointer;
}
.sp-phone.is-mini .sp-ico { width: 30px; height: 30px; }
.sp-ico:hover { color: var(--ink); background: var(--bg-hover); }
.sp-ico.is-on { color: var(--accent-2); background: rgba(82,136,193,0.22); }
.sp-ico:disabled { opacity: .35; cursor: default; }
.sp-ico .ui-ico { width: 16px; height: 16px; }

/* QoS bars */
.sp-qos {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
  padding: 0 2px;
  flex-shrink: 0;
}
.sp-qos i {
  display: block;
  width: 3px;
  border-radius: 1px;
  background: rgba(255,255,255,0.15);
  transition: background .2s ease, height .2s ease;
}
.sp-qos i:nth-child(1) { height: 4px; }
.sp-qos i:nth-child(2) { height: 7px; }
.sp-qos i:nth-child(3) { height: 10px; }
.sp-qos i:nth-child(4) { height: 14px; }
.sp-qos[data-level="1"] i:nth-child(-n+1),
.sp-qos[data-level="2"] i:nth-child(-n+2),
.sp-qos[data-level="3"] i:nth-child(-n+3),
.sp-qos[data-level="4"] i:nth-child(-n+4) { background: currentColor; }
.sp-qos[data-level="0"] { color: #7f8b99; }
.sp-qos[data-level="1"] { color: #e53935; }
.sp-qos[data-level="2"] { color: #ffd54f; }
.sp-qos[data-level="3"] { color: #6ab3f3; }
.sp-qos[data-level="4"] { color: #4fae4e; }
.sp-qos-label {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .68rem;
  color: var(--muted);
  min-width: 3.2em;
  font-variant-numeric: tabular-nums;
}

/* Mini strip (visible only in mini layout) */
.sp-mini-bar {
  display: none;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.sp-phone.is-mini .sp-mini-bar { display: flex; }
.sp-mini-timer {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-weight: 800;
  font-size: .95rem;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
  min-width: 3.2em;
}
.sp-mini-levels {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 56px;
}
.sp-mini-level {
  display: grid;
  grid-template-columns: 12px 1fr;
  align-items: center;
  gap: 4px;
}
.sp-mini-level .ui-ico { width: 11px; height: 11px; color: var(--muted); }
.sp-mini-level .bar {
  height: 4px;
  border-radius: 999px;
  background: rgba(255,255,255,0.1);
  overflow: hidden;
}
.sp-mini-level .bar > i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4fae4e, #6ab3f3);
  border-radius: inherit;
}
.sp-mini-hang {
  width: 30px; height: 30px; border: none; border-radius: 50%;
  background: #e53935; color: #fff;
  display: grid; place-items: center; cursor: pointer; flex-shrink: 0;
}
.sp-mini-hang:disabled { opacity: .35; cursor: default; }
.sp-mini-hang .ui-ico { width: 14px; height: 14px; }

.sp-body {
  padding: 14px 16px 16px;
  display: grid;
  gap: 10px;
  overflow-y: auto;
  min-height: 0;
  justify-items: center;
  align-content: start;
}
.sp-body > * {
  width: 100%;
  max-width: 292px;
  box-sizing: border-box;
}

.sp-account {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 10px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--line);
  font-size: .78rem; color: var(--muted);
}
.sp-account strong { color: var(--ink); font-weight: 700; }
.sp-account code {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .7rem; color: var(--accent-2); margin-left: auto;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 42%;
}

.sp-qos-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--line);
  font-size: .78rem;
  color: var(--muted);
}
.sp-qos-row strong { color: var(--ink); font-weight: 700; }

.sp-timer-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; font-size: .78rem; color: var(--muted);
}
.sp-timer {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-weight: 700; color: var(--accent-2); font-size: .95rem;
}

.sp-number-wrap {
  display: flex; align-items: center; gap: 4px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 14px; padding: 4px 6px 4px 12px;
}
.sp-number-wrap:focus-within { border-color: rgba(82,136,193,0.55); }
.sp-number {
  flex: 1; min-width: 0; border: none; background: transparent; outline: none;
  color: var(--ink); font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 1.2rem; font-weight: 600; letter-spacing: .04em; padding: 10px 0;
}
.sp-number::placeholder {
  color: var(--muted); font-weight: 500; letter-spacing: 0;
  font-family: var(--font); font-size: .92rem;
}

.sp-fav-row {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.sp-fav-chip {
  border: 1px solid var(--line); background: rgba(255,255,255,0.04);
  color: var(--ink); border-radius: 999px; padding: 5px 10px;
  display: inline-flex; flex-direction: column; align-items: flex-start;
  cursor: pointer; max-width: 140px; text-align: left;
}
.sp-fav-chip:hover { border-color: rgba(106,179,243,0.45); background: rgba(82,136,193,0.12); }
.sp-fav-chip b { font-size: .72rem; font-weight: 700; }
.sp-fav-chip small { font-size: .65rem; color: var(--muted); font-family: "IBM Plex Mono", monospace; }

.sp-pad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px;
}
.sp-key {
  border: none; border-radius: 14px; background: rgba(255,255,255,0.04);
  color: var(--ink); padding: 11px 6px 9px;
  display: grid; gap: 1px; place-items: center; cursor: pointer;
  transition: background .12s ease, transform .08s ease; min-height: 50px;
}
.sp-key:hover { background: var(--bg-hover); }
.sp-key:active { transform: scale(.96); background: var(--bg-active); }
.sp-key b {
  font-size: 1.2rem; font-weight: 700;
  font-family: "IBM Plex Mono", ui-monospace, monospace; line-height: 1;
}
.sp-key i {
  font-style: normal; font-size: .6rem; color: var(--muted);
  letter-spacing: .08em; font-weight: 600; min-height: .75em;
}
.sp-phone.is-incall .sp-key {
  background: rgba(82,136,193,0.12);
}

.sp-call-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sp-call-btn {
  border: none; border-radius: 14px; padding: 11px 10px;
  font-weight: 800; font-size: .86rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer; color: #fff;
}
.sp-call-btn .ui-ico { width: 18px; height: 18px; }
.sp-call-btn.call { background: #4fae4e; }
.sp-call-btn.call:hover { filter: brightness(1.08); }
.sp-call-btn.hang { background: #e53935; }
.sp-call-btn.hang:hover { filter: brightness(1.08); }
.sp-call-btn.answer { background: #2b5278; grid-column: 1 / -1; }
.sp-call-btn:disabled { opacity: .4; cursor: default; filter: none; }

.sp-incall {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
}
.sp-incall[hidden] { display: none !important; }
.sp-tool {
  border: 1px solid var(--line); background: rgba(255,255,255,0.04);
  color: var(--ink); border-radius: 12px; padding: 8px 4px;
  display: grid; gap: 3px; place-items: center; cursor: pointer;
  font-size: .65rem; font-weight: 700;
}
.sp-tool .ui-ico { width: 16px; height: 16px; color: var(--muted); }
.sp-tool:hover { background: var(--bg-hover); }
.sp-tool.is-on { background: rgba(82,136,193,0.22); color: var(--accent-2); border-color: rgba(106,179,243,0.4); }
.sp-tool.is-on .ui-ico { color: var(--accent-2); }
.sp-tool:disabled { opacity: .35; cursor: default; }

.sp-levels { display: grid; gap: 10px; }
.sp-level {
  display: grid; grid-template-columns: 22px 1fr 42px;
  align-items: center; gap: 8px;
}
.sp-level .ui-ico { width: 16px; height: 16px; color: var(--muted); }
.sp-level input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px;
  border-radius: 999px; background: rgba(255,255,255,0.08); outline: none; cursor: pointer;
}
.sp-level input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent-2); border: none;
  box-shadow: 0 0 0 3px rgba(82,136,193,0.25);
}
.sp-meter {
  height: 6px; border-radius: 999px; background: rgba(255,255,255,0.08);
  overflow: hidden; grid-column: 2 / 4; margin-top: -2px;
}
.sp-meter > i {
  display: block; height: 100%; width: 0%; border-radius: inherit;
  background: linear-gradient(90deg, #4fae4e, #6ab3f3);
  transition: width .1s linear;
}
.sp-level-val {
  font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums;
  text-align: right; font-family: "IBM Plex Mono", ui-monospace, monospace;
}

.sp-toast {
  position: absolute; left: 12px; right: 12px; bottom: 12px;
  padding: 10px 12px; border-radius: 12px;
  background: rgba(33,43,54,0.96); border: 1px solid var(--line);
  color: var(--ink); font-size: .82rem; font-weight: 600;
  opacity: 0; pointer-events: none; transform: translateY(6px);
  transition: opacity .18s ease, transform .18s ease; z-index: 5;
}
.sp-toast.is-show { opacity: 1; transform: none; }

.sp-settings {
  display: none; flex-direction: column;
  max-height: min(560px, 70vh);
  border-top: 1px solid var(--line); background: var(--bg);
  min-height: 0;
}
.sp-phone.is-settings .sp-body { display: none; }
.sp-phone.is-settings .sp-settings { display: flex; }
.sp-set-tabs {
  display: flex; gap: 4px; padding: 10px 10px 0;
  flex-shrink: 0; overflow-x: auto;
}
.sp-set-tab {
  flex: 1; min-width: 0; border: none; background: transparent;
  color: var(--muted); border-radius: 10px; padding: 8px 6px;
  font-size: .7rem; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.sp-set-tab.active { background: var(--bg-active); color: var(--ink); }
.sp-set-scroll {
  flex: 1; overflow-y: auto; padding: 10px 12px 14px;
  display: grid; gap: 12px; min-height: 0;
}
.sp-set-block h4 {
  margin: 0 0 8px; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted);
}
.sp-features {
  margin: 0; padding-left: 18px; color: var(--muted);
  font-size: .78rem; line-height: 1.45;
}
.sp-features li { margin: 2px 0; }
.sp-features strong { color: var(--ink); font-weight: 700; }

.sp-acc-list { display: grid; gap: 6px; }
.sp-acc-item {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-sidebar); cursor: pointer; text-align: left;
  color: inherit; width: 100%; position: relative;
}
.sp-acc-item:hover { background: var(--bg-hover); }
.sp-acc-item.is-active {
  border-color: rgba(106,179,243,0.45);
  background: rgba(82,136,193,0.14);
}
.sp-acc-item .av {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center; background: #2b5278;
  color: #fff; font-weight: 800; font-size: .75rem; flex-shrink: 0;
}
.sp-acc-item .meta { flex: 1; min-width: 0; display: grid; gap: 2px; }
.sp-acc-item .meta strong {
  font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sp-acc-item .meta small {
  color: var(--muted); font-size: .7rem;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sp-acc-item .check { color: var(--accent-2); opacity: 0; font-weight: 800; }
.sp-acc-item.is-active .check { opacity: 1; }
.sp-acc-del {
  border: none; background: transparent; color: var(--muted);
  width: 28px; height: 28px; border-radius: 8px; cursor: pointer; font-size: 1.1rem;
}
.sp-acc-del:hover { background: rgba(229,57,53,0.15); color: #ff8a80; }

.sp-form { display: grid; gap: 8px; }
.sp-form .field { margin: 0; }
.sp-form .field label { font-size: .72rem; }
.sp-form .field input,
.sp-form .field select {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; background: var(--bg-sidebar); outline: none; color: var(--ink);
}
.sp-form .field input:focus,
.sp-form .field select:focus { border-color: var(--accent); }
.sp-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sp-hint { margin: 0; font-size: .75rem; color: var(--muted); line-height: 1.4; }

.sp-hist-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 1px solid var(--line); background: var(--bg-sidebar);
  border-radius: 10px; padding: 8px 10px; color: inherit; cursor: pointer; text-align: left;
}
.sp-hist-item:hover { background: var(--bg-hover); }
.sp-hist-item .dir { color: var(--accent-2); font-weight: 800; width: 16px; }
.sp-hist-item .meta { display: grid; gap: 2px; min-width: 0; }
.sp-hist-item strong { font-size: .86rem; }
.sp-hist-item small { color: var(--muted); font-size: .7rem; }

.sp-codec-list { display: grid; gap: 4px; }
.sp-codec {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-sidebar); font-size: .84rem; cursor: default;
}
.sp-codec code {
  margin-left: auto; font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: .7rem; color: var(--muted);
}
.sp-toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-sidebar); font-size: .86rem;
}
.sp-toggle-row small { display: block; color: var(--muted); font-size: .72rem; margin-top: 2px; }
.sp-switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.sp-switch input { opacity: 0; width: 0; height: 0; }
.sp-switch span {
  position: absolute; inset: 0; border-radius: 999px;
  background: rgba(255,255,255,0.12); cursor: pointer; transition: background .15s ease;
}
.sp-switch span::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; top: 3px; left: 3px; transition: transform .15s ease;
}
.sp-switch input:checked + span { background: var(--accent); }
.sp-switch input:checked + span::after { transform: translateX(18px); }

@media (max-width: 720px) {
  .sp-phone {
    --sp-w: calc(100vw - 24px);
    left: 12px; right: 12px; top: auto; bottom: 12px;
  }
}

/* —— Docked in main app (phone tab) —— */
.sp-phone.is-docked {
  --sp-w: min(420px, 100%);
  position: relative;
  left: auto;
  top: auto;
  right: auto;
  bottom: auto;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  max-height: none;
  height: 100%;
  border-radius: 0;
  border: 0;
  box-shadow: none;
  display: none !important;
  z-index: 1;
  animation: none;
}
html.is-phone-tab .sp-phone.is-docked {
  display: flex !important;
}
.sp-phone.is-docked .sp-head {
  cursor: default;
}
.sp-phone.is-docked #sp-close,
.sp-phone.is-docked #sp-pin {
  display: none !important;
}
.phone-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  background: var(--bg-chat);
}
.phone-panel-host {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.layout.show-phone .main {
  background: var(--bg-chat);
}
@media (max-width: 720px) {
  .sp-phone.is-docked {
    max-width: none;
    width: 100%;
  }
}
