:root {
  color-scheme: light;
  --primary-bg: #f5f7fb;
  --panel-bg: #ffffff;
  --border: #d8e0ea;
  --divider: #e8eef5;
  --accent: #1677ff;
  --accent-hover: #4096ff;
  --accent-soft: #edf5ff;
  --ppg: #22c55e;
  --orange: #f59e0b;
  --red: #ef4444;
  --cyan: #38bdf8;
  --text-primary: #172033;
  --text-body: #42526b;
  --text-secondary: #7c8aa0;
  --log-bg: #111827;
  --log-text: #4ade80;
  --log-time: #94a3b8;
  --surface-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 1024px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--primary-bg);
  color: var(--text-primary);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-bg);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.12s ease, background-color 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}

button:hover:not(:disabled) {
  border-color: var(--accent-hover);
  color: var(--accent);
}

button:disabled,
select:disabled {
  opacity: 0.72;
  cursor: default;
}

.window-shell {
  display: grid;
  grid-template-rows: 44px minmax(0, 1fr) 56px;
  width: 100vw;
  height: 100vh;
  min-width: 1024px;
  background: var(--primary-bg);
}

.title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 8px 0 16px;
  border-bottom: 1px solid var(--divider);
  background: var(--panel-bg);
  box-shadow: var(--surface-shadow);
}

.title-text {
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0;
}

.main-split {
  display: grid;
  grid-template-columns: minmax(620px, 2fr) 5px minmax(310px, 1fr);
  min-height: 0;
}

.main-split::before {
  content: "";
  grid-column: 2;
  grid-row: 1;
  background: var(--primary-bg);
}

.left-panel,
.right-panel {
  min-width: 0;
  min-height: 0;
  padding: 12px;
}

.left-panel {
  grid-column: 1;
  display: grid;
  grid-template-rows: 42px 44px minmax(0, 1fr);
  background: var(--panel-bg);
  border-right: 1px solid var(--divider);
}

.right-panel {
  grid-column: 3;
  padding: 12px;
  background: var(--primary-bg);
}

.phone-tabs,
.content-tabs {
  display: flex;
  align-items: end;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--panel-bg);
}

.phone-tabs {
  align-items: center;
  padding: 0 4px 5px 4px;
  border-bottom: 1px solid var(--divider);
}

.phone-tab {
  position: relative;
  flex: 0 0 116px;
  height: 33px;
  padding: 3px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-body);
  text-align: left;
}

.phone-tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(22, 119, 255, 0.08);
}

.phone-tab.placeholder {
  background: #f8fafc;
  color: var(--text-secondary);
}

.phone-tab strong,
.phone-tab span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.phone-name-button {
  display: block;
  width: 100%;
  height: 15px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 15px;
  text-align: left;
}

.phone-name-button:hover {
  color: var(--accent);
  text-decoration: underline;
}

.phone-tab.placeholder .phone-name-button {
  cursor: default;
}

.phone-tab.placeholder .phone-name-button:hover {
  color: inherit;
  text-decoration: none;
}

.phone-tab strong {
  font-size: 13px;
  font-weight: 700;
  line-height: 15px;
}

.phone-tab span {
  margin-top: 1px;
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 13px;
}

.phone-tab.online span {
  color: var(--ppg);
}

.phone-tab.online strong::before {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--ppg);
  vertical-align: 2px;
  content: "";
}

.phone-tab.online .phone-name-button::before {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--ppg);
  vertical-align: 2px;
  content: "";
}

.phone-tab.placeholder .phone-name-button::before {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 50%;
  background: #cbd5e1;
  vertical-align: 2px;
  content: "";
}

.content-tabs {
  height: 44px;
  padding-left: 0;
}

.content-tab {
  position: relative;
  flex: 0 0 100px;
  height: 44px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-body);
  font-size: 15px;
}

.content-tab.active {
  color: var(--accent);
  font-weight: 700;
}

.content-tab.active::after {
  position: absolute;
  right: 8px;
  bottom: 0;
  left: 8px;
  height: 2px;
  background: var(--accent);
  content: "";
}

.tab-pane {
  display: none;
  min-height: 0;
  overflow: hidden;
  background: var(--primary-bg);
  padding: 16px;
}

.tab-pane.active {
  display: block;
}

.chart-grid {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 12px;
  width: 100%;
  height: 100%;
}

.chart-card {
  min-height: 0;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
  box-shadow: var(--surface-shadow);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 210px;
  background: #ffffff;
}

.export-layout {
  display: grid;
  grid-template-rows: minmax(0, 1fr) 140px auto;
  width: 100%;
  height: 100%;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--surface-shadow);
}

.pagination-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  padding: 10px 16px;
  background: #f8fafc;
}

.inline-label,
.checkbox-label {
  color: var(--text-body);
  font-size: 14px;
  white-space: nowrap;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: 4px;
}

select,
input {
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-bg);
  color: var(--text-primary);
}

select {
  width: 120px;
}

#gotoPageInput {
  width: 60px;
  padding: 0 7px;
}

