:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #6d28d9;
  --primary-hover: #5b21b6;
  --ok-bg: #ecfdf5;
  --ok-text: #047857;
  --warn-bg: #fff7ed;
  --warn-text: #c2410c;
  --mcode-bg: #ecfdf5;
  --mcode-text: #047857;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

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

h1 {
  margin: 0 0 6px;
  font-size: 1.6rem;
  font-weight: 700;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.95rem;
  background: #fff;
  color: var(--text);
}

.search {
  flex: 1 1 280px;
  min-width: 200px;
}

.select {
  min-width: 140px;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.95rem;
  cursor: pointer;
  background: #eef2ff;
  color: #3730a3;
}

.btn:hover { filter: brightness(0.97); }

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-ghost {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.85rem;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--primary);
}

.meta-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
  font-size: 0.92rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.85rem;
  font-weight: 600;
}

.pill-ok { background: var(--ok-bg); color: var(--ok-text); }
.pill-warn { background: var(--warn-bg); color: var(--warn-text); }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Consolas, monospace; }
.nowrap { white-space: nowrap; }

.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th {
  text-align: left;
  padding: 12px 12px;
  background: #fafafa;
  color: #374151;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table tbody tr:hover { background: #fafbff; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 36px 12px !important;
}

.contact-name { font-weight: 600; }
.contact-id { color: var(--muted); font-size: 0.82rem; word-break: break-all; }

.badge-mcode {
  display: inline-block;
  background: var(--mcode-bg);
  color: var(--mcode-text);
  border-radius: 999px;
  padding: 3px 10px;
  font-weight: 600;
  font-size: 0.85rem;
}

.link-btn {
  border: none;
  background: none;
  color: #2563eb;
  cursor: pointer;
  padding: 0;
  font: inherit;
}

.link-btn:hover { text-decoration: underline; }

.conf-bar {
  width: 72px;
  height: 8px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

.conf-fill {
  height: 100%;
  background: linear-gradient(90deg, #60a5fa, #2563eb);
  border-radius: 999px;
}

.pager {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
}

.alert {
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.alert-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal.hidden { display: none; }

.modal-card {
  width: min(720px, 100%);
  max-height: 80vh;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-body {
  margin: 0;
  padding: 16px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.88rem;
  line-height: 1.45;
  background: #fafafa;
}
