:root {
  --bg: #f6f8f9;
  --panel: #ffffff;
  --line: #dce3e6;
  --text: #1c2a2f;
  --muted: #607079;
  --accent: #167d7f;
  --accent-dark: #0f5f61;
  --soft: #e8f3f2;
  --warn: #a35d00;
  --warn-bg: #fff4df;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

label {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--text);
}

textarea {
  resize: vertical;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: var(--bg);
}

.login-card {
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.login-card h1 {
  margin: 0 0 18px;
  font-size: 24px;
}

.login-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.login-tabs button.active {
  border-color: var(--accent);
  background: var(--soft);
  color: var(--accent-dark);
  font-weight: 700;
}

body.is-logged-in .login-screen {
  display: none;
}

body:not(.is-logged-in) .app-shell {
  display: none !important;
}

.print-title {
  display: none;
}

.topbar h1,
.section-head h2,
.panel h2 {
  margin: 0;
}

.topbar h1 {
  font-size: 24px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.user-box {
  display: grid;
  gap: 8px;
  width: 220px;
}

.user-box label {
  margin-top: 0;
}

.session-chip {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7faf9;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.layout {
  display: grid;
  grid-template-columns: 280px minmax(560px, 1fr) 300px;
  gap: 16px;
  padding: 16px;
}

.panel,
.calendar-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel {
  padding: 16px;
}

.panel section + section {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.panel h2,
.section-head h2 {
  font-size: 17px;
}

.calendar-panel {
  padding: 16px;
  min-width: 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.calendar-tools {
  display: grid;
  grid-template-columns: auto minmax(150px, 1fr) auto;
  align-items: end;
  gap: 8px;
}

.calendar-tools label {
  margin: 0 0 9px;
}

.calendar-tools select,
.calendar-tools button {
  width: auto;
}

.primary-button {
  width: 100%;
  margin-top: 14px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.inline-row {
  display: grid;
  grid-template-columns: 1fr 36px;
  gap: 8px;
}

.icon-button {
  width: 36px;
  padding: 0;
  font-size: 18px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
  margin-top: 8px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent-dark);
  font-size: 12px;
}

.tag button {
  width: 18px;
  min-height: 18px;
  border: 0;
  padding: 0;
  background: transparent;
}

.week-header,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.week-header {
  border: 1px solid var(--line);
  border-bottom: 0;
  background: #eef4f5;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.week-header span {
  padding: 8px;
  text-align: center;
}

.calendar-grid {
  border-left: 1px solid var(--line);
  border-top: 1px solid var(--line);
}

.day-cell {
  min-height: 132px;
  padding: 7px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.day-cell.empty {
  background: #f1f4f5;
}

.day-cell.weekend,
.day-cell.holiday {
  background: #def4e2;
}

.day-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.day-number {
  font-size: 16px;
  font-weight: 800;
}

.badge {
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent-dark);
  font-size: 11px;
}

.badge.manual {
  background: var(--warn-bg);
  color: var(--warn);
}

.duty-line {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin: 4px 0;
  line-height: 1.28;
  white-space: nowrap;
}

.duty-label {
  flex: 0 0 auto;
  color: var(--muted);
}

.duty-person {
  flex: 1 1 auto;
  min-width: 1em;
  font-weight: 700;
  overflow: visible;
}

.note {
  margin-top: 6px;
  color: var(--warn);
  font-size: 12px;
}

.day-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.day-actions button {
  flex: 1;
  min-height: 30px;
  font-size: 12px;
  border-color: #d8dee1;
  background: #f3f5f6;
  color: #526168;
}

.day-actions button:hover {
  border-color: #c8d0d4;
  background: #eceff1;
}

body.is-user .settings-panel,
body.is-user .admin-only,
body.is-user .admin-summary-section {
  display: none !important;
}

body.is-user .layout {
  grid-template-columns: minmax(0, 1fr) 300px;
}

body.is-user .calendar-panel {
  grid-column: auto;
}

body.is-user .settings-panel button,
body.is-user .settings-panel input,
body.is-user .settings-panel select,
body.is-user .settings-panel textarea,
body.is-user .admin-only input {
  cursor: not-allowed;
}

.list {
  display: grid;
  gap: 8px;
}

.list-item {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.list-item strong {
  display: block;
  margin-bottom: 3px;
}

.list-item span,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.compact-list {
  max-height: 240px;
  overflow: auto;
}

.removal-list {
  margin-top: 12px;
}

.removal-item button {
  width: 100%;
  min-height: 30px;
  margin-top: 8px;
  font-size: 12px;
}

dialog {
  width: min(460px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}

dialog::backdrop {
  background: rgb(28 42 47 / 38%);
}

#editForm {
  padding: 16px;
}

.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-head h2 {
  margin: 0;
}

.dialog-actions {
  margin-top: 16px;
}

.dialog-actions button {
  min-width: 90px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: 320px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--text);
  color: #fff;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: 260px minmax(520px, 1fr);
  }

  .side-panel {
    grid-column: 1 / -1;
  }

  body.is-user .layout {
    grid-template-columns: minmax(0, 1fr) 300px;
  }

  body.is-user .side-panel {
    grid-column: auto;
  }
}

@media (max-width: 860px) {
  body {
    font-size: 15px;
  }

  .topbar,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .calendar-tools {
    grid-template-columns: 1fr;
  }

  .calendar-tools label {
    margin-bottom: -2px;
  }

  .calendar-tools select,
  .calendar-tools button {
    width: 100%;
  }

  .topbar {
    gap: 14px;
    padding: 14px;
  }

  .topbar h1 {
    font-size: 21px;
  }

  .user-box {
    width: 100%;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 10px;
  }

  body.is-user .layout {
    grid-template-columns: 1fr;
  }

  .panel,
  .calendar-panel {
    border-radius: 6px;
  }

  .panel,
  .calendar-panel {
    padding: 12px;
  }

  .calendar-panel {
    overflow-x: visible;
  }

  .week-header {
    display: none;
  }

  .calendar-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    min-width: 0;
    border: 0;
  }

  .day-cell {
    min-height: 0;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px;
  }

  .day-cell.empty {
    display: none;
  }

  .day-head {
    margin-bottom: 8px;
  }

  .day-number {
    font-size: 0;
  }

  .day-number::after {
    content: attr(data-date) " " attr(data-weekday);
    font-size: 16px;
    font-weight: 800;
  }

  .duty-line {
    gap: 10px;
    margin: 6px 0;
    white-space: normal;
  }

  .duty-label {
    width: 42px;
  }

  .day-actions {
    margin-top: 10px;
  }

  .day-actions button {
    min-height: 36px;
  }
}

@media print {
  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body {
    background: #fff;
  }

  .print-title {
    display: block;
    margin: 0 0 12px;
    text-align: center;
  }

  .print-title h1 {
    margin: 0;
    color: #111;
    font-size: 23px;
    font-weight: 800;
  }

  .topbar,
  .settings-panel,
  .side-panel,
  .day-actions,
  #printButton,
  .toast {
    display: none !important;
  }

  .layout {
    display: block;
    padding: 0;
  }

  .calendar-panel {
    border: 0;
    padding: 0;
  }

  .day-cell {
    min-height: 115px;
  }
}
