:root {
  --bg: #f4f6f7;
  --panel: #ffffff;
  --line: #d9e0e4;
  --line-strong: #b7c4cb;
  --text: #1b2428;
  --muted: #66757e;
  --soft: #eef3f4;
  --accent: #0f766e;
  --accent-weak: #d9f0ed;
  --warning: #b45309;
  --warning-weak: #fff4d6;
  --danger: #b42318;
  --danger-weak: #fee4df;
  --early: #d9f0ed;
  --middle: #e4ecff;
  --night: #e8e2ff;
  --off: #edf0f2;
  --shadow: 0 18px 40px rgba(38, 56, 64, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
select,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.app-shell {
  height: 100dvh;
  display: grid;
  grid-template-rows: 72px minmax(0, 1fr);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 260px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.2;
}

h2 {
  font-size: 14px;
  line-height: 1.2;
}

.brand p,
.schedule-tools p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.toolbar,
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.select-field {
  height: 42px;
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 6px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

.select-field select {
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 13px;
}

.primary-btn,
.secondary-btn,
.icon-btn,
.mini-btn,
.brush,
.filter,
.quick-editor button {
  min-height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  white-space: nowrap;
}

.primary-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.icon-btn {
  width: 34px;
  padding: 0;
  font-size: 18px;
}

.mini-btn {
  min-height: 28px;
  padding: 0 9px;
  color: var(--accent);
}

button:active {
  transform: translateY(1px);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 340px minmax(560px, 1fr) 286px;
  gap: 12px;
  padding: 12px;
}

.workspace.left-collapsed {
  grid-template-columns: 40px minmax(560px, 1fr) 286px;
}

.workspace.right-collapsed {
  grid-template-columns: 340px minmax(560px, 1fr) 40px;
}

.workspace.left-collapsed.right-collapsed {
  grid-template-columns: 40px minmax(560px, 1fr) 40px;
}

.panel,
.schedule-panel {
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.left-panel,
.right-panel {
  overflow: auto;
  padding: 14px;
  position: relative;
}

.panel-collapse {
  position: sticky;
  top: 0;
  z-index: 10;
  width: 26px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--accent);
  font-size: 18px;
  font-weight: 700;
}

.left-collapse {
  float: right;
  margin: -4px -4px 8px 8px;
}

.right-collapse {
  float: left;
  margin: -4px 8px 8px -4px;
}

.workspace.left-collapsed .left-panel,
.workspace.right-collapsed .right-panel {
  padding: 8px 6px;
  overflow: hidden;
}

.workspace.left-collapsed .left-panel section,
.workspace.right-collapsed .right-panel section {
  display: none;
}

.workspace.left-collapsed .left-collapse,
.workspace.right-collapsed .right-collapse {
  float: none;
  margin: 0 auto;
}

.workspace.left-collapsed .left-collapse,
.workspace.right-collapsed .right-collapse {
  font-size: 0;
}

.workspace.left-collapsed .left-collapse::before {
  content: "›";
  font-size: 18px;
}

.workspace.right-collapsed .right-collapse::before {
  content: "‹";
  font-size: 18px;
}

.left-panel section + section,
.right-panel section + section {
  margin-top: 14px;
}

.panel-heading,
.schedule-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.employee-list {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.employee-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.employee-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.employee-title strong {
  font-size: 13px;
}

.employee-title span {
  color: var(--muted);
  font-size: 11px;
}

.employee-config-grid {
  margin-top: 9px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.employee-config-grid label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
}

.employee-config-grid label:first-child {
  grid-column: 1 / -1;
}

.employee-config-grid select {
  width: 100%;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: #263840;
  font-size: 12px;
  padding: 0 8px;
}

.employee-actions {
  display: grid;
  gap: 5px;
  align-content: start;
}

.employee-actions button {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #43525a;
  padding: 0 8px;
  font-size: 12px;
}

.role-select {
  margin: 0;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.tag,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 6px;
  border-radius: 6px;
  background: var(--soft);
  color: #3d4b52;
  font-size: 11px;
}

.tag.convert {
  background: #e5f7df;
}

.tag.watch {
  background: #fff0d3;
}

.tag.nurse {
  background: #e6efff;
}

.shift-notes {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.shift-notes div {
  display: grid;
  grid-template-columns: 118px 1fr;
  gap: 8px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  font-size: 12px;
}

.shift-notes strong {
  color: #263840;
}

.shift-notes span {
  color: var(--muted);
}

.rule-cards {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.rule-card {
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: center;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.rule-card .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
}

.rule-card.warn .dot {
  background: var(--warning);
}

.rule-card.bad .dot {
  background: var(--danger);
}

.rule-card strong {
  display: block;
  font-size: 12px;
}

.rule-card span {
  color: var(--muted);
  font-size: 11px;
}

.schedule-panel {
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.schedule-tools {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brush-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: nowrap;
  padding: 7px 9px;
  border: 1px solid #b9ded9;
  border-radius: 8px;
  background: #eefaf8;
  color: #3b565c;
  font-size: 12px;
}

.bar-divider {
  width: 1px;
  height: 22px;
  background: #b9d6d2;
}

.help-dot {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 1px solid #9ecbc5;
  border-radius: 50%;
  background: #fff;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  padding: 0;
}

.brush {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.filter-bar {
  margin-left: auto;
}

.filter {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.brush.active,
.filter.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.danger-action {
  border-color: #f0b8ae;
  color: var(--danger);
}

.danger-action:hover {
  background: var(--danger-weak);
}

.grid-wrap {
  min-height: 0;
  overflow: auto;
  position: relative;
}

.schedule-table {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 1880px;
  width: max-content;
  font-size: 12px;
}

.schedule-table th,
.schedule-table td {
  min-width: 58px;
  height: 48px;
  padding: 5px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
  vertical-align: middle;
  position: relative;
}

.schedule-table th {
  position: sticky;
  top: 0;
  z-index: 5;
  height: 44px;
  background: #f8fafb;
  color: #43525a;
  font-weight: 600;
}

.schedule-table th.weekend {
  background: #fff6e5;
  color: #7a4a0b;
}

.schedule-table .name-col,
.schedule-table .name-cell {
  position: sticky;
  left: 0;
  z-index: 6;
  min-width: 118px;
  width: 118px;
  background: #fff;
  border-left: 0;
}

.schedule-table th.name-col {
  z-index: 8;
  background: #f8fafb;
}

.schedule-table .summary-col,
.schedule-table .summary-cell {
  position: sticky;
  z-index: 4;
  min-width: 82px;
  background: #fbfcfc;
}

.schedule-table tbody tr:hover td,
.schedule-table tbody tr:hover .name-cell {
  background: #f0faf8;
}

.schedule-table tbody tr:hover td.weekend {
  background: #fff1cf;
}

.schedule-table td.weekend {
  background: #fffcf4;
}

.schedule-table th.summary-col {
  z-index: 7;
  background: #eef3f4;
}

.summary-col.rest,
.summary-cell.rest {
  right: 328px;
}

.summary-col.day,
.summary-cell.day {
  right: 246px;
}

.summary-col.night,
.summary-cell.night {
  right: 164px;
}

.summary-col.total,
.summary-cell.total {
  right: 82px;
}

.summary-col.balance,
.summary-cell.balance {
  right: 0;
  min-width: 82px;
}

.name-cell strong {
  display: block;
  font-size: 13px;
}

.name-cell .small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.locked-row td:not(.name-cell) {
  background-image: linear-gradient(135deg, rgba(15, 118, 110, 0.04), rgba(15, 118, 110, 0.04));
}

.cell {
  user-select: none;
  outline: 0;
}

.cell.selected {
  box-shadow: inset 0 0 0 2px var(--accent);
  z-index: 3;
}

.cell.locked {
  cursor: not-allowed;
}

.shift-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 22px;
  gap: 3px;
  padding: 0 6px;
  border-radius: 6px;
  font-weight: 700;
}

.shift-chip em {
  font-style: normal;
  font-size: 11px;
  font-weight: 600;
  opacity: 0.82;
}

.shift-early .shift-chip,
.shift-chip.early {
  background: var(--early);
  color: #075f55;
}

.shift-middle .shift-chip,
.shift-chip.middle {
  background: var(--middle);
  color: #244b92;
}

.shift-night .shift-chip,
.shift-chip.night {
  background: var(--night);
  color: #55308f;
}

.shift-off .shift-chip,
.shift-chip.off {
  background: var(--off);
  color: #66757e;
}

.warning-mark {
  position: absolute;
  right: 4px;
  top: 4px;
  color: var(--warning);
  font-size: 11px;
}

.summary-cell {
  color: #233138;
  font-weight: 700;
  text-align: center;
}

.schedule-table tfoot th,
.schedule-table tfoot td {
  height: 30px;
  background: #f8fafb;
  color: #52636b;
  font-size: 11px;
  font-weight: 700;
}

.schedule-table tfoot .footer-label {
  position: sticky;
  left: 0;
  z-index: 5;
  text-align: left;
  background: #eef3f4;
}

.schedule-table tfoot .footer-cell {
  text-align: center;
}

.schedule-table tfoot .footer-cell.weekend {
  background: #fff6e5;
}

.schedule-table tfoot .footer-fill {
  position: sticky;
  right: 0;
  z-index: 4;
  background: #eef3f4;
}

.balance-ok {
  color: var(--accent);
}

.balance-warn {
  color: var(--warning);
}

.balance-bad {
  color: var(--danger);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.conflict-list,
.confirm-list {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.conflict-item {
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.conflict-item.bad {
  border-color: #f2b8ae;
  background: var(--danger-weak);
}

.conflict-item.warn {
  border-color: #f6cf89;
  background: var(--warning-weak);
}

.conflict-item strong {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
}

.conflict-item p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.conflict-item button {
  margin-top: 8px;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 8px;
  font-size: 12px;
}

.confirm-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  font-size: 12px;
}

.confirm-row input {
  accent-color: var(--accent);
}

.quick-editor {
  position: fixed;
  z-index: 30;
  width: 286px;
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  max-width: 360px;
  padding: 11px 14px;
  border: 1px solid #a7d7d1;
  border-radius: 8px;
  background: #ecfaf8;
  color: #075f55;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.toast[hidden] {
  display: none;
}

.quick-editor[hidden] {
  display: none;
}

.quick-editor button {
  min-height: 36px;
  padding: 0 8px;
  font-size: 12px;
}

.quick-editor-section + .quick-editor-section {
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.quick-editor-section strong {
  display: block;
  margin-bottom: 6px;
  color: #31444c;
  font-size: 12px;
}

.quick-editor-section div {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

@media (max-width: 1180px) {
  body {
    overflow: auto;
  }

  .app-shell {
    min-height: 100dvh;
    height: auto;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar {
    flex-wrap: wrap;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .left-panel,
  .right-panel,
  .schedule-panel {
    min-height: 420px;
  }
}
