:root {
  --bg: #0b1020;
  --bg-2: #121a35;
  --card: #18213f;
  --card-2: #1e2950;
  --text: #eef2ff;
  --muted: #93a0c8;
  --accent: #4f7cff;
  --green: #22c55e;
  --red: #ef4444;
  --radius: 16px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: radial-gradient(1400px 900px at 50% -10%, #1a2550 0%, var(--bg) 60%);
  color: var(--text);
  min-height: 100dvh;
}

.app {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 18px 28px;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.3px;
}
.brand .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 12px var(--green);
}

.icon-btn {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--text);
  width: 42px;
  height: 42px;
  border-radius: 12px;
  font-size: 20px;
  cursor: pointer;
  transition: background 0.15s;
}
.icon-btn:hover {
  background: var(--card-2);
}

.screen {
  display: none;
}
.screen.active {
  display: grid;
}

/* ---- СЕТКА 3 КОЛОНКИ ---- */
.workspace {
  grid-template-columns: 300px minmax(300px, 380px) 1fr;
  gap: 18px;
  align-items: start;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  padding: 16px;
}

.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 14px;
}

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
}
.badge-off {
  background: rgba(147, 160, 200, 0.15);
  color: var(--muted);
}
.badge-on {
  background: rgba(34, 197, 94, 0.16);
  color: #86efac;
}
.badge-rec {
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
}

/* ---- ЛЕВО: ТЕЛЕФОН ---- */
.phone-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.phone-ico {
  font-size: 30px;
  filter: grayscale(0.2);
}
.phone-info {
  flex: 1;
  min-width: 0;
}
.phone-sub {
  color: var(--muted);
  font-size: 11px;
  margin-top: 4px;
}
.phone-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.line-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.line-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-2);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 10px 12px;
}
.line-row.active {
  border-color: var(--green);
}
.line-row .l-name {
  font-weight: 600;
  font-size: 14px;
}
.line-row .l-sub {
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
}
.line-row button {
  flex: none;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.line-row button.disc {
  background: var(--red);
}
.rec-toggle-row {
  margin-bottom: 12px;
}
.rec-toggle-row label {
  font-size: 14px;
}

.field-sm {
  margin-bottom: 12px;
}
.field-sm label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.mini-input {
  width: 100%;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 14px;
  outline: none;
}
.mini-input:focus {
  border-color: var(--accent);
}

/* ---- ЛЕВО: ЗАПИСЬ ---- */
.rec-live {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}
.rec-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #64748b;
  flex: none;
}
.rec-dot.live {
  background: var(--red);
  animation: blink 1s infinite;
}
@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.25;
  }
}

.rec-meter {
  height: 10px;
  background: var(--bg-2);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 14px;
}
.rec-meter-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), #f59e0b, var(--red));
  transition: width 0.06s linear;
}

.last-rec-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}
.last-rec audio {
  width: 100%;
}

/* ---- ЦЕНТР: ЗВОНИЛКА ---- */
.dialer-col {
  display: flex;
  justify-content: center;
}
.dialer-card {
  width: 100%;
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 22px;
  padding: 18px;
}

.display {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-2);
  border-radius: 14px;
  padding: 8px 12px;
  margin-bottom: 10px;
}
.number {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 1px;
  min-width: 0;
}
.number::placeholder {
  color: var(--muted);
  font-weight: 400;
  font-size: 18px;
}
.backspace {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
  padding: 6px 8px;
}
.backspace:active {
  color: var(--text);
}

