:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --text: #1c2430;
  --muted: #657284;
  --line: #d9e0e8;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --warn: #b45309;
  --fail: #b91c1c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft JhengHei", "Segoe UI", Arial, sans-serif;
  height: 100vh;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  padding: 10px 14px;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.loading-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 50%;
  vertical-align: -2px;
  animation: spin 0.8s linear infinite;
}

button.secondary .loading-dot {
  border-color: rgba(28, 36, 48, 0.25);
  border-top-color: var(--text);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

button.secondary {
  background: #e8eef4;
  color: var(--text);
}

button.secondary:hover {
  background: #d8e1ea;
}

button.danger {
  background: #b91c1c;
}

button.danger:hover {
  background: #991b1b;
}

button.small {
  padding: 6px 9px;
}

#app {
  height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
  overflow: hidden;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(245, 247, 250, 0.94), rgba(230, 238, 246, 0.96)),
    linear-gradient(135deg, #17202b, #0f766e);
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 16px 44px rgba(23, 32, 43, 0.16);
}

.login-card h1 {
  margin-bottom: 2px;
}

.login-brand {
  margin-bottom: 6px;
  color: var(--text);
}

.sidebar {
  background: #17202b;
  color: white;
  padding: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

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

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: #2dd4bf;
  color: #10212a;
  font-weight: 800;
}

.brand small {
  display: block;
  color: #a6b4c2;
  margin-top: 4px;
}

nav {
  display: grid;
  gap: 8px;
}

.nav-group {
  display: grid;
  gap: 6px;
}

.nav-group-label {
  padding: 4px 12px 0;
  color: #8fa0b1;
  font-size: 13px;
}

.nav-item {
  width: 100%;
  text-align: left;
  background: transparent;
  color: #dbe5ee;
}

.nav-subitem {
  padding-left: 18px;
  font-size: 15px;
}

.nav-item.active,
.nav-item:hover {
  background: #263443;
}

main {
  padding: 24px;
  height: 100vh;
  overflow-y: auto;
}

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

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  font-size: 24px;
  margin-bottom: 6px;
}

h2 {
  font-size: 18px;
}

.topbar p,
.hint,
small {
  color: var(--muted);
}

