:root {
  --bg: #000000;
  --bg-elevated: #1c1c1e;
  --bg-card: #2c2c2e;
  --bg-hover: #3a3a3c;
  --line: #38383a;
  --text: #f5f5f7;
  --text-secondary: #a1a1a6;
  --text-tertiary: #6e6e73;
  --accent: #0a84ff;
  --accent-press: #0071e3;
  --ok: #30d158;
  --warn: #ffd60a;
  --danger: #ff453a;
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  max-width: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap {
  width: min(1200px, calc(100% - 40px));
  max-width: 100%;
  margin: 0 auto;
  padding: 28px 0 48px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 16px;
}
.topbar .brand {
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: 0 0 4px;
}
.topbar h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 980px;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  color: var(--text-secondary);
  font-size: 13px;
}
.pill.ok { color: var(--ok); }
.pill.warn { color: var(--warn); }
.pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.grid {
  display: grid;
  gap: 16px;
  min-width: 0;
  max-width: 100%;
}
.grid > * {
  min-width: 0;
  max-width: 100%;
}
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}
.card h2 {
  margin: 0 0 14px;
  font-size: 17px;
  font-weight: 600;
}
.card h3 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
}
.muted { color: var(--text-secondary); font-size: 13px; }
.stat-label {
  color: var(--text-secondary);
  font-size: 12px;
  margin-bottom: 8px;
}
.stat-value {
  font-size: 28px;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.progress {
  height: 6px;
  background: var(--bg-card);
  border-radius: 100px;
  overflow: hidden;
  margin-top: 10px;
}
.progress > span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 100px;
  transition: width 0.25s ease;
}

.chat-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.chat-card .id {
  color: var(--text-tertiary);
  font-size: 12px;
  margin-top: 4px;
}

.list {
  max-height: 360px;
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  min-width: 0;
  max-width: 100%;
}
.list-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.list-item:last-child { border-bottom: 0; }
.list-item .meta {
  color: var(--text-tertiary);
  font-size: 12px;
  margin-bottom: 4px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

label {
  display: block;
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 6px;
}
input, select, textarea {
  width: 100%;
  background: #000;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.25);
}
textarea { min-height: 88px; resize: vertical; }

.row { margin-bottom: 12px; }
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
}

button, .btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--text);
  border-radius: 980px;
  padding: 9px 16px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
button:hover, .btn:hover { background: var(--bg-hover); }
button.primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}
button.primary:hover { background: var(--accent-press); }
button.danger {
  background: rgba(255, 69, 58, 0.15);
  border-color: rgba(255, 69, 58, 0.35);
  color: #ff8a80;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
}
.checks label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  margin: 0;
}
.checks input { width: auto; }

.table-wrap {
  overflow: auto;
  max-height: 360px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  word-break: break-all;
}
th {
  position: sticky;
  top: 0;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-weight: 600;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}
.form-grid .full { grid-column: 1 / -1; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.login-card h1 {
  margin: 0 0 8px;
  font-size: 24px;
  letter-spacing: -0.02em;
}
.hint {
  color: var(--text-secondary);
  font-size: 13px;
  min-height: 1.2em;
  margin: 8px 0 0;
}
.nav-links {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* 仪表盘通用 */
.page-dashboard,
.page-dashboard .wrap,
.page-dashboard .dash-lists,
.page-dashboard .dash-main {
  max-width: 100%;
  min-width: 0;
}
.dash-line {
  margin: 6px 0 12px;
  font-size: 15px;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.dash-file {
  margin-bottom: 8px;
  line-height: 1.4;
}
.page-dashboard .list-item,
.page-dashboard .list-item div {
  word-break: break-word;
  overflow-wrap: anywhere;
  max-width: 100%;
}

@media (max-width: 960px) {
  .wrap {
    width: min(1200px, calc(100% - 28px));
    padding: 20px 0 36px;
  }
  .grid-3, .grid-2, .form-grid { grid-template-columns: 1fr; }
  /* 统计卡保持 2×2，避免手机上一列四张过高 */
  .grid-4, .dash-stats { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .chat-grid { grid-template-columns: 1fr; }
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .nav-links {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }
  .topbar h1 { font-size: 24px; }
  .stat-value { font-size: 22px; }
  .card { padding: 14px; }
  .list { max-height: 280px; }
}

@media (max-width: 560px) {
  .wrap {
    width: calc(100% - 20px);
    padding: 14px 0 calc(28px + env(safe-area-inset-bottom, 0px));
  }
  .dash-stats { gap: 10px; }
  .grid { gap: 12px; }
  .topbar { margin-bottom: 16px; }
  .topbar .brand {
    font-size: 11px;
    letter-spacing: 0.04em;
  }
  .topbar h1 { font-size: 22px; }
  .nav-links .btn,
  .nav-links .pill {
    flex: 1 1 auto;
    justify-content: center;
    text-align: center;
    min-height: 40px;
  }
  .nav-links .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .stat-label { font-size: 11px; margin-bottom: 6px; }
  .stat-value { font-size: 20px; }
  .card h2 { font-size: 16px; margin-bottom: 10px; }
  .dash-line { font-size: 14px; }
  .dash-round { font-size: 12px; line-height: 1.5; }
  .list { max-height: 240px; -webkit-overflow-scrolling: touch; }
  .list-item { padding: 10px; font-size: 12px; }
  .muted, .hint { font-size: 12px; }
  /* 相位文字可能较长，避免撑破卡片 */
  #stPhase {
    font-size: 18px;
    line-height: 1.25;
    word-break: break-word;
  }
}

@media (max-width: 380px) {
  .dash-stats { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 18px; }
}
