: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;
}

.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 {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
}

.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;
}

.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-item {
  width: 100%;
  text-align: left;
  background: transparent;
  color: #dbe5ee;
}

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

main {
  padding: 24px;
}

.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;
}

.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 {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: white;
  color: var(--text);
}

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

.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;
}

.conversation {
  min-height: 520px;
  display: grid;
  grid-template-rows: auto 1fr;
}

.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;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-record {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  color: var(--text);
  padding: 12px;
  text-align: left;
}

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

.history-record span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.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) {
  #app,
  .split,
  .workspace,
  .history-layout,
  .metrics {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

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

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