.primary-button {
  min-width: 80px;
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.primary-button:hover:not(:disabled) {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
  color: #ffffff;
}

.secondary-button {
  min-width: 80px;
  background: var(--panel-bg);
  color: var(--text-primary);
}

.export-table-wrap {
  min-height: 0;
  background: var(--panel-bg);
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  table-layout: fixed;
  background: var(--panel-bg);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 13px;
}

th {
  height: 72px;
  padding: 8px;
  border-bottom: 1px solid var(--divider);
  background: #f7f9fc;
  color: #27364f;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

td {
  height: 40px;
  padding: 4px 8px;
  border-bottom: 1px solid #eef2f7;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

tbody tr:nth-child(even) td {
  background: #fbfdff;
}

tbody tr.selected td {
  background: var(--accent-soft);
}

tbody tr.clickable:hover td {
  background: #f3f8ff;
}

tbody tr.clickable {
  cursor: pointer;
}

.status-parsed {
  color: var(--ppg);
  font-weight: 700;
}

.status-pending {
  color: var(--orange);
  font-weight: 700;
}

.status-failed {
  color: var(--red);
  font-weight: 700;
}

.export-bottom {
  display: grid;
  grid-template-rows: 60px 80px;
  background: var(--panel-bg);
}

.pagination-row {
  padding: 12px 16px;
  background: var(--panel-bg);
}

#pageInfoLabel {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 140px;
  height: 36px;
  color: var(--accent);
}

.pagination-gap {
  width: 20px;
}

.export-status {
  position: relative;
  padding: 12px 16px;
  background: #f8fafc;
  border-top: 1px solid var(--divider);
  color: var(--text-secondary);
  font-size: 14px;
}

.sample-summary {
  margin-top: 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.parse-error {
  margin-top: 8px;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}

#reparseButton {
  position: absolute;
  top: 12px;
  right: 16px;
}

.raw-details {
  max-height: 180px;
  overflow: auto;
  border-top: 1px solid var(--divider);
  background: var(--panel-bg);
}

.raw-details summary {
  padding: 8px 16px;
  color: var(--text-secondary);
  cursor: pointer;
}

.raw-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.9fr);
  gap: 12px;
  padding: 0 16px 12px 16px;
}

pre {
  min-height: 120px;
  max-height: 260px;
  margin: 0;
  overflow: auto;
  padding: 10px;
  background: var(--log-bg);
  color: #e5e7eb;
  border-radius: 6px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.compact-table {
  max-height: 260px;
}

.compact-table table {
  min-width: 460px;
}

.compact-table th {
  height: 34px;
  font-size: 12px;
}

.compact-table td {
  height: 28px;
  font-size: 12px;
}

.log-shell {
  width: 100%;
  height: 100%;
  background: var(--log-bg);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.12);
}

.event-rows {
  min-height: 0;
  overflow: auto;
  padding: 8px 10px 12px 10px;
  background: var(--log-bg);
  color: var(--log-text);
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.5;
}

.event-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 8px;
  padding: 1px 0;
}

.event-row span {
  min-width: 0;
  overflow: visible;
  white-space: normal;
  overflow-wrap: anywhere;
}

.event-time {
  color: inherit;
}

.event-type {
  color: #facc15;
}

.event-row-saved {
  color: var(--log-text);
}

.event-row-parse_completed {
  color: var(--orange);
}

.event-message.error,
.event-row-parse_failed,
.event-row-rejected,
.event-type.rejected,
.event-type.parse_failed {
  color: #ff453a;
}

.status-bar {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) 100px;
  align-items: center;
  height: 56px;
  padding: 8px 16px;
  border-top: 1px solid var(--divider);
  background: var(--primary-bg);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.28);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  width: 520px;
  max-width: calc(100vw - 48px);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-bg);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.24);
}

.waveform-modal-card {
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr);
  width: min(1180px, calc(100vw - 72px));
  height: min(760px, calc(100vh - 72px));
}

.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--divider);
}

.modal-header h2 {
  margin: 0;
  color: var(--text-primary);
  font-size: 17px;
}

.modal-header p {
  margin: 3px 0 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.modal-close-button {
  width: 32px;
  min-width: 32px;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 22px;
}

.modal-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px 18px;
}

.waveform-modal-body {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 12px;
  min-height: 0;
  padding: 12px;
}

.modal-body label {
  display: grid;
  gap: 6px;
  color: var(--text-body);
  font-size: 13px;
}

.modal-body label:first-child,
.modal-body label:nth-child(4),
.modal-body label:nth-child(5),
.readonly-info {
  grid-column: 1 / -1;
}

.modal-body input {
  width: 100%;
  padding: 0 9px;
}

.readonly-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  padding: 12px;
  border: 1px solid var(--divider);
  border-radius: 8px;
  background: #f8fafc;
}

.readonly-info div {
  min-width: 0;
}

.readonly-info span,
.readonly-info strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.readonly-info span {
  color: var(--text-secondary);
  font-size: 12px;
}

.readonly-info strong {
  margin-top: 2px;
  color: var(--text-primary);
  font-size: 13px;
}

.modal-footer {
  border-top: 1px solid var(--divider);
  border-bottom: 0;
}

#phoneInfoMessage {
  flex: 1;
  color: var(--text-secondary);
  font-size: 13px;
}

#phoneInfoMessage.error {
  color: var(--red);
}

#phoneInfoMessage.success {
  color: var(--ppg);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--text-body);
  font-size: 14px;
}

#statusText {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.connection-dot {
  color: var(--text-secondary);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

.connection-dot.connected {
  color: var(--ppg);
}

.connection-dot.disconnected {
  color: var(--red);
}

.data-stats {
  overflow: hidden;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.current-time {
  color: var(--text-body);
  font-size: 14px;
  text-align: right;
}

@media (max-width: 1100px) {
  .main-split {
    grid-template-columns: minmax(560px, 1fr) 5px minmax(300px, 0.85fr);
  }

  .phone-tab {
    flex-basis: 99px;
  }
}
