:root{
    --bg: #0a0a12;
    --panel: #14141f;
    --panel-2: #1b1b2a;
    --border: #26263a;
    --text: #e8e8f0;
    --text-dim: #8888a4;
    --pink: #ff2e88;
    --violet: #7c3aff;
    --cyan: #00e5ff;
    --grad: linear-gradient(120deg, var(--pink), var(--violet) 50%, var(--cyan));
    --danger: #ff4d5e;
    --ok: #35e6a0;
  }

  * { box-sizing: border-box; }

  body {
    margin: 0;
    background: radial-gradient(1200px 700px at 15% -10%, #1a1030 0%, transparent 60%),
                radial-gradient(1000px 600px at 110% 10%, #071b2e 0%, transparent 55%),
                var(--bg);
    color: var(--text);
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 28px 16px 60px;
  }

  h1, h2, .display {
    font-family: 'Space Grotesk', sans-serif;
    letter-spacing: -0.01em;
  }

  .app {
    width: 100%;
    max-width: 85vw;
  }

  .brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 22px;
  }

  .brand-mark {width:24px;height:34px;border-radius:20px;background:var(--grad);flex-shrink:0;}

  .brand h1 {
    font-size: 19px;
    font-weight: 600;
    margin: 0;
    background: var(--grad);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }

  .card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px;
    margin-bottom: 4px;
  }

  label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
    margin-bottom: 6px;
    font-weight: 500;
  }

  .row { display: flex; gap: 10px; }
  .row > div { flex: 1; }
  .row.align-end { align-items: end; }

  input[type=text] {
    width: 100%;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--text);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    outline: none;
    transition: border-color .15s;
  }
  input[type=text]:focus { border-color: var(--violet); }
  input[type=text]::placeholder { color: #55556a; }

  button {
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 13px;
    border: none;
    border-radius: 10px;
    padding: 10px 16px;
    cursor: pointer;
    transition: opacity .15s, transform .1s;
    white-space: nowrap;
  }
  button:active { transform: scale(0.97); }
  button:disabled { opacity: 0.35; cursor: not-allowed; }

  .btn-primary {
    background: var(--grad);
    color: #0a0a12;
  }
  .btn-primary:hover:not(:disabled) { opacity: 0.92; }

  .btn-ghost {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
  }
  .btn-ghost:hover:not(:disabled) { border-color: var(--violet); }

  .btn-danger {
    background: var(--danger);
    color: #1a0508;
  }

  .btn-icon {
    width: 44px; height: 44px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    padding: 0;
    font-size: 18px;
    flex-shrink: 0;
  }

  #status-line {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-dim);
    margin: 4px 2px 16px;
  }

  .dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--text-dim);
    flex-shrink: 0;
  }
  .dot.live {
    background: var(--ok);
    box-shadow: 0 0 8px var(--ok), 0 0 16px var(--ok);
  }
  .dot.pending {
    background: var(--cyan);
    box-shadow: 0 0 8px var(--cyan);
    animation: pulse 1.4s ease-in-out infinite;
  }
  @keyframes pulse { 50% { opacity: 0.35; } }

  /* --- Чат --- */
  #chat {
    height: 320px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-right: 4px;
  }
  #chat::-webkit-scrollbar { width: 6px; }
  #chat::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

  .msg {
    max-width: 78%;
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
  }
  .msg.me {
    align-self: flex-end;
    background: linear-gradient(120deg, rgba(255,46,136,0.22), rgba(124,58,255,0.22));
    border: 1px solid rgba(124,58,255,0.35);
    border-bottom-right-radius: 4px;
  }
  .msg.them {
    align-self: flex-start;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
  }
  .msg.sys {
    align-self: center;
    color: var(--text-dim);
    font-size: 12px;
    font-style: italic;
    background: none;
  }

  /* --- Файлы --- */
  .file-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
  }
  .file-icon {
    width: 36px; height: 36px;
    border-radius: 9px;
    background: var(--grad);
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px;
  }
  .file-meta { flex: 1; min-width: 0; }
  .file-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .file-size { font-size: 11px; color: var(--text-dim); }
  .file-progress-track {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin-top: 6px;
    overflow: hidden;
  }
  .file-progress-fill {
    height: 100%;
    background: var(--grad);
    width: 0%;
    transition: width .15s;
  }
  .file-link {
    color: var(--cyan);
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
  }

  /* --- Ввод --- */
  .composer {
    display: flex;
    gap: 8px;
    margin-top: 14px;
  }
  .composer input[type=text] { flex: 1; }

  /* --- Звонок --- */
  .call-bar {
    display: none;
    align-items: center;
    gap: 14px;
    background: linear-gradient(120deg, rgba(255,46,136,0.14), rgba(0,229,255,0.14));
    border: 1px solid var(--violet);
    border-radius: 14px;
    padding: 12px 16px;
    margin-bottom: 16px;
  }
  .call-bar.show { display: flex; }

  .call-ring {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--grad);
    flex-shrink: 0;
    position: relative;
  }
  .call-ring::before {
    content: '';
    position: absolute;
    inset: -5px;
    border-radius: 50%;
    border: 2px solid var(--cyan);
    animation: ring 1.6s ease-out infinite;
  }
  @keyframes ring {
    0% { transform: scale(0.9); opacity: 0.9; }
    100% { transform: scale(1.5); opacity: 0; }
  }

  .call-info { flex: 1; }
  .call-title { font-weight: 600; font-size: 14px; }
  .call-sub { font-size: 12px; color: var(--text-dim); }

  .call-bars {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 20px;
    width: 30px;
  }
  .call-bars span {
    width: 3px;
    background: var(--grad);
    border-radius: 2px;
    animation: bar 0.9s ease-in-out infinite;
  }
  .call-bars span:nth-child(1) { height: 30%; animation-delay: 0s; }
  .call-bars span:nth-child(2) { height: 70%; animation-delay: .15s; }
  .call-bars span:nth-child(3) { height: 45%; animation-delay: .3s; }
  .call-bars span:nth-child(4) { height: 90%; animation-delay: .45s; }
  .call-bars span:nth-child(5) { height: 55%; animation-delay: .6s; }
  @keyframes bar { 0%, 100% { transform: scaleY(0.4); } 50% { transform: scaleY(1); } }

  /* --- Видео --- */
  .video-stage {
    display: none;
    position: relative;
    background: #000;
    border-radius: 14px;
    overflow: hidden;
    margin-bottom: 12px;
    border: 1px solid var(--border);
  }
  .video-stage.show { display: block; }

  #remoteVideo {
    width: 100%;
    max-height: 360px;
    display: block;
    background: #050508;
    object-fit: contain;
  }

  #localVideo {
    position: absolute;
    bottom: 10px; right: 10px;
    width: 110px;
    border-radius: 10px;
    border: 2px solid transparent;
    background: linear-gradient(#0a0a12, #0a0a12) padding-box, var(--grad) border-box;
    box-shadow: 0 4px 18px rgba(0,0,0,0.5);
    object-fit: cover;
    transform: scaleX(-1); /* зеркалим камеру, но не при показе экрана — переключается классом */
  }
  #localVideo.no-mirror { transform: none; }

  .screen-badge {
    position: absolute;
    top: 10px; left: 10px;
    background: rgba(10,10,18,0.75);
    backdrop-filter: blur(6px);
    border: 1px solid var(--cyan);
    color: var(--cyan);
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    display: none;
    align-items: center;
    gap: 6px;
  }
  .screen-badge.show { display: flex; }
  .screen-badge .dot { background: var(--cyan); box-shadow: 0 0 6px var(--cyan); animation: pulse 1.4s ease-in-out infinite; }

  .call-controls-extra {
    display: flex;
    gap: 8px;
  }

  .btn-icon.active {
    background: var(--grad);
    color: #0a0a12;
  }

  .hidden { display: none !important; }

  #incomingCallToast {
    position: fixed;
    top: 20px; left: 50%;
    transform: translateX(-50%);
    background: var(--panel);
    border: 1px solid var(--violet);
    box-shadow: 0 0 0 1px rgba(124,58,255,0.2), 0 8px 30px rgba(124,58,255,0.25);
    border-radius: 14px;
    padding: 14px 16px;
    display: none;
    align-items: center;
    gap: 12px;
    z-index: 50;
  }
  #incomingCallToast.show { display: flex; }
