/* 公共样式 —— 主控维护。页面 agent 只读不改。布局写 layout.css，页面专属写 pages.css */
:root {
  --bg: #F6F4F0;
  --surface: #FFFFFF;
  --surface-2: #FBF9F6;
  --text: #2B2B2B;
  --text-2: #5F5A55;
  --muted: #8A8580;
  --line: #ECE6DD;
  --accent: #FF7A45;
  --accent-ink: #D9551E;     /* 品牌色上的文字/链接用，对比度更够 */
  --accent-soft: #FFF0E8;
  --success: #1E8E4E; --success-soft: #E6F5EC;
  --danger: #D23F3A;  --danger-soft: #FDECEA;
  --warning: #B7791F; --warning-soft: #FDF3E1;
  --chart-1: #E8642C;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161514; --surface: #201E1C; --surface-2: #262321; --text: #EDE8E2; --text-2: #C4BDB5; --muted: #9A938B;
    --line: #34302C; --accent-ink: #FF9466; --accent-soft: #3A2A22;
    --success: #4CC27E; --success-soft: #1D3326; --danger: #F0716C; --danger-soft: #3A2222; --warning: #E5B04A; --warning-soft: #3A3020;
    --chart-1: #E06A35; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161514; --surface: #201E1C; --surface-2: #262321; --text: #EDE8E2; --text-2: #C4BDB5; --muted: #9A938B;
  --line: #34302C; --accent-ink: #FF9466; --accent-soft: #3A2A22;
  --success: #4CC27E; --success-soft: #1D3326; --danger: #F0716C; --danger-soft: #3A2222; --warning: #E5B04A; --warning-soft: #3A3020;
  --chart-1: #E06A35; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.35; }
h1 { font-size: 20px; } h3 { font-size: 15px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* 表单控件 */
input, select, textarea, button { font: inherit; color: inherit; }
.input, input[type=text], input[type=password], input[type=search], input[type=email], input[type=tel], input[type=number],
input[type=datetime-local], input[type=date], input[type=time], select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); outline: none; min-height: 36px;
}
/* 手机：输入框字号 ≥16px，否则 iPhone 一点输入框页面就自动放大；按钮和输入框加高，手指好点 */
@media (max-width: 640px) {
  .input, input[type=text], input[type=password], input[type=search], input[type=email], input[type=tel], input[type=number],
  input[type=datetime-local], input[type=date], input[type=time], select, textarea { font-size: 16px; min-height: 42px; }
  .btn:not(.btn-sm) { min-height: 40px; }
}
/* 下拉框统一自绘箭头：iOS / 安卓原生箭头宽度不一，窄屏上会挡住文字 */
select {
  -webkit-appearance: none; appearance: none; padding-right: 30px; text-overflow: ellipsis; white-space: nowrap; overflow: hidden;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%238b8b8b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 12px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; line-height: 1.7; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-label { font-size: 13px; color: var(--text-2); }
.field-hint { font-size: 12px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 16px; }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  padding: 0 14px; height: 36px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: #F06A35; color: #fff; }
.btn-danger { color: var(--danger); }
.btn-danger:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 6px 8px; border-radius: 8px; font-size: 16px; line-height: 1; color: var(--text-2); }
.icon-btn:hover { background: var(--surface-2); }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent-ink); cursor: pointer; font-size: 13px; }

/* 页头 / 卡片 */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head p { margin-top: 4px; font-size: 13px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 14px 16px 0; }
.card-body { padding: 14px 16px 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar > input, .toolbar > select { width: auto; min-width: 120px; }
.toolbar .grow { flex: 1; min-width: 160px; }

/* 数字卡片 */
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
@media (max-width: 900px) { .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.stat-label { font-size: 13px; color: var(--text-2); }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1.3; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat-danger .stat-value { color: var(--danger); }
.stat-success .stat-value { color: var(--success); }
.stat-accent .stat-value { color: var(--accent-ink); }

/* 徽标 / 圆点 */
.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 99px; font-size: 12px; white-space: nowrap; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line); }
.badge-accent { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
.badge-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-muted { color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* 分段切换 */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 4px 12px; border-radius: 7px; cursor: pointer; color: var(--text-2); font-size: 13px; }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* 表格 */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 10px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-weight: 600; color: var(--text-2); background: var(--surface-2); white-space: nowrap; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table .col-check { width: 36px; }
.table-empty { text-align: center; color: var(--muted); padding: 32px 12px !important; }
.table-compact th, .table-compact td { padding: 6px 10px; }
.table caption { caption-side: top; text-align: left; color: var(--muted); font-size: 12px; padding-bottom: 6px; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 12px; flex-wrap: wrap; font-size: 13px; }

/* 空状态 / 加载 */
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.empty-icon { font-size: 32px; margin-bottom: 6px; }
.empty .btn { margin-top: 12px; }
.loading { display: flex; align-items: center; gap: 8px; justify-content: center; color: var(--muted); padding: 32px; }
.spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 弹窗 */
.modal { border: 0; border-radius: 16px; padding: 0; width: min(520px, calc(100% - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal::backdrop { background: rgba(0,0,0,.35); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 0; }
.modal-body { padding: 16px 20px; max-height: 70vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 18px; }

/* 提示 */
.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translate(-50%, 20px); z-index: 1000; opacity: 0; pointer-events: none;
  background: #2B2B2B; color: #fff; padding: 10px 18px; border-radius: 99px; font-size: 14px; max-width: calc(100% - 32px); width: max-content;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-success { background: #1E6E40; }
.toast-error { background: #A8322E; }

/* 图表 */
.chart-block { min-width: 0; }
.chart { position: relative; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-axis { stroke: var(--muted); stroke-width: 1; opacity: .6; }
.chart-tick { fill: var(--muted); font-size: 11px; }
.chart-bar { fill: var(--chart-1); }
.chart-hit { fill: transparent; cursor: pointer; }
.chart-hit:hover { fill: var(--text); fill-opacity: .04; }
.chart-tip { position: absolute; z-index: 5; pointer-events: none; background: var(--text); color: var(--surface); font-size: 12px; padding: 5px 9px; border-radius: 6px; white-space: nowrap; }
.chart-foot { display: flex; justify-content: flex-end; margin-top: 4px; }
.hbar-list { display: flex; flex-direction: column; gap: 10px; }
.hbar-row { display: grid; grid-template-columns: minmax(80px, 30%) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.hbar-label { display: flex; align-items: center; gap: 6px; min-width: 0; }
.hbar-label span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 10px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--chart-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar-value { font-variant-numeric: tabular-nums; color: var(--text-2); }
