:root {
  --grad: linear-gradient(135deg, #ff60c0, #8050ff 48%, #50b0ff);
  --bg: #0b1020;
  --panel: #141a2e;
  --panel-2: #1b2238;
  --text: #f5f7fb;
  --muted: #9aa3b8;
  --line: rgba(255, 255, 255, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Demo backdrop (only shows on the standalone page) */
.page-bg {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 24px;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(128, 80, 255, 0.18), transparent),
    radial-gradient(1000px 500px at 0% 110%, rgba(80, 176, 255, 0.16), transparent),
    var(--bg);
}
.page-bg h1 { font-size: 34px; margin: 0; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.page-bg p { color: var(--muted); margin: 0; }

.hidden { display: none !important; }

/* ============ WIDGET ============ */
.widget {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 14px;
}

/* Launcher FAB */
.launcher {
  position: relative;
  width: 62px;
  height: 62px;
  border: none;
  border-radius: 50%;
  background: var(--grad);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 18px 40px -10px rgba(128, 80, 255, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
.launcher:hover { transform: translateY(-2px); box-shadow: 0 24px 50px -12px rgba(128, 80, 255, 0.85); }
.launcher--open { transform: scale(0.92); }
.launcher__icon { width: 26px; height: 26px; }
.launcher__pulse {
  position: absolute; inset: 0; border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(128, 80, 255, 0.55);
  animation: ring 2.2s infinite;
}
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(128,80,255,0.5); } 70% { box-shadow: 0 0 0 16px rgba(128,80,255,0); } 100% { box-shadow: 0 0 0 0 rgba(128,80,255,0); } }
.launcher__badge {
  position: absolute; top: -2px; right: -2px;
  min-width: 20px; height: 20px; padding: 0 5px;
  font-size: 11px; font-weight: 700; line-height: 20px;
  background: #ef4444; color: #fff; border-radius: 999px;
  border: 2px solid var(--bg);
}

/* Panel */
.panel {
  width: 360px;
  max-width: calc(100vw - 32px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 18px;
  box-shadow: 0 40px 90px -20px rgba(0, 0, 0, 0.75);
  transform-origin: bottom right;
  animation: pop 0.18s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(0.96); } to { opacity: 1; transform: none; } }

.panel__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.head__right { display: flex; align-items: center; gap: 8px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); }
.brand__dot { width: 14px; height: 14px; border-radius: 50%; background: var(--grad); box-shadow: 0 0 16px rgba(128, 80, 255, 0.6); }

.status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.status__dot { width: 9px; height: 9px; border-radius: 50%; background: #6b7280; transition: 0.3s; }
.status__dot[data-state='ready'] { background: #34d399; box-shadow: 0 0 10px #34d39988; }
.status__dot[data-state='ringing'] { background: #fbbf24; box-shadow: 0 0 10px #fbbf2488; animation: blink 1s infinite; }
.status__dot[data-state='incall'] { background: #60a5fa; box-shadow: 0 0 10px #60a5fa88; }
.status__dot[data-state='error'] { background: #f87171; box-shadow: 0 0 10px #f8717188; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

.iconbtn { background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); width: 28px; height: 28px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.iconbtn:hover { color: var(--text); }

/* Tabs */
.tabs { display: flex; gap: 6px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.tab { flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px; padding: 9px; font-size: 14px; font-weight: 600; color: var(--muted); background: transparent; border: none; border-radius: 9px; cursor: pointer; transition: 0.2s; }
.tab--active { background: var(--grad); color: #fff; }
.badge { min-width: 18px; padding: 1px 5px; font-size: 11px; font-weight: 700; color: #fff; background: #ef4444; border-radius: 999px; text-align: center; }

/* Incoming / Active */
.incoming, .active { background: var(--panel-2); border: 1px solid var(--line); border-radius: 18px; padding: 22px; text-align: center; margin-bottom: 16px; }
.incoming__label, .active__label { margin: 0; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.incoming__from, .active__peer { margin: 8px 0 18px; font-size: 22px; font-weight: 700; color: var(--text); }
.incoming__actions, .active__actions { display: flex; gap: 12px; justify-content: center; }
.incoming { animation: blink 1.4s infinite; }
.active__timer { margin: 0 0 18px; font-variant-numeric: tabular-nums; font-size: 28px; font-weight: 700; color: #60a5fa; }

/* Dialer */
.dialer__input { width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; color: var(--text); font-size: 22px; text-align: center; padding: 14px; margin-bottom: 16px; outline: none; }
.dialer__input:focus { border-color: rgba(128, 80, 255, 0.7); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.keypad button { padding: 15px 0; font-size: 20px; font-weight: 600; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; cursor: pointer; transition: 0.08s; }
.keypad button:hover { background: #232b45; }
.keypad button:active { transform: scale(0.94); }
.dialer__actions { display: flex; gap: 12px; align-items: center; }

/* Buttons */
.btn { flex: 1; padding: 14px; font-size: 16px; font-weight: 700; border: none; border-radius: 14px; cursor: pointer; color: #fff; transition: 0.08s; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--answer { background: linear-gradient(135deg, #22c55e, #16a34a); }
.btn--reject { background: linear-gradient(135deg, #f87171, #ef4444); }
.btn--ghost { background: var(--panel-2); border: 1px solid var(--line); flex: 0 0 auto; padding: 14px 18px; }
.btn--ghost.btn--active { background: var(--grad); }
#backspaceBtn { flex: 0 0 auto; font-size: 18px; }

/* Messages */
.messages { height: 280px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 4px; margin-bottom: 14px; }
.messages__empty { margin: auto; text-align: center; font-size: 13px; color: var(--muted); padding: 0 20px; }
.msg { max-width: 80%; padding: 9px 12px; border-radius: 14px; }
.msg__meta { font-size: 10px; color: var(--muted); margin-bottom: 3px; }
.msg__body { font-size: 14px; line-height: 1.35; word-break: break-word; color: var(--text); }
.msg--inbound { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg--outbound { align-self: flex-end; background: linear-gradient(135deg, #4f46e5, #7c3aed); border-bottom-right-radius: 4px; }

/* Composer */
.composer { display: flex; flex-direction: column; gap: 8px; }
.composer__to { width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; color: var(--text); font-size: 14px; padding: 11px 12px; outline: none; }
.composer__to:focus { border-color: rgba(128, 80, 255, 0.7); }
.composer__row { display: flex; gap: 8px; align-items: stretch; }
.composer__body { flex: 1; resize: none; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; color: var(--text); font-size: 14px; font-family: inherit; padding: 11px 12px; outline: none; }
.composer__body:focus { border-color: rgba(128, 80, 255, 0.7); }
.composer__send { flex: 0 0 auto; padding: 0 20px; }

/* ============ SETUP WIZARD ============ */
.setup { max-height: 60vh; overflow-y: auto; padding-right: 4px; }
.setup__top { display: flex; align-items: center; justify-content: space-between; }
.setup__title { margin: 0 0 4px; font-size: 18px; color: var(--text); }
.setup__sub { margin: 0 0 16px; font-size: 13px; color: var(--muted); line-height: 1.4; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field > span a { color: #8ab4ff; }
.hint-inline { color: #6b7280; font-weight: 400; }
.field input { width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; color: var(--text); font-size: 14px; padding: 10px 12px; outline: none; }
.field input:focus { border-color: rgba(128, 80, 255, 0.7); }
.setup__actions { display: flex; gap: 10px; margin-top: 6px; }
.setup__result { min-height: 18px; font-size: 13px; margin: 10px 0 0; }
.setup__result[data-state='ok'] { color: #34d399; }
.setup__result[data-state='err'] { color: #f87171; }

.hooks { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.hooks__title { margin: 0 0 4px; font-size: 13px; font-weight: 700; color: var(--text); }
.hooks__hint { margin: 0 0 12px; font-size: 12px; color: var(--muted); line-height: 1.4; }
.hook { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 11px; }
.hook > span { color: var(--muted); flex: 0 0 auto; width: 96px; }
.hook code { flex: 1; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.copy { flex: 0 0 auto; background: var(--grad); color: #fff; border: none; border-radius: 8px; padding: 7px 10px; font-size: 11px; font-weight: 600; cursor: pointer; }

/* Login */
.login { padding: 8px 4px 4px; }
.login__input { width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; color: var(--text); font-size: 15px; padding: 13px 14px; outline: none; }
.login__input:focus { border-color: rgba(128, 80, 255, 0.7); }
.login__btn { width: 100%; margin-top: 12px; }

/* Footer */
.panel__foot { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.foot__links { display: flex; gap: 14px; }
.link { background: none; border: none; color: #8ab4ff; cursor: pointer; font-size: 12px; }
.link:hover { text-decoration: underline; }

/* Debug line — shows the latest status/error so issues are visible */
.debug { margin-top: 10px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; line-height: 1.4; color: #fbbf24; word-break: break-word; min-height: 14px; }
