/* style.css — phone-style contacts + call UI + add.html manager. */

:root {
  --bg: #0f1115;
  --bg-2: #161a21;
  --card: #1c212b;
  --border: #262d3a;
  --text: #eef1f6;
  --muted: #8b93a7;
  --accent: #34d399;
  --accent-dim: #1f9d6f;
  --danger: #ef4444;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

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

body {
  background: radial-gradient(120% 120% at 50% 0%, var(--bg-2) 0%, var(--bg) 60%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

/* ---------- error banner ---------- */
#error-banner {
  position: fixed;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 92vw;
  background: #3a1416;
  color: #fca5a5;
  border: 1px solid #7f1d1d;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
}
#error-banner button {
  background: none;
  border: none;
  color: inherit;
  font-size: 16px;
  padding: 0;
}

/* ---------- token overlay ---------- */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
}
.overlay-card {
  width: min(420px, 90vw);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
}
.overlay-card h1 {
  margin: 0 0 16px;
  font-size: 22px;
}
.token-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}
.token-row label {
  font-size: 12px;
  color: var(--muted);
  text-align: left;
}
.token-row input,
input[type="text"],
input[type="email"],
input[type="password"],
input:not([type]),
select,
textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  width: 100%;
}
.token-row button,
.primary {
  background: var(--accent);
  color: #06231a;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
}
.hint {
  color: var(--muted);
  font-size: 13px;
}

/* ---------- shared top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 10px;
}
.topbar h1 {
  margin: 0;
  font-size: 22px;
}
.manage-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 20px;
}

/* ---------- contacts list ---------- */
.view {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 520px;
  margin: 0 auto;
}
.contact-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 140px;
}
.contact-row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 4px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
}
.contact-row.selected {
  background: var(--card);
  border-color: var(--accent-dim);
}
.contact-row:active {
  background: var(--bg-2);
}
.contact-text {
  flex: 1;
  min-width: 0;
}
.contact-name {
  font-size: 16px;
  font-weight: 600;
}
.contact-sub {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.contact-reset {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
}
.contact-reset:active {
  color: #fca5a5;
  border-color: #7f1d1d;
  background: #3a1416;
}

/* --- avatars --- */
.avatar,
.contact-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.avatar-img,
.contact-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.avatar-ph {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  color: #fff;
  font-weight: 700;
  font-size: 20px;
}

/* ---------- empty state ---------- */
.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}
.empty p {
  margin: 0;
}

/* ---------- bottom call bar ---------- */
.callbar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  padding: 12px 18px calc(18px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 40%);
}
.selected-label {
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
}
.selected-label[data-empty="true"] {
  color: var(--muted);
}
.call-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #06231a;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(52, 211, 153, 0.4);
  transition: transform 0.08s ease, box-shadow 0.2s ease;
}
.call-btn:active {
  transform: scale(0.94);
}
.call-btn:disabled {
  background: var(--bg-2);
  color: var(--muted);
  box-shadow: none;
  cursor: not-allowed;
}

/* ---------- call screen ---------- */
#call-view {
  align-items: center;
  padding-top: 8vh;
  text-align: center;
}
.call-timer {
  font-size: 18px;
  letter-spacing: 1px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-bottom: 28px;
}
.call-avatar,
.avatar-lg {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  box-shadow: 0 0 0 6px var(--bg-2), 0 12px 40px rgba(0, 0, 0, 0.5);
}
.avatar-lg .avatar-img,
.call-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.avatar-lg.avatar-ph,
.call-avatar.avatar-ph {
  font-size: 54px;
}
.call-name {
  margin-top: 20px;
  font-size: 24px;
  font-weight: 700;
}
.call-sub {
  margin-top: 4px;
  font-size: 14px;
  color: var(--muted);
}
.call-status {
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
}
.call-status[data-state="thinking"] {
  color: #fbbf24;
}
.call-status[data-state="speaking"] {
  color: var(--accent);
}

.call-controls {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
  padding: 28px 18px calc(24px + env(safe-area-inset-bottom));
}
.round-btn {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  background: var(--card);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}
.round-btn[data-muted="true"] {
  background: #3a1416;
  color: #fca5a5;
}
.round-btn[data-on="true"] {
  background: #f2f4f8;
  color: #10141c;
}
.round-btn[data-on="false"] {
  color: var(--muted);
}
.round-btn[data-on="false"] .hi,
.round-btn[data-on="false"] .hi2 {
  opacity: 0;
  transition: opacity 0.15s;
}
.end-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(239, 68, 68, 0.4);
}
.end-btn:active,
.round-btn:active {
  transform: scale(0.94);
}

/* ---------- add.html: tabs + cards ---------- */
.tabs {
  display: flex;
  gap: 8px;
  padding: 6px 18px 12px;
}
.tab {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 12px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
}
.tab.active {
  background: var(--card);
  color: var(--text);
  border-color: var(--accent-dim);
}

