/* ============ 多国节假日日历 ============ */

:root {
  --bg: #f4f6f9;
  --bg-soft: #eef1f6;
  --panel: #ffffff;
  --border: #e3e7ee;
  --border-strong: #cfd5df;
  --text: #16191f;
  --text-2: #3d444f;
  --muted: #7b8794;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, .1);
  --weekend: #f7f8fa;
  --holiday-bg: #fffdf7;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 14px;
  --radius-sm: 9px;
}

[data-theme="dark"] {
  --bg: #0e1116;
  --bg-soft: #141922;
  --panel: #171c24;
  --border: #262d38;
  --border-strong: #333c4a;
  --text: #e7eaef;
  --text-2: #c3cbd6;
  --muted: #8d97a5;
  --accent: #6aa1ff;
  --accent-soft: rgba(106, 161, 255, .16);
  --weekend: #12161d;
  --holiday-bg: #1b1a15;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: .01em; }

/* ---------- 布局 ---------- */
.app {
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr);
  gap: 18px;
  max-width: 1560px;
  margin: 0 auto;
  padding: 18px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: calc(100vh - 36px);
  overflow: auto;
  scrollbar-width: thin;
}

.main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  overflow: hidden;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 14px;
}

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.panel-head h2 { font-size: 13px; color: var(--text-2); }

.brand { display: flex; gap: 11px; align-items: center; padding: 2px 4px 0; }
.brand .logo { font-size: 26px; line-height: 1; }
.brand h1 { font-size: 17px; }
.brand .sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

/* ---------- 地区选择 ---------- */
.mini-actions { display: flex; gap: 6px; }
.mini, .preset, .btn {
  font: inherit; font-size: 12px;
  border: 1px solid var(--border-strong);
  background: var(--bg-soft);
  color: var(--text-2);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  transition: .15s;
}
.mini:hover, .preset:hover, .btn:hover { border-color: var(--accent); color: var(--accent); }
.btn { border-radius: var(--radius-sm); padding: 6px 12px; font-size: 13px; background: var(--panel); }
.btn.ghost { border-color: transparent; background: transparent; padding: 6px 8px; font-size: 15px; }

.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.preset { font-size: 11.5px; padding: 3px 9px; }

.region-list { display: flex; flex-direction: column; gap: 2px; }
.region {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: var(--radius-sm);
  cursor: pointer; user-select: none;
  transition: background .12s;
}
.region:hover { background: var(--bg-soft); }
.region.on { background: var(--accent-soft); }
.region input { accent-color: var(--c); margin: 0; cursor: pointer; }
.region .swatch { width: 9px; height: 9px; border-radius: 3px; background: var(--c); flex: none; opacity: .45; }
.region.on .swatch { opacity: 1; }
.region .rf { font-size: 15px; line-height: 1; }
.region .rz { font-size: 13.5px; color: var(--text-2); }
.region.on .rz { color: var(--text); font-weight: 600; }
.region .re { font-size: 11px; color: var(--muted); margin-left: auto; }