.login-box {
  display: flex;
  align-items: center;
  gap: 12px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric {
  padding: 18px;
}

.metric span {
  display: block;
  font-size: 32px;
  font-weight: 800;
}

.panel {
  padding: 18px;
}

.split {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  align-items: start;
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.summary-item {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.summary-item span {
  color: var(--muted);
  font-size: 13px;
}

.summary-item strong {
  font-size: 14px;
  word-break: break-word;
}

.ai-config-shell {
  display: grid;
  gap: 16px;
}

.ai-tab-panel {
  display: none;
}

.ai-tab-panel.active {
  display: block;
}

.config-stack {
  display: grid;
  gap: 16px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(17, 24, 39, 0.45);
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-card {
  width: min(760px, 100%);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.18);
  padding: 20px;
}

.stt-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.stt-toolbar input,
.stt-toolbar select {
  width: auto;
}

.stt-toolbar input[type="search"] {
  flex: 1 1 320px;
}

.stt-draft-box {
  display: grid;
  gap: 10px;
}

.stt-draft-input-row {
  display: flex;
  gap: 8px;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 44px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid #c5d1dd;
  border-radius: 999px;
  background: white;
}

.chip button {
  min-width: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.stt-group-card {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
}

.stt-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stt-group-main {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
  flex: 1;
}

.stt-group-main input[type="checkbox"] {
  margin-top: 4px;
}

.stt-group-info {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.stt-group-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.stt-group-title-row strong {
  font-size: 18px;
}

.stt-group-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
}

.boost-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.boost-inline input {
  width: 72px;
  min-width: 72px;
  padding: 8px 10px;
}

.stt-group-card .row-actions {
  align-items: center;
  flex-wrap: wrap;
}

.stt-group-card .chip-list {
  min-height: 0;
  padding: 10px 12px;
  background: #f8fbff;
}

.stt-group-card .chip {
  padding: 5px 10px;
  font-size: 14px;
}

.legacy-stt-card {
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
}

.legacy-stt-top {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.legacy-stt-check {
  padding-top: 6px;
}

.legacy-stt-body {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.legacy-stt-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
}

.legacy-stt-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.legacy-stt-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
}

.legacy-stt-card .chip-list {
  min-height: 0;
  padding: 10px 12px;
  background: #fff;
}

.legacy-stt-card:has(.stt-group-checkbox:checked) {
  border-color: #7db7ff;
  background: #f7fbff;
}

@media (max-width: 900px) {
  .stt-group-header {
    align-items: stretch;
    flex-direction: column;
  }

  .stt-group-card .row-actions {
    justify-content: flex-start;
  }

  .legacy-stt-top {
    grid-template-columns: 1fr;
  }

  .legacy-stt-head {
    flex-direction: column;
    align-items: flex-start;
  }
}

.stack-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.form-panel {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-check input {
  width: auto;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: white;
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 88px;
  font: inherit;
}

.deployment-note {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.list {
  display: grid;
  gap: 10px;
}

.voice-list {
  display: grid;
  gap: 16px;
}

.voice-item {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.voice-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  color: var(--muted);
  font-size: 14px;
}

.knowledge-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 8px;
  background: #fbfcfe;
}

.knowledge-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
}

.voice-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.voice-current {
  display: grid;
  gap: 10px;
}

.voice-current audio {
  width: min(520px, 100%);
  max-width: 100%;
}

.voice-modal-current {
  display: grid;
  gap: 8px;
  margin: 12px 0 16px;
}

.voice-modal-current audio {
  width: min(520px, 100%);
  max-width: 100%;
}

.voice-method-switch {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.voice-method-tab.active {
  background: #2563eb;
  color: #fff;
}

.voice-method-tab.active:hover {
  background: #1d4ed8;
}

.voice-method-panel {
  display: none;
}

.voice-method-panel.active {
  display: block;
}

.voice-modal-upload-form {
  padding: 0;
  border: 0;
}

.voice-update-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  gap: 14px;
}

.voice-method {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  display: grid;
  gap: 12px;
}

.voice-method-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.voice-tools {
  display: grid;
  gap: 10px;
}

.voice-tools textarea {
  min-height: 112px;
}

.voice-draft {
  display: none;
  gap: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fbff;
}

.voice-draft.active {
  display: grid;
}

.voice-draft-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.voice-draft audio {
  width: min(420px, 100%);
  max-width: 100%;
}

.voice-upload-form {
  display: grid;
  gap: 10px;
}

.voice-upload-form input[type="file"] {
  width: 100%;
}

#defaultVoiceStatus {
  margin-bottom: 12px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-heading h2 {
  margin-bottom: 0;
}

.pager {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.pager button {
  padding: 7px 10px;
}

.pager button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  background: #eef3f7;
  color: #415062;
  font-weight: 700;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.data-table td:last-child,
.data-table th:last-child {
  text-align: right;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfe;
}

.item strong {
  display: block;
  margin-bottom: 4px;
}

.status {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  background: #e6fffa;
  color: var(--accent-strong);
}

.status.failed {
  background: #fee2e2;
  color: var(--fail);
}

.workspace {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
}

.phone-panel {
  min-height: 520px;
  display: grid;
  align-content: start;
  gap: 16px;
}

.phone-identity {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfe;
}

.sip-registration {
  border-radius: 8px;
  padding: 9px 12px;
  background: #f1f5f9;
  color: var(--muted);
  font-size: 14px;
}

.sip-registration.registering {
  background: #fef3c7;
  color: var(--warn);
}

.sip-registration.registered {
  background: #dcfce7;
  color: #166534;
}

.sip-registration.failed {
  background: #fee2e2;
  color: var(--fail);
}

.phone-target {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #eef3f7;
}

.phone-target span {
  color: var(--muted);
}

.phone-target strong {
  font-size: 40px;
  line-height: 1;
  letter-spacing: 0;
}

.phone-status {
  border-radius: 8px;
  padding: 12px;
  background: #e6fffa;
  color: var(--accent-strong);
  font-weight: 700;
}

.phone-status.calling {
  background: #fef3c7;
  color: var(--warn);
}

.phone-status.in-call {
  background: #dcfce7;
  color: #166534;
}

.phone-status.incoming {
  background: #dbeafe;
  color: #1d4ed8;
}

.incoming-call {
  display: grid;
  gap: 12px;
  border: 1px solid #93c5fd;
  border-radius: 8px;
  padding: 12px;
  background: #eff6ff;
}

.incoming-call > div:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.incoming-call span {
  color: var(--muted);
}

.incoming-call strong {
  font-size: 24px;
}

.phone-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.extension-dialer {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.extension-dialer button {
  width: 100%;
}

.ringtone-setting {
  display: grid;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.ringtone-setting label {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ringtone-setting input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
}

.dialer,
.composer,
.button-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.ghost,
.ghost-danger {
  border: 1px solid var(--line);
  background: white;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
}

.ghost-danger {
  border-color: #efb4b4;
  color: #9a1f1f;
}

.conversation {
  min-height: 520px;
  height: calc(100vh - 180px);
  max-height: calc(100vh - 180px);
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
}

.line-panel {
  min-width: 0;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding: 12px;
  background: #eef3f7;
  border-radius: 8px;
  min-height: 340px;
}

.bubble {
  max-width: 78%;
  padding: 10px 12px;
  border-radius: 8px;
  background: white;
  border: 1px solid var(--line);
}

.bubble.ai {
  background: #dff7ee;
  align-self: flex-start;
}

.bubble.user {
  background: white;
  align-self: flex-end;
}

.bubble.system {
  align-self: center;
  max-width: 88%;
  background: #f8fafc;
  color: var(--muted);
  font-size: 14px;
}

.message-audio {
  display: block;
  width: 100%;
  height: 36px;
  margin-top: 10px;
}

.bubble.has-audio {
  width: min(78%, 360px);
  min-width: min(340px, 100%);
}

.bubble.user .message-audio {
  margin-left: auto;
}

.history-layout {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}

.history-panel {
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-height: 520px;
  height: calc(100vh - 180px);
  max-height: calc(100vh - 180px);
}

.history-filters {
  display: grid;
  gap: 8px;
  margin: 10px 0 12px;
}

.history-filters label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
}

.history-filters input,
.history-filters select {
  width: 100%;
}

.history-list {
  display: grid;
  align-content: start;
  grid-auto-rows: 82px;
  gap: 8px;
  overflow-y: auto;
  min-height: 0;
  padding-right: 4px;
}

.history-record {
  width: 100%;
  height: 82px;
  border: 1px solid var(--line);
  background: white;
  color: var(--text);
  padding: 12px 14px;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  overflow: hidden;
}

.history-record.active {
  border-color: var(--accent);
  background: #edf7f5;
}

.history-record-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  min-width: 0;
}

.history-record-top strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-record-time {
  white-space: nowrap;
  flex-shrink: 0;
}

.history-record span {
  display: block;
  color: var(--muted);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-record-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.history-badge,
.review-badge,
.message-correction {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  line-height: 1;
  background: #edf2f7;
  color: var(--muted);
}

.history-badge.bad,
.review-badge.bad,
.message-correction.bad {
  background: #fde8e8;
  color: #b42318;
}

.history-badge.warn,
.review-badge.pending {
  background: #fff3d6;
  color: #b36b00;
}

.review-badge.good,
.message-correction.good {
  background: #dff7ee;
  color: #117a5a;
}

.history-review-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.history-review-summary > div,
.history-review-section {
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
  padding: 12px;
}

.history-review-summary strong,
.history-review-summary span {
  display: block;
}

.history-review-summary strong {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}

.history-review-header {
  margin-bottom: 12px;
}

.company-review-list {
  display: grid;
  gap: 12px;
}

.company-review-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdff;
}

.company-review-card.review-good {
  border-color: #b9ebd5;
  background: #f7fffb;
}

.company-review-card.review-bad {
  border-color: #f4b5b5;
  background: #fffafa;
}

.company-review-head,
.company-review-sub,
.company-review-actions,
.message-review-actions,
.message-correction-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.company-review-head {
  justify-content: space-between;
  align-items: flex-start;
}

.company-review-meta,
.company-review-sub {
  color: var(--muted);
  font-size: 14px;
  margin-top: 6px;
}

.company-review-form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.company-review-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

.message-review-actions {
  margin-top: 10px;
}

.message-correction-list {
  margin-top: 8px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: #17202b;
  color: white;
  padding: 12px 14px;
  border-radius: 8px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 900px) {
  body {
    height: auto;
    overflow: auto;
  }

  #app,
  .split,
  .workspace,
  .history-layout,
  .config-grid,
  .summary-grid,
  .metrics {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    overflow: visible;
  }

  main {
    height: auto;
    overflow: visible;
  }

  .topbar,
  .dialer,
  .composer {
    flex-direction: column;
    align-items: stretch;
  }

  .conversation,
  .history-panel {
    height: auto;
    max-height: none;
  }

  .history-review-summary {
    grid-template-columns: 1fr;
  }

  .bubble.has-audio {
    width: 100%;
    min-width: 0;
  }

  .voice-update-grid {
    grid-template-columns: 1fr;
  }

  .voice-head,
  .voice-draft-row,
  .voice-method-title {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Hotword group list layout fix */
#sttGroupList {
  display: grid;
  gap: 10px;
}

.stt-group-card {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  padding: 14px 16px;
  cursor: pointer;
}

.stt-group-card.selected,
.stt-group-card:has(.stt-group-checkbox:checked) {
  border-color: #7db7ff;
  background: #f7fbff;
}

.stt-card-select {
  padding-top: 4px;
}

.stt-card-content {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.stt-card-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.stt-card-title-row strong {
  font-size: 17px;
}

.stt-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
}

.stt-card-actions {
  justify-content: flex-end;
  white-space: nowrap;
}

.stt-phrase-list {
  min-height: 0;
  padding: 10px 12px;
  background: #fbfcfe;
}

@media (max-width: 900px) {
  .stt-group-card {
    grid-template-columns: 28px minmax(0, 1fr);
  }

  .stt-card-actions {
    grid-column: 2;
    justify-content: flex-start;
    white-space: normal;
  }
}

/* Admin history review UI - closer to admin_company_review_dev.php */
#historyDetail {
  min-width: 0;
}

#historyDetail .topline,
.configured-keywords .topline,
.history-message-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.history-review-section.conversation-column {
  display: grid;
  gap: 12px;
}

.configured-keywords {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfe;
}

.keyword-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.configured-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #f1c96a;
  border-radius: 999px;
  padding: 6px 10px;
  background: #fff8df;
  color: #995f00;
  font-size: 13px;
}

.configured-chip.good {
  border-color: #9ed9c3;
  background: #e6f8f0;
  color: #117a5a;
}

.configured-chip.bad {
  border-color: #efb4b4;
  background: #fde8e8;
  color: #b42318;
}

.configured-chip.warn {
  border-color: #f1c96a;
  background: #fff8df;
  color: #995f00;
}

.configured-remove {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  min-width: 20px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid currentColor;
  background: rgba(255,255,255,0.65);
  color: inherit;
  line-height: 1;
  font-weight: 700;
}

.configured-remove:hover {
  background: rgba(0,0,0,0.08);
}

.history-message-list {
  display: grid;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  background: #eef3f7;
  max-height: calc(100vh - 340px);
  overflow: auto;
}

.history-message {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.history-message.user {
  background: #eef6ff;
}

.history-message.assistant {
  background: #effaf2;
}

.history-message.active {
  outline: 2px solid #5c8dff;
  outline-offset: 0;
}

.history-message-top span {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.history-message-text {
  line-height: 1.75;
  cursor: text;
  white-space: pre-wrap;
  word-break: break-word;
}

.history-message-text mark {
  background: #fde68a;
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}

.history-message-text mark.voice-error {
  background: #fecaca;
  color: #991b1b;
}

.message-feedback {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.feedback-btn {
  min-width: 34px;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--text);
}

.feedback-btn.good.active,
.feedback-btn.good:hover {
  border-color: #60a985;
  background: #dff7ee;
  color: #117a5a;
}

.feedback-btn.bad.active,
.feedback-btn.bad:hover {
  border-color: #ef9a9a;
  background: #fde8e8;
  color: #b42318;
}

.token-info {
  margin-left: 4px;
}

.history-mark-menu {
  position: fixed;
  z-index: 2000;
  display: grid;
  gap: 4px;
  min-width: 180px;
  padding: 8px;
  border-radius: 8px;
  background: #101827;
  box-shadow: 0 18px 44px rgba(15, 23, 42, 0.28);
}

.history-mark-menu button {
  width: 100%;
  background: transparent;
  color: #fff;
  text-align: left;
  border-radius: 6px;
  padding: 10px 12px;
}

.history-mark-menu button:hover {
  background: rgba(255,255,255,0.12);
}

.compact-company-review {
  margin-top: 12px;
}

.compact-company-review .company-review-card {
  padding: 12px;
}

@media (max-width: 900px) {
  .history-message-list {
    max-height: none;
  }
  #historyDetail .topline,
  .configured-keywords .topline,
  .history-message-top {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* History review pagination + mobile friendly refinements */
.history-list {
  grid-auto-rows: auto;
}

.history-record {
  min-height: 104px;
  height: auto;
  justify-content: flex-start;
}

.history-record-preview {
  color: var(--text);
  font-size: 15px;
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.history-record-summary {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-pager {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 0 0;
  background: var(--panel);
}

.history-pager button {
  min-width: 86px;
}

.history-selection-toolbar {
  position: fixed;
  z-index: 1800;
  display: flex;
  gap: 6px;
  padding: 6px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #111827;
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.22);
}

.history-selection-toolbar button {
  padding: 7px 10px;
  border-radius: 999px;
  background: transparent;
  color: white;
  font-size: 13px;
  white-space: nowrap;
}

.history-selection-toolbar button:hover {
  background: rgba(255, 255, 255, 0.14);
}

.configured-chip.good,
.history-badge.good {
  border-color: #8bd9bb;
  background: #dcfce7;
  color: #047857;
}

.history-badge.bad,
.configured-chip.bad {
  border-color: #fecaca;
  background: #fee2e2;
  color: #b91c1c;
}

.history-message.active {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
}

.selectable-text {
  user-select: text;
  -webkit-user-select: text;
  touch-action: manipulation;
}

@media (max-width: 760px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  #app {
    display: block;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 1000;
    height: auto;
    max-height: 44vh;
    overflow: auto;
    padding: 12px;
  }

  .brand {
    margin-bottom: 10px;
  }

  nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .nav-group {
    display: contents;
  }

  .nav-group-label {
    display: none;
  }

  .nav-item,
  .nav-subitem {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
    padding: 10px 12px;
    border-radius: 999px;
  }

  main {
    height: auto;
    overflow: visible;
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .login-box {
    width: 100%;
    justify-content: space-between;
  }

  .metrics,
  .split,
  .config-grid,
  .workspace,
  .history-layout,
  .summary-grid,
  .history-review-summary {
    grid-template-columns: 1fr !important;
  }

  .panel {
    padding: 14px;
  }

  .conversation,
  .history-panel {
    height: auto;
    max-height: none;
    min-height: 0;
  }

  .history-panel {
    grid-template-rows: auto auto auto;
  }

  .history-list {
    max-height: 52vh;
    overflow-y: auto;
    padding-right: 0;
  }

  .messages {
    min-height: 0;
    max-height: none;
    overflow: visible;
    padding: 10px;
  }

  .history-message-list {
    max-height: none;
    overflow: visible;
  }

  .bubble,
  .bubble.has-audio {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .phone-actions,
  .button-row,
  .dialer,
  .composer {
    display: grid;
    grid-template-columns: 1fr;
  }

  button,
  input,
  select,
  textarea {
    font-size: 16px;
  }

  .phone-actions button,
  .extension-dialer button,
  #callAiPhoneBtn,
  #dialExtensionBtn {
    min-height: 48px;
    font-weight: 700;
  }

  .extension-dialer select,
  .phone-target,
  .phone-status,
  .sip-registration {
    font-size: 16px;
  }

  .history-selection-toolbar {
    left: 8px !important;
    right: 8px;
    top: auto !important;
    bottom: 12px;
    justify-content: center;
    border-radius: 16px;
    flex-wrap: wrap;
  }

  .history-mark-menu {
    max-width: calc(100vw - 16px);
  }

  .configured-chip {
    max-width: 100%;
  }

  .history-record-top {
    flex-direction: column;
    align-items: flex-start;
  }

  .history-record-time {
    white-space: normal;
  }
}

/* Clean history list: match admin_company_review_dev.php compact cards */
.history-list {
  gap: 8px;
}

.history-record.admin-history-card {
  min-height: 92px;
  padding: 10px 12px;
  gap: 6px;
  justify-content: flex-start;
}

.admin-history-card .history-record-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
}

.admin-history-card .history-record-top strong {
  font-size: 15px;
  line-height: 1.25;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

.admin-history-card .history-record-badges {
  margin: 0;
  flex-wrap: nowrap;
  align-items: start;
  justify-content: flex-end;
}

.admin-history-card .history-badge {
  white-space: nowrap;
  background: #eef3f7;
  color: #536174;
  border-color: transparent;
  padding: 3px 9px;
}

.admin-history-card .history-badge.bad {
  background: #fff1f2;
  color: #b91c1c;
}

.admin-history-card .history-record-preview {
  font-size: 15px;
  line-height: 1.35;
  color: var(--text);
  -webkit-line-clamp: 1;
}

.admin-history-card .history-record-summary {
  font-size: 13px;
  color: var(--muted);
}

.admin-history-card.active {
  border-color: var(--accent);
  background: #edf7f5;
}

@media (max-width: 900px) {
  .history-record.admin-history-card {
    min-height: 86px;
  }
  .admin-history-card .history-record-top {
    grid-template-columns: minmax(0, 1fr) auto;
  }
}

/* vNext: history left list follows admin_company_review_dev compact card style */
#callHistory.history-list,
.history-list {
  grid-auto-rows: auto !important;
  gap: 8px !important;
  overflow-y: auto;
  padding-right: 4px;
}

.history-record.history-card-simple {
  width: 100%;
  min-height: 92px !important;
  height: auto !important;
  padding: 10px 12px !important;
  display: grid !important;
  grid-template-rows: auto auto auto;
  gap: 6px !important;
  justify-content: initial !important;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: left;
  overflow: hidden;
}

.history-record.history-card-simple.active {
  border-color: var(--accent);
  background: #edf7f5;
}

.history-card-simple .history-card-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.history-card-simple .history-card-time {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 15px;
  line-height: 1.25;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-card-simple .history-badge {
  flex: 0 0 auto;
  margin: 0;
  display: inline-flex;
  align-items: center;
  border: 0;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  line-height: 1.2;
  background: #eef3f7;
  color: #536174;
  white-space: nowrap;
}

.history-card-simple .history-badge.good {
  background: #dff8eb;
  color: #047857;
}

.history-card-simple .history-badge.bad {
  background: #ffe3e3;
  color: #b91c1c;
}

.history-card-simple .history-card-preview {
  font-size: 15px;
  line-height: 1.35;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.history-card-simple .history-card-meta {
  font-size: 13px;
  line-height: 1.3;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-pager {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px 0 0;
  background: var(--panel);
}

.history-pager .hint {
  text-align: center;
  white-space: normal;
  line-height: 1.25;
}

.history-pager button {
  min-width: 74px;
  padding: 9px 12px;
}

@media (max-width: 900px) {
  .history-record.history-card-simple {
    min-height: 86px !important;
    padding: 10px !important;
  }
  .history-card-simple .history-card-time {
    font-size: 15px;
  }
  .history-card-simple .history-card-preview {
    -webkit-line-clamp: 2;
  }
}


/* Extension presence indicators */
.extension-presence-list {
  display: grid;
  gap: 8px;
  margin: 10px 0 12px;
  max-height: 260px;
  overflow-y: auto;
}

.extension-presence-item {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: left;
}

.extension-presence-item:hover,
.extension-presence-item.active {
  border-color: var(--accent);
  background: #ecfdf5;
}

.presence-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
  background: #94a3b8;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.16);
}

.presence-dot.online { background: #16a34a; box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.16); }
.presence-dot.busy { background: #dc2626; box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.16); }
.presence-dot.offline,
.presence-dot.unknown { background: #94a3b8; }

.presence-main {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.presence-main strong,
.presence-main small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.presence-label {
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--muted);
}

.presence-label.online { background: #dcfce7; color: #166534; }
.presence-label.busy { background: #fee2e2; color: #991b1b; }

@media (max-width: 760px) {
  .extension-presence-list { max-height: none; }
  .extension-presence-item { padding: 12px; }
}

/* 分機撥打區只保留選單，不顯示額外分機列表 */
#dialExtensionPresenceList {
  display: none !important;
}

/* History mark company modal / suggestions */
.history-company-modal {
  width: min(560px, calc(100vw - 28px));
  overflow: visible;
}

.history-company-modal label {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.history-company-suggestions {
  display: none;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  margin-top: 4px;
}

.history-company-suggestions.active {
  display: block;
}

.history-company-suggestions button {
  width: 100%;
  display: grid;
  gap: 4px;
  text-align: left;
  padding: 10px 12px;
  border: 0;
  border-radius: 0;
  background: #fff;
  color: var(--text);
}

.history-company-suggestions button:hover,
.history-company-suggestions button:focus {
  background: #eef7f5;
}

.history-company-suggestions button:disabled {
  color: var(--muted);
  background: #fff;
}

.history-company-suggestions strong {
  font-weight: 800;
}

.history-company-suggestions span {
  color: var(--muted);
  font-size: 13px;
}

.configured-chip .configured-remove {
  margin-left: 5px;
  padding: 0 4px;
  min-width: 22px;
  border-radius: 999px;
}

.history-badge.good,
.configured-chip.good {
  border-color: #9adfc9;
  background: #e8fff6;
  color: #047857;
}

.history-badge.warn,
.configured-chip.warn {
  border-color: #f6d577;
  background: #fff8df;
  color: #a16207;
}

.history-badge.bad,
.configured-chip.bad {
  border-color: #fecaca;
  background: #fff1f2;
  color: #b91c1c;
}

@media (max-width: 720px) {
  .history-company-modal {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 24px);
  }

  .history-company-suggestions {
    max-height: 42vh;
  }
}


/* Password-manager guard for admin-created test accounts.
   The input stays visible as bullets but is not a browser login password field,
   so Chrome/Google Password Manager is less likely to interrupt user creation. */
.masked-input {
  -webkit-text-security: disc;
}

.pager button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}


.modal-card.compact-modal {
  width: min(460px, 100%);
}

.modal-title-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.modal-title-row h2 {
  margin: 0 0 6px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}

.login-box {
  flex-wrap: wrap;
}