.call-status {
  text-align: center;
  padding: 4px 0 8px;
}
.call-status .call-name {
  color: var(--muted);
  font-size: 13px;
}
.call-status .call-target {
  font-size: 22px;
  font-weight: 700;
  margin-top: 2px;
}
.call-status .call-timer {
  color: var(--green);
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
  font-size: 15px;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.key {
  aspect-ratio: 1.7 / 1;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 14px;
  background: linear-gradient(180deg, var(--card-2), var(--card));
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 0.05s, background 0.15s;
}
.key span {
  font-size: 23px;
  font-weight: 600;
  line-height: 1;
}
.key small {
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 1px;
  margin-top: 3px;
}
.key:active {
  transform: scale(0.94);
  background: var(--accent);
}

.call-actions {
  display: flex;
  justify-content: center;
  gap: 36px;
}
.call-btn,
.hangup-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.08s;
}
.call-btn {
  background: var(--green);
  box-shadow: 0 8px 22px rgba(34, 197, 94, 0.4);
}
.hangup-btn {
  background: var(--red);
  box-shadow: 0 8px 22px rgba(239, 68, 68, 0.4);
}
.call-btn:active,
.hangup-btn:active {
  transform: scale(0.92);
}
.hangup-btn.in-call {
  animation: pulse 1.4s infinite;
}
@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 8px 22px rgba(239, 68, 68, 0.4);
  }
  50% {
    box-shadow: 0 8px 32px rgba(239, 68, 68, 0.85);
  }
}

/* ---- ПРАВО: ИСТОРИЯ ---- */
.history-card {
  display: flex;
  flex-direction: column;
  min-height: 320px;
}
.hist-actions {
  display: flex;
  gap: 6px;
}
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  max-height: 62vh;
}
.hist-item {
  background: var(--bg-2);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.hist-main {
  min-width: 0;
  flex: 1;
}
.hist-num {
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hist-num:hover {
  color: var(--accent);
}
.hist-meta {
  color: var(--muted);
  font-size: 11px;
  margin-top: 3px;
}
.hist-side {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
}
.hist-dur {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.hist-norec {
  font-size: 10px;
  color: #64748b;
}
.dl-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s;
}
.dl-btn:hover {
  filter: brightness(1.08);
}
.dl-btn:active {
  filter: brightness(0.9);
}

/* ---- НАСТРОЙКИ ---- */
.settings-screen {
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
}
.settings-screen.active {
  display: block;
}
.section-title {
  font-size: 18px;
  margin: 8px 0 14px;
}
.field {
  margin-bottom: 16px;
}
.field label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}
.field select {
  width: 100%;
  background: var(--card);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
}
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.toggle-row label {
  margin: 0;
  color: var(--text);
  font-size: 15px;
}
.toggle-row input[type="checkbox"] {
  width: 46px;
  height: 26px;
  appearance: none;
  background: var(--card-2);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  flex: none;
}
.toggle-row input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.toggle-row input[type="checkbox"]:checked {
  background: var(--green);
}
.toggle-row input[type="checkbox"]:checked::after {
  transform: translateX(20px);
}

.mic-test-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-weight: 600;
}
.meter {
  height: 14px;
  background: var(--bg-2);
  border-radius: 999px;
  overflow: hidden;
}
.meter-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), #a3e635, #f59e0b, var(--red));
  transition: width 0.06s linear;
}
.record-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}
.record-row audio {
  width: 100%;
}

.ghost-btn {
  background: var(--card-2);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 9px 13px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.ghost-btn:hover {
  background: #26326a;
}
.ghost-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.ghost-btn.wide {
  width: 100%;
  margin-top: 18px;
  padding: 14px;
}
.ghost-btn.tiny {
  padding: 5px 9px;
  font-size: 12px;
  border-radius: 8px;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  margin: 8px 0 0;
  line-height: 1.4;
}
.perm-hint {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fecaca;
  padding: 12px 14px;
  border-radius: 12px;
  margin-top: 16px;
  font-size: 13px;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: #000c;
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 50;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(6px);
  max-width: 90vw;
  text-align: center;
}

/* ---- АДАПТИВ ---- */
@media (max-width: 940px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .dialer-col {
    order: -1;
  }
  .dialer-card {
    max-width: 440px;
    margin: 0 auto;
  }
  .side {
    flex-direction: column;
  }
  .history-list {
    max-height: none;
  }
}