.opt { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.opt input { accent-color: var(--accent); }
.hint { margin: 8px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.panel.foot .hint { margin-top: 4px; }

/* ---------- 工具条 ---------- */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 12px;
}
.nav { display: flex; align-items: center; gap: 8px; }
.nav-btn { font-size: 17px; padding: 4px 12px; line-height: 1.2; }
.ym { display: flex; gap: 6px; }
.ym select {
  font: inherit; font-size: 14px; font-weight: 600;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  cursor: pointer;
}
.tool-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.summary { font-size: 12.5px; color: var(--muted); }
.summary b { color: var(--text); }
.dot-sep { opacity: .5; margin: 0 4px; }

/* ---------- 日历 ---------- */
.cal { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.cal-row { display: grid; grid-template-columns: 54px repeat(7, minmax(0, 1fr)); }
.cal-row + .cal-row { border-top: 1px solid var(--border); }

.cell { border-right: 1px solid var(--border); min-width: 0; }
.cell:last-child { border-right: none; }

.cal-head { background: var(--bg-soft); }
.cal-head .cell {
  text-align: center; font-size: 12px; font-weight: 600;
  color: var(--text-2); padding: 8px 0; border-right-color: var(--border);
}
.cal-head .cell-we { color: var(--muted); }
.cal-head .weekno { font-size: 11px; color: var(--muted); }

.day {
  min-height: 98px;
  padding: 5px 6px 6px;
  display: flex; flex-direction: column; gap: 4px;
  background: var(--panel);
  position: relative;
}
.day.is-weekend { background: var(--weekend); }
.day.is-out { opacity: .34; }
.day.has-holiday { background: var(--holiday-bg); }
.day.is-overlap {
  background: var(--holiday-bg);
  box-shadow: inset 0 0 0 1.5px var(--accent);
}
.day.is-today .dnum {
  background: var(--accent); color: #fff; border-radius: 6px;
  padding: 1px 6px; margin: -1px -3px;
}

.d-top { display: flex; align-items: center; gap: 4px; min-height: 20px; }
.dnum { font-size: 13px; font-weight: 650; color: var(--text-2); font-variant-numeric: tabular-nums; }
.day.can-month .dnum { color: var(--text); }
.dtag { font-size: 10px; color: var(--accent); }

.chips { display: flex; flex-direction: column; gap: 3px; overflow: hidden; }
.chip {
  display: flex; align-items: center; gap: 4px;
  font-size: 11px; line-height: 1.35;
  padding: 2px 5px;
  border-radius: 6px;
  background: var(--bg-soft);
  color: var(--text-2);
  border-left: 2px solid var(--c, var(--border-strong));
  max-width: 100%;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.chip .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--c); flex: none; }
.chip .flag { font-size: 11px; flex: none; }
.chip .nm { overflow: hidden; text-overflow: ellipsis; }
.chip.t-public { background: color-mix(in srgb, var(--c) 13%, transparent); color: var(--text); font-weight: 550; }
.chip.t-bank { background: color-mix(in srgb, var(--c) 8%, transparent); }
.chip.t-optional { background: var(--bg-soft); opacity: .9; }
.chip.t-observance { background: transparent; border-left-color: var(--border-strong); color: var(--muted); }
.chip.t-workday { background: repeating-linear-gradient(45deg, var(--bg-soft), var(--bg-soft) 4px, transparent 4px, transparent 8px); color: var(--muted); }
.chip.more { background: transparent; color: var(--muted); border-left-color: transparent; font-size: 10.5px; }

.weekno { display: flex; align-items: center; justify-content: center; background: var(--bg-soft); }
.weekno .wn { font-size: 12px; font-weight: 650; color: var(--muted); font-variant-numeric: tabular-nums; }
.cal-row:not(.cal-head) .weekno { background: var(--bg-soft); }

/* ---------- 统计 ---------- */
.stats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.stats li { display: grid; grid-template-columns: 96px 1fr 40px; align-items: center; gap: 8px; font-size: 12px; }
.stats .sname { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats .sbar { height: 7px; background: var(--bg-soft); border-radius: 999px; overflow: hidden; }
.stats .sbar i { display: block; height: 100%; background: var(--c); border-radius: 999px; transition: width .3s; }
.stats .snum { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- 分栏 ---------- */
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.ct { font-size: 13px; color: var(--text-2); margin-bottom: 10px; display: flex; align-items: center; gap: 6px; }
.ct::before { content: ""; width: 3px; height: 13px; border-radius: 2px; background: var(--accent); }

.runs, .overlaps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow: auto; }
.runs li, .overlaps li {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 7px 9px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 12.5px;
}
.runs b { font-variant-numeric: tabular-nums; }
.pill { font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.pill.alt { background: var(--bg-soft); color: var(--muted); border: 1px solid var(--border); }
.overlaps .od { font-weight: 650; font-variant-numeric: tabular-nums; min-width: 74px; }

.tag-region {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; padding: 1px 7px; border-radius: 999px;
  background: color-mix(in srgb, var(--c) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
  color: var(--text-2); white-space: nowrap;
}
.empty { margin: 0; font-size: 12.5px; color: var(--muted); padding: 6px 2px; }

/* ---------- 清单表 ---------- */
.htable { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.htable th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 11.5px;
  padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.htable td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.htable tr:last-child td { border-bottom: none; }
.htable .td-date { font-variant-numeric: tabular-nums; white-space: nowrap; }
.htable .td-date b { font-size: 13px; }
.htable .td-wd { color: var(--muted); white-space: nowrap; }
.htable .td-name { color: var(--text); }
.htable .sub { display: block; font-size: 11px; color: var(--muted); }
.htable .td-note { color: var(--muted); font-size: 11.5px; }
.htable tr.row-work { background: var(--bg-soft); }
.htable tr.row-work .td-name { color: var(--muted); text-decoration: line-through; }
.tt { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--bg-soft); color: var(--muted); white-space: nowrap; }
.tt.t-public { background: var(--accent-soft); color: var(--accent); }
.tt.t-bank { background: var(--bg-soft); color: var(--text-2); }
.tt.t-workday { background: var(--bg-soft); color: var(--muted); }

.site-foot { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); padding: 0 4px 8px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  font-size: 12.5px; padding: 8px 16px; border-radius: 999px;
  box-shadow: var(--shadow); z-index: 99; opacity: .96;
}

/* ---------- 加载态 ---------- */
.cal.loading { opacity: .45; transition: opacity .15s; }

/* ---------- 响应式 ---------- */
@media (max-width: 1080px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; }
  .cols { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .app { padding: 10px; gap: 12px; }
  .card { padding: 10px; }
  .cal { overflow-x: auto; }
  .cal-row { min-width: 660px; }
  .day { min-height: 84px; }
  .toolbar { padding: 8px; }
  .summary { display: none; }
}

/* ---------- 数据状态 / 刷新 ---------- */
.badge { font-size: 11px; padding: 1px 8px; border-radius: 999px; font-weight: 600; }
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: rgba(234, 179, 8, 0.16); color: #b45309; }

.srcbox { margin: 6px 0 0; }
.srcbox > summary { cursor: pointer; font-size: 12px; color: var(--muted); padding: 2px 0; user-select: none; }
.srcbox > summary:hover { color: var(--fg); }
.src-list { list-style: none; margin: 6px 0 0; padding: 0; max-height: 190px; overflow: auto; }
.src-list li {
  display: flex; gap: 6px; align-items: baseline; font-size: 11px; line-height: 1.5;
  padding: 3px 0; border-top: 1px dashed var(--border);
}
.src-list li b { flex: 0 0 62px; font-weight: 600; }
.src-list li span { color: var(--muted); word-break: break-all; }

.refresh-btn { width: 100%; margin-top: 10px; justify-content: center; }
.refresh-btn.busy { opacity: 0.6; cursor: progress; }
.diag-btn { width: 100%; margin-top: 6px; justify-content: center; font-size: 12px; color: var(--text-2); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--border); color: inherit; }

.hint.bad { color: #DC2626; font-weight: 600; }
[data-theme="dark"] .hint.bad { color: #ff8f8f; }

.diag-out {
  margin: 8px 0 0; padding: 8px 10px; max-height: 320px; overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10.5px; line-height: 1.6; white-space: pre-wrap; word-break: break-all;
  color: var(--text-2); background: var(--bg-soft);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}

.panel.foot code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px; padding: 0.5px 5px; border-radius: 4px;
  background: var(--accent-soft);
}
.perm { margin-top: 10px; }
.perm-ok { color: #16A34A; font-weight: 600; }
.perm-no { color: #D97706; font-weight: 600; }

/* ---------- 打印 ---------- */
@media print {
  .sidebar, .tool-right, .toast { display: none !important; }
  .app { grid-template-columns: 1fr; padding: 0; }
  .card, .panel { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .day { min-height: 76px; }
  body { background: #fff; }
}