.container {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 14px 60px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 {
  margin: 0 0 12px;
  font-size: 16px;
}
.card label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 12px 0 6px;
}
.card .btn-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.btn {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
}
.btn.danger {
  background: #3a1416;
  border-color: #7f1d1d;
  color: #fca5a5;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* avatar picker */
.avatar-picker {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}
#avatar-preview {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
}
#avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
#avatar-preview .avatar-ph {
  width: 100%;
  height: 100%;
  font-size: 26px;
}

/* manage list */
.manage-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.manage-row:last-child {
  border-bottom: none;
}
.manage-info {
  flex: 1;
  min-width: 0;
}
.manage-name {
  font-weight: 600;
  font-size: 15px;
}
.manage-sub {
  font-size: 12px;
  color: var(--muted);
}
.manage-actions {
  display: flex;
  gap: 6px;
}
.manage-actions .btn {
  padding: 6px 10px;
  font-size: 12px;
}

/* drag to reorder (SortableJS) */
.drag-handle {
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  padding: 8px 6px;
  margin: -4px 0;
  flex: none;
  touch-action: none; /* keep drag gestures flowing instead of scrolling */
}
.drag-handle:active {
  cursor: grabbing;
}
.manage-row.s-chosen {
  opacity: 0.5;
}
.manage-row.s-ghost {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
  border-radius: 10px;
}
.manage-row.s-drag {
  background: var(--bg);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4);
  border-radius: 10px;
  z-index: 2;
}

/* small sliders */
.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.slider-row label {
  margin: 0;
  flex: 1;
}
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.slider-val {
  font-variant-numeric: tabular-nums;
  min-width: 48px;
  text-align: right;
  color: var(--accent);
  font-weight: 600;
}

#token-warn {
  margin: 0 auto 8px;
  max-width: 520px;
  background: #3a2a0e;
  border: 1px solid #7c5a1d;
  color: #fcd34d;
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
#token-warn input {
  flex: 1;
  min-width: 160px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 10px;
}

/* ---------- account system (auth + account pages) ---------- */
#auth-view {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(120% 120% at 50% 0%, var(--bg-2) 0%, var(--bg) 60%);
}
.auth-card {
  width: min(420px, 92vw);
  max-height: 92dvh;
  overflow-y: auto;
  text-align: left;
}
.login-logo {
  display: block;
  width: 100%;
  margin: 0 auto 14px;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}
.auth-brand h1 {
  margin: 0;
  font-size: 19px;
}
.auth-logo {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #06231a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 17px;
  flex: 0 0 auto;
}
.auth-form label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0 4px;
}
.auth-title {
  margin: 0 0 6px;
  font-size: 18px;
}
.auth-btn {
  width: 100%;
  margin-top: 14px;
}
.auth-links {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
}
.auth-links a {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}
.auth-error {
  color: #fca5a5;
  background: #3a1416;
  border: 1px solid #7f1d1d;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  margin: 12px 0 0;
}
.auth-note {
  color: var(--accent);
  font-size: 13px;
  margin: 12px 0 0;
}
.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  border-radius: 12px;
  padding: 3px 9px;
}
.badge.status-active {
  color: var(--accent);
  border-color: var(--accent-dim);
}
.badge.status-pending {
  color: #fbbf24;
  border-color: #7c5a1d;
}
.badge.status-suspended {
  color: #fca5a5;
  border-color: #7f1d1d;
  background: #3a1416;
}
.user-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.user-row:last-child {
  border-bottom: none;
}
.user-row .badge {
  flex: 0 0 auto;
  margin-right: 10px;
  text-transform: capitalize;
}
.usage-line {
  font-size: 12px;
  color: var(--accent);
  margin-top: 2px;
}
.user-row.clickable {
  cursor: pointer;
}
.status-dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 2px;
}
.status-dot.status-active {
  background: var(--accent);
}
.status-dot.status-pending {
  background: #fbbf24;
}
.status-dot.status-suspended {
  background: #ef4444;
}
.user-row.clickable:hover {
  background: var(--bg-2);
  border-radius: 10px;
}
.history-group {
  margin-top: 18px;
}
.history-contact {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.history-contact.clickable {
  cursor: pointer;
  user-select: none;
}
.history-contact.clickable:hover .history-name {
  color: var(--accent);
}
.history-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex: 0 0 auto;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
}
.history-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.history-head-text {
  flex: 1;
  min-width: 0;
}
.history-title-line {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
.history-count {
  font-weight: 400;
  color: var(--muted);
  font-size: 13px;
}
.history-last {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}
.history-arrow {
  flex: 0 0 auto;
  font-size: 13px;
  color: var(--muted);
}
.history-msgs.hidden {
  display: none;
}
.msg {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.msg:last-child {
  border-bottom: none;
}
.msg-role {
  flex: 0 0 90px;
  font-weight: 700;
  color: var(--muted);
  font-size: 12px;
}
.msg-assistant .msg-role {
  color: var(--accent);
}
.msg-text {
  flex: 1;
  min-width: 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-at {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--muted);
}