:root {
  color-scheme: light;
  --bg: #f3f4f1;
  --paper: #ffffff;
  --ink: #1a1c19;
  --muted: #5c615c;
  --line: #e1e3dc;
  --line-strong: #c5c8c0;
  --accent: #114e4a;
  --danger: #8f2d2d;
  --font: "Microsoft YaHei", "微软雅黑", "PingFang SC", sans-serif;
  --mono: "Microsoft YaHei", "微软雅黑", "PingFang SC", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
}
body:has(#app[hidden]) { background: #fff; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: #d5e6e2; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#login[hidden], #app[hidden] { display: none !important; }
#login { min-height: 100vh; display: flex; flex-direction: column; background: transparent; }

.mast {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--ink);
  background: rgba(255, 255, 255, 0.9);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.foot { margin-top: auto; border-bottom: 0; border-top: 1px solid var(--line-strong); }

.login-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(360px, calc(100% - 48px));
  margin: 0 auto;
  padding: 32px 0;
}
.eyebrow {
  margin: 0 0 12px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--accent);
}
h1 {
  margin: 0;
  font-size: 44px;
  line-height: 1.15;
  font-weight: 600;
  letter-spacing: -0.03em;
}
.lede { max-width: 38em; color: var(--muted); font-size: 16px; }
.roles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; margin: 28px 0 0; }
.roles div { border-top: 1px solid var(--line-strong); padding-top: 8px; }
.roles dt { font-weight: 600; }
.roles dd { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.panel-card, dialog {
  background: var(--paper);
  border: 1px solid var(--ink);
  padding: 22px;
}
#login .panel-card {
  width: 100%;
  background: transparent;
  border: 0;
  padding: 0;
}
.login-mark {
  display: block;
  width: 72px;
  height: 72px;
  margin: 0 auto 4px;
}
.panel-card { display: grid; gap: 14px; }
.card-kicker {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--muted);
}
.field { display: grid; gap: 6px; }
.field > span, .form .k {
  font-family: var(--font);
  font-size: 12px;
  letter-spacing: 0;
  color: var(--muted);
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: white;
  padding: 8px 10px;
  border-radius: 0;
}
textarea { min-height: 84px; resize: vertical; }
button.primary, button.ghost, button.danger {
  min-height: 36px;
  padding: 7px 14px;
  border-radius: 0;
}
button.primary { background: var(--accent); color: white; border: 1px solid var(--accent); }
button.ghost { background: white; border: 1px solid var(--line-strong); }
button.danger { background: white; color: var(--danger); border: 1px solid #e4c8c8; }
button.slim { min-height: 30px; padding: 4px 10px; font-size: 13px; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
.alert {
  margin: 0;
  border: 1px solid #e4c8c8;
  background: #fbf7f7;
  color: var(--danger);
  padding: 8px 10px;
  font-size: 13px;
}
.alert:empty { display: none; }
.status { color: var(--muted); }

.app-header { background: white; border-bottom: 1px solid var(--ink); }
#topbar, #tabs { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 24px; }
#topbar { min-height: 58px; }
.brand { display: flex; align-items: baseline; gap: 16px; min-width: 0; }
.mark { font-family: var(--mono); font-size: 12px; letter-spacing: 0.14em; }
.labline { font-weight: 600; }
.who { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.role {
  border: 1px solid var(--line-strong);
  padding: 2px 8px;
  font-family: var(--mono);
  font-size: 12px;
}
#tabs { min-height: 44px; justify-content: flex-start; gap: 4px; border-top: 1px solid var(--line); }
.tab {
  appearance: none;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  min-height: 44px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}
.tab.on { color: var(--ink); border-bottom-color: var(--accent); }
.idx { font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em; }

#panel { padding: 18px 24px 48px; }
.toolbar { display: flex; justify-content: space-between; gap: 12px 20px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar h2 { margin: 0; font-size: 20px; font-weight: 600; }
.toolbar h2.month { font-size: 28px; font-weight: 600; letter-spacing: 0.02em; }
.hint { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); background: white; }
.seg button { border: 0; background: transparent; min-height: 32px; }
.seg button.on { background: var(--ink); color: white; }

.legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; padding: 0; }
.legend button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line-strong);
  background: white;
  min-height: 0;
  padding: 4px 8px;
  font-size: 12px;
}
.legend button.on { border-color: var(--ink); }
.swatch { width: 10px; height: 10px; display: inline-block; flex: none; background: var(--cell, #c5c8c0); }
.c0 { --cell: #c4622d; }
.c1 { --cell: #1f6a8a; }
.c2 { --cell: #2f6b4f; }
.c3 { --cell: #8c3d55; }
.c4 { --cell: #6e5a2e; }
.c5 { --cell: #3e4e86; }
.c6 { --cell: #0f6e6a; }
.c7 { --cell: #a15c38; }

.grid-scroll {
  overflow-x: hidden;
  overflow-y: auto;
  max-height: calc(100vh - 248px);
  max-width: 100%;
  border: 1px solid var(--line-strong);
  background: white;
}
.sheet { border-collapse: separate; border-spacing: 0; width: 100%; table-layout: fixed; }
.sheet th, .sheet td {
  box-shadow: inset -1px -1px 0 var(--line);
  background-clip: padding-box;
  padding: 0;
  font-weight: 400;
  text-align: center;
}
.sheet thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f6f6f3;
  min-width: 0;
  height: 36px;
}
.sheet .equip {
  position: sticky;
  left: 0;
  z-index: 2;
  width: 168px;
  background: white;
  text-align: left;
}
.sheet thead th.equip { z-index: 4; background: #f3f4f1; width: 168px; padding: 0; text-align: left; }
.eq-head { justify-content: flex-start; }
.sheet thead th.equip .eq-name { text-align: left; }
.dow, .dom { display: block; line-height: 1.15; }
.dow { font-size: 11px; color: var(--muted); }
.dom { font-size: 12px; font-weight: 600; }
.sheet thead th.weekend { background: #f7f7f4; }
.sheet thead th.today { background: #e7f1ee; }
.sheet thead th.today .dom { color: var(--accent); }
.eq-code, .eq-name {
  font-size: 13px;
  font-weight: 400;
  font-synthesis: none;
  line-height: 32px;
}
.eq-code {
  flex: 0 0 2ch;
  width: 2ch;
  min-width: 2ch;
  max-width: 2ch;
  font-variant-numeric: tabular-nums;
  text-align: left;
  color: var(--muted);
  white-space: nowrap;
}
.eq-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
th.equip .eq, td.equip .eq {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 8px;
  overflow: hidden;
}
td.group {
  background: #eef0ec;
  text-align: left;
  height: 22px;
  padding: 0;
  font-size: 12px;
  color: var(--muted);
}
.group-label { position: sticky; left: 8px; display: inline-block; line-height: 22px; }
td.slot { background: white; height: 32px; position: relative; }
td.slot.weekend { background: #f7f7f4; }
td.slot.today { background: #eef4f2; }
td.slot.booked {
  background: color-mix(in srgb, var(--cell) 22%, white);
  box-shadow: inset 3px 0 0 var(--cell), inset -1px -1px 0 var(--line);
}
td.slot.booked.faded {
  background: #f3f4f1;
  box-shadow: inset 3px 0 0 #c5c8c0, inset -1px -1px 0 var(--line);
}
td.slot.booked.faded .slot-name { color: #8b8f88; }
.slot-btn {
  appearance: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 6px;
}
.slot.can .slot-btn { color: #c5c8c0; justify-content: center; font-size: 14px; padding: 0; }
.slot.can:hover .slot-btn, .slot.can .slot-btn:focus-visible { color: var(--accent); }
.slot-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
}

.frame { border: 1px solid var(--line-strong); background: white; overflow: auto; }
table.data { width: 100%; border-collapse: collapse; background: white; table-layout: fixed; }
table.data col.col-project { width: 16%; }
table.data col.col-stage { width: 96px; }
table.data col.col-date { width: 120px; }
table.data col.col-count { width: 76px; }
table.data col.col-files { width: 36%; }
table.data col.col-ops { width: 96px; }
table.data th, table.data td {
  border-bottom: 1px solid var(--line);
  padding: 8px 12px;
  text-align: left;
  vertical-align: middle;
}
table.data th {
  background: #f6f6f3;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}
table.data .nowrap { white-space: nowrap; }
.name-line { display: flex; align-items: center; gap: 8px; font-weight: 600; min-height: 28px; }
.notes { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.files { display: grid; gap: 2px; margin: 0 0 6px; }
.file-row { display: flex; align-items: center; justify-content: flex-start; gap: 12px; min-height: 28px; }
.file-row a { flex: 1; min-width: 0; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload { display: flex; align-items: center; gap: 8px; min-height: 28px; }
.file-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  background: white;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.file-btn input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
.file-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}
.name-line span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; align-items: center; flex-wrap: nowrap; gap: 12px; min-height: 28px; }
.linkish { border: 0; background: none; padding: 0; min-height: 0; color: var(--accent); }
.linkish.danger { color: var(--danger); }
.section { margin-top: 28px; }
.section h2 { margin: 0 0 8px; font-size: 18px; }
.section-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 8px; }
.summary { margin: 0; color: var(--muted); font-size: 13px; }

dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: auto;
  padding: 0;
}
dialog::backdrop { background: rgba(26, 28, 25, 0.35); }
.form { display: grid; gap: 12px; padding: 18px; }
.form h3 { margin: 0; font-size: 18px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.kv { display: grid; grid-template-columns: 88px 1fr; gap: 6px 10px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.actions { display: flex; justify-content: flex-end; gap: 8px; }
.noscript { padding: 16px 24px; }

@media (max-width: 800px) {
  .login-main { width: min(100% - 32px, 360px); padding-top: 24px; }
  h1 { font-size: 34px; }
  .roles { grid-template-columns: 1fr; }
  #topbar, #tabs, #panel { padding-left: 14px; padding-right: 14px; }
  .grid-scroll { max-height: calc(100vh - 300px); }
  .kv { grid-template-columns: 72px 1fr; }
}
@media print {
  .mast, #tabs, .tools, .no-print, dialog { display: none !important; }
  body, .grid-scroll { background: white; }
  .grid-scroll { max-height: none; overflow: visible; border: 0; }
  .sheet .equip, .sheet thead th { position: static; }
}
