:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "Noto Sans TC", sans-serif;
  color: #17202b;
  background: #f3f5f8;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --blue: #1677ff;
  --ink: #17202b;
  --muted: #6d7785;
  --line: #e1e6ed;
  --surface: #fff;
  --shadow: 0 16px 48px rgba(28, 44, 64, .08);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--blue); text-decoration: none; }
code { overflow-wrap: anywhere; color: #445166; }
.hidden { display: none !important; }
.admin-shell { background: radial-gradient(circle at 12% -6%, #e5f0ff 0, transparent 27rem), #f3f5f8; }
.admin-frame { width: min(1500px, 100% - 40px); margin: 0 auto; padding: 20px 0 112px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 8px 0 26px; }
.brand-lockup, .topbar-actions { display: flex; align-items: center; gap: 12px; }
.brand-lockup { color: var(--ink); }
.brand-lockup strong { display: block; letter-spacing: -.03em; font-size: 17px; }
.brand-lockup small { display: block; color: var(--muted); font-size: 11px; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; color: white; border-radius: 13px; font-size: 18px; font-weight: 750; background: linear-gradient(145deg, #2b8cff, #1461e8); box-shadow: 0 8px 20px #1677ff42; }
.admin-name { color: #526174; font-size: 13px; }
.status-pill { display: inline-flex; align-items: center; gap: 8px; border-radius: 999px; background: #f1f4f8; color: #596677; padding: 7px 11px; font-size: 12px; white-space: nowrap; }
.status-pill i { width: 7px; height: 7px; border-radius: 50%; background: #99a4b1; }
.status-pill.is-online { background: #e9f8ef; color: #16733c; }
.status-pill.is-online i { background: #2bb867; }
.status-pill.is-offline { background: #fff0ed; color: #aa3c2b; }
.status-pill.is-offline i { background: #e4614e; }
.service-indicator { display: inline-flex; width: 14px; height: 14px; align-items: center; justify-content: center; border-radius: 50%; background: #fff0ed; }
.service-indicator i { width: 8px; height: 8px; border-radius: 50%; background: #e4614e; }
.service-indicator.is-online { background: #e9f8ef; }
.service-indicator.is-online i { background: #2bb867; }
.service-indicator.is-offline { background: #fff0ed; }
.service-indicator.is-offline i { background: #e4614e; }
.card { background: var(--surface); border: 1px solid #e9edf2; border-radius: 20px; box-shadow: var(--shadow); }
.login-card { width: min(440px, 100%); margin: min(12vh, 120px) auto 0; padding: 34px; }
h1, h2, h3, h4, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(28px, 4vw, 38px); letter-spacing: -.045em; }
h2 { margin: 0; font-size: 21px; letter-spacing: -.03em; }
h3 { margin: 0 0 14px; font-size: 15px; letter-spacing: -.015em; }
.eyebrow { color: #718096; text-transform: uppercase; font-size: 10px; font-weight: 750; letter-spacing: .12em; margin-bottom: 8px; }
.muted { color: var(--muted); line-height: 1.55; }
.small { font-size: 12px; }
.stack-form, .editor-form { display: grid; gap: 16px; }
label { display: grid; gap: 7px; color: #39465a; font-size: 12px; font-weight: 650; }
input, select, textarea { width: 100%; min-width: 0; min-height: 44px; border: 1px solid #dfe5ec; outline: none; border-radius: 11px; padding: 10px 12px; color: var(--ink); background: #fff; transition: border-color .16s, box-shadow .16s; }
input:focus, select:focus, textarea:focus { border-color: #74adff; box-shadow: 0 0 0 3px #1677ff1b; }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 18px; accent-color: var(--blue); }
input[type="color"] { min-height: 42px; padding: 4px; }
select[multiple] { padding: 5px; }
.inline-label { display: flex; align-items: center; justify-content: space-between; min-height: 42px; padding: 0 12px; border: 1px solid #dfe5ec; border-radius: 11px; }
.button { display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 12px; min-height: 44px; padding: 0 17px; font-weight: 700; font-size: 13px; transition: transform .12s, background .12s, box-shadow .12s; }
.button:hover { transform: translateY(-1px); }
.button-primary { color: #fff; background: linear-gradient(180deg, #2384ff, #1266e9); box-shadow: 0 7px 18px #1677ff35; }
.button-primary:hover { background: #075be0; }
.button-secondary { color: #253449; background: #edf1f6; }
.button-secondary:hover, .button-quiet:hover { background: #e3e9f0; }
.button-quiet { color: #596a80; background: transparent; }
.form-message { min-height: 18px; margin: 0; color: #bd4435; font-size: 12px; }
.form-message.success { color: #1e8149; }
.service-error-banner { margin: 0 0 16px; padding: 14px 16px; border: 1px solid #ffd2cb; border-radius: 14px; color: #87362b; background: #fff3f0; font-size: 13px; line-height: 1.5; }
.workspace { display: grid; gap: 22px; }
.welcome-row { display: flex; align-items: end; justify-content: space-between; gap: 24px; padding: 8px 2px 0; }
.welcome-row p { max-width: 420px; margin-bottom: 5px; font-size: 13px; }
.tabbar { display: flex; gap: 6px; overflow-x: auto; padding: 6px; background: #e9edf3; border-radius: 14px; }
.tab { flex: 0 0 auto; border: 0; background: transparent; color: #657286; border-radius: 10px; padding: 10px 15px; font-size: 13px; font-weight: 700; }
.tab.active { background: white; color: #1f2d40; box-shadow: 0 2px 10px #19273a12; }
.tab-panel { min-width: 0; }
.two-column { display: grid; grid-template-columns: minmax(245px, .34fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.list-card, .editor-card, .domains-layout > .card, #tab-calls > .card { padding: 22px; min-width: 0; }
.card-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.entity-list { display: grid; gap: 8px; }
.entity-row { display: grid; gap: 4px; width: 100%; text-align: left; border: 1px solid transparent; border-radius: 13px; background: #f6f8fb; padding: 13px; color: var(--ink); }
.entity-row:hover { background: #eef4ff; }
.entity-row.selected { border-color: #a6cbff; background: #eff6ff; }
.entity-row strong { font-size: 13px; }
.entity-row span { color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.empty-state { color: #7c8795; padding: 18px 10px; text-align: center; font-size: 13px; }
.editor-form { gap: 0; }
.form-section { border-top: 1px solid var(--line); padding: 20px 0; }
.form-section:first-of-type { border-top: 0; padding-top: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.custom-invite-header-editor { display: grid; gap: 12px; margin-top: 18px; padding: 15px; border: 1px solid var(--line); border-radius: 15px; background: #fafbfd; }
.custom-header-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.custom-header-heading h4 { margin: 0 0 4px; font-size: 13px; }
.custom-header-heading p { margin: 0; }
.custom-invite-header-list { display: grid; gap: 10px; }
.custom-invite-header-row { display: grid; grid-template-columns: minmax(130px, .8fr) minmax(140px, .8fr) minmax(170px, 1.1fr) minmax(170px, 1.1fr) auto; align-items: end; gap: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.custom-header-remove { min-height: 40px; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; border-top: 1px solid var(--line); padding-top: 18px; }
.brand-editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, .72fr); gap: 18px; align-items: start; }
.preview-wrap { background: #f6f8fb; border-radius: 15px; padding: 14px; }
.brand-preview { display: grid; justify-items: center; text-align: center; min-height: 310px; padding: 26px 18px; border-radius: 17px; background: #f5f7fa; background-size: cover; background-position: center; color: #17202b; overflow: hidden; }
.brand-preview strong { font-size: 12px; opacity: .74; }
.brand-preview h4 { margin: 13px 0 6px; font-size: 24px; line-height: 1.18; letter-spacing: -.04em; }
.brand-preview p { margin: 0 0 18px; color: #697687; font-size: 13px; }
.preview-logo { max-width: 130px; max-height: 60px; object-fit: contain; margin-bottom: 16px; }
.preview-support { width: 58px; height: 58px; border-radius: 50%; object-fit: cover; margin-bottom: 14px; }
.call-button { min-height: 44px; padding: 0 21px; color: white; border: 0; border-radius: 14px; background: #007aff; font-weight: 700; }
.call-button.pill { border-radius: 999px; }
.call-button.square { border-radius: 6px; }
.share-url { overflow-wrap: anywhere; padding: 12px; margin: 16px 0; border-radius: 11px; color: #40536c; background: #f1f5fa; font-size: 12px; }
.share-url a { display: inline-block; margin-top: 6px; }
.qr-preview { display: block; width: min(240px, 100%); height: auto; margin: 16px 0 4px; padding: 10px; border: 1px solid #e1e6ed; border-radius: 15px; background: #fff; }
.domains-layout { grid-template-columns: minmax(0, .9fr) minmax(280px, 1fr); }
.callout { display: grid; gap: 7px; padding: 16px; border-radius: 14px; background: #f3f7fc; color: #43546b; font-size: 13px; line-height: 1.5; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 650px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); font-size: 12px; }
th { color: #738095; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
td { color: #354358; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 10; max-width: min(420px, calc(100vw - 32px)); padding: 12px 16px; border-radius: 13px; color: white; background: #202d3d; box-shadow: 0 12px 35px #12233a30; opacity: 0; transform: translateY(8px); pointer-events: none; transition: .2s; font-size: 13px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #a5372c; }
.floating-save-dock { position: fixed; right: 24px; bottom: 20px; z-index: 20; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; max-width: calc(100vw - 48px); padding: 10px; border: 1px solid #dce3eb; border-radius: 16px; background: rgba(255,255,255,.95); box-shadow: 0 12px 36px rgba(24, 39, 58, .2); backdrop-filter: blur(14px); }
.workspace.has-floating-save .toast { bottom: 92px; }

/* Public QR call page */
.call-shell { display: grid; place-items: center; padding: 24px; background: #f5f7fa; }
.call-card { width: min(460px, 100%); min-height: min(680px, calc(100vh - 48px)); display: grid; align-content: center; justify-items: center; gap: 10px; padding: clamp(24px, 6vw, 44px); border: 1px solid var(--call-border, #e7ebf0); border-radius: 32px; color: var(--call-ink, #17202b); background: rgba(255,255,255,.94); box-shadow: 0 24px 70px #24364d18; text-align: center; background-size: cover; background-position: center; }
.call-logo { max-width: 170px; max-height: 80px; object-fit: contain; margin-bottom: 8px; }
.call-support { width: 82px; height: 82px; object-fit: cover; border-radius: 50%; box-shadow: 0 8px 24px #192a3c20; }
.call-company { color: var(--call-muted, #687689); font-size: 13px; font-weight: 700; }
.call-card h1 { margin: 6px 0 0; font-size: clamp(27px, 7vw, 35px); }
.call-subtitle { color: var(--call-muted, #6c7889); font-size: 14px; line-height: 1.5; }
.visitor-field { display: grid; gap: 7px; width: 100%; margin: 11px 0; text-align: left; }
.call-card .visitor-field label, .call-card .visitor-field .muted, .call-card .privacy-note { color: var(--call-muted, #5e6c80); }
.visitor-field label { font-size: 13px; }
.visitor-field input { min-height: 49px; border-radius: 14px; font-size: 16px; }
.privacy-note { color: #8792a0; font-size: 11px; line-height: 1.5; }
.call-actions { display: grid; grid-template-columns: 1fr; gap: 9px; width: 100%; margin-top: 5px; }
.call-start, .call-hangup { min-height: 54px; width: 100%; border: 0; border-radius: 17px; color: white; font-size: 16px; font-weight: 750; }
.call-start { background: var(--brand, #007aff); box-shadow: 0 10px 24px color-mix(in srgb, var(--brand, #007aff) 27%, transparent); }
.call-start.pill, .call-hangup.pill { border-radius: 999px; }
.call-start.square, .call-hangup.square { border-radius: 7px; }
.call-hangup { background: #e74c3c; }
.call-status { min-height: 22px; margin: 3px 0 0; color: var(--call-muted, #5e6c80); font-size: 13px; }
.dtmf-controls { width: 100%; margin-top: 8px; }
.dtmf-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; max-width: 320px; margin: 0 auto; }
.dtmf-grid button { min-height: 44px; border: 1px solid #dce3eb; border-radius: 13px; color: #203047; background: #f5f7fa; font-size: 17px; font-weight: 650; }
.dtmf-grid button:hover:not(:disabled) { border-color: #9fc5ff; background: #edf5ff; }
.dtmf-grid button:disabled { cursor: wait; opacity: .55; }
.dtmf-status { min-height: 18px; margin: 7px 0 0; color: #607086; font-size: 12px; }
.call-error { color: #b44234; }
.remote-audio { position: absolute; width: 1px; height: 1px; opacity: 0; }

@media (max-width: 920px) {
  .two-column { grid-template-columns: 1fr; }
  .brand-editor-layout { grid-template-columns: 1fr; }
  .welcome-row { display: block; }
  .welcome-row p { margin-top: 10px; }
}
@media (max-width: 620px) {
  .admin-frame { width: min(100% - 24px, 1500px); padding-top: 12px; padding-bottom: 116px; }
  .topbar { align-items: flex-start; padding-bottom: 18px; }
  .topbar-actions { gap: 6px; flex-wrap: wrap; justify-content: end; }
  .status-pill { font-size: 10px; padding: 6px 8px; }
  .admin-name { display: none; }
  .login-card { margin-top: 8vh; padding: 25px 20px; }
  .list-card, .editor-card, .domains-layout > .card, #tab-calls > .card { padding: 17px; border-radius: 17px; }
  .form-grid { grid-template-columns: 1fr; }
  .custom-header-heading { align-items: flex-start; flex-direction: column; }
  .custom-invite-header-row { grid-template-columns: 1fr; align-items: stretch; }
  .form-actions { align-items: stretch; }
  .form-actions .button { flex: 1 1 auto; }
  .floating-save-dock { right: 12px; bottom: 12px; left: 12px; max-width: none; justify-content: stretch; }
  .floating-save-dock .button { flex: 1 1 auto; }
  .workspace.has-floating-save .toast { right: 12px; bottom: 92px; }
  .call-shell { padding: 14px; }
  .call-card { min-height: calc(100vh - 28px); border-radius: 26px; }
}
#ice-debug-panel {
  margin-top: 1rem;
  padding: 0.75rem;
  border: 1px solid var(--call-border, #c8d0da);
  border-radius: 0.75rem;
  color: var(--call-ink, #17202b);
  text-align: left;
}

#ice-debug-panel summary {
  cursor: pointer;
  font-weight: 600;
}

#ice-debug-output {
  max-height: 18rem;
  margin: 0.75rem 0 0;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 0.75rem/1.45 ui-monospace, Consolas, monospace;
}
