:root {
  --bg: #f7f8fb;
  --ink: #17202a;
  --muted: #697586;
  --line: #d9dee8;
  --panel: #ffffff;
  --sapia: #f28c28;
  --sapia-soft: #fff0df;
  --trust: #2e9d63;
  --trust-soft: #e7f6ed;
  --danger: #d72d2d;
  --accent: #2e5fbb;
  --shadow: 0 8px 24px rgba(31, 42, 68, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
select,
input {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  cursor: pointer;
}

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

button.ghost {
  background: transparent;
}

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

#app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: block;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 20px;
}

.login-panel {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-start;
  margin-top: 10px;
}

.login-panel label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.month-switcher {
  display: flex;
  align-items: end;
  gap: 6px;
}

.month-switcher button {
  width: 38px;
  min-height: 40px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.month-switcher button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

select,
input {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 10px;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border-radius: 999px;
  background: #e9eef8;
  padding: 0 10px;
  color: #28466e;
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0 14px;
}

.tab {
  flex: 0 0 auto;
}

.tab.active {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.section-head.compact {
  align-items: center;
  margin-top: 0;
}

.muted {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.legend,
.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

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

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.dot.sapia {
  background: var(--sapia);
}

.dot.trust {
  background: var(--trust);
}

.mark {
  color: var(--danger);
  font-style: normal;
  font-weight: 700;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.table-wrap.small {
  max-height: 520px;
}

table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  border: 1px solid var(--line);
  min-width: 74px;
  height: 48px;
  padding: 6px;
  text-align: center;
  vertical-align: middle;
  font-size: 13px;
}

td.editable-shift {
  cursor: pointer;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f0f3f8;
  font-weight: 700;
}

.name-col {
  position: sticky;
  left: 0;
  z-index: 3;
  min-width: 88px;
  background: #f8fafc;
  text-align: left;
}

.shift-cell {
  display: grid;
  gap: 2px;
  min-height: 34px;
  place-items: center;
  border-radius: 6px;
  line-height: 1.15;
  font-weight: 700;
}

.shift-cell .time {
  font-size: 11px;
  font-weight: 500;
  color: rgba(23, 32, 42, 0.72);
}

.shift-cell.sapia {
  background: var(--sapia-soft);
  color: #9b4f00;
}

.shift-cell.trust {
  background: var(--trust-soft);
  color: #14633b;
}

.shift-cell.off,
.shift-cell.blank {
  background: #fff;
  color: var(--danger);
}

.shift-cell.shinomiya-standby {
  background: #fff;
  color: transparent;
}

.shift-cell.support-duty {
  min-height: 34px;
  border: 1px solid #d9dee8;
  background: #fff;
  color: transparent;
}

.shift-cell.violation,
td.violation,
.summary-row td.violation {
  outline: 2px solid var(--danger);
  outline-offset: -2px;
  color: var(--danger);
}

.shift-cell.violation .time {
  color: var(--danger);
}

.summary-row th,
.summary-row td {
  background: #f7f9fc;
  font-weight: 700;
}

.spacer-row td {
  height: 14px;
  background: #fff;
  border-left-color: transparent;
  border-right-color: transparent;
}

.request-count {
  margin-bottom: 10px;
  color: var(--muted);
}

.request-submit-row {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 10px;
}

.request-submit-row.bottom {
  margin: 12px 0 0;
}

.request-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.request-weekhead {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.request-day.empty {
  visibility: hidden;
}

.my-calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.my-weekhead {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.my-day {
  min-height: 88px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
  display: grid;
  align-content: start;
  gap: 8px;
}

.my-day.empty {
  visibility: hidden;
}

.my-day.weekend {
  background: #fbfcff;
}

.my-day.sapia {
  background: var(--sapia-soft);
}

.my-day.trust {
  background: var(--trust-soft);
}

.my-day strong {
  font-size: 13px;
}

.my-day span {
  font-size: 12px;
  font-weight: 700;
}

.surgery-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(118px, 1fr));
  gap: 8px;
}

.surgery-weekhead {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.surgery-blank {
  min-height: 1px;
}

.surgery-day {
  display: grid;
  gap: 8px;
  min-height: 132px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  box-shadow: 0 3px 12px rgba(31, 42, 68, 0.05);
}

.surgery-day.weekend {
  background: #fbfcff;
}

.surgery-day strong {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  font-size: 14px;
}

.surgery-day strong span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.surgery-day .need-note {
  color: var(--muted);
  font-size: 12px;
}

.surgery-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.surgery-tabs button {
  min-height: 36px;
  padding: 0 6px;
  font-size: 12px;
  white-space: nowrap;
}

.surgery-tabs button.active {
  border-color: var(--sapia);
  background: var(--sapia-soft);
  color: #9b4f00;
  font-weight: 700;
}

.request-day {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
  box-shadow: 0 3px 12px rgba(31, 42, 68, 0.05);
}

.request-day.weekend {
  background: #fbfcff;
}

.request-date {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.request-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.request-actions button {
  min-height: 34px;
  padding: 0 6px;
}

.request-actions button.active {
  border-color: var(--danger);
  color: var(--danger);
  font-weight: 700;
}

.admin-grid {
  display: grid;
  gap: 14px;
}

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

.member-list,
.staffing-rules {
  display: grid;
  gap: 8px;
}

.member-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
}

.member-fixed {
  color: var(--muted);
  font-size: 13px;
}

.assignment-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.assignment-tabs button {
  min-height: 34px;
  padding: 0 8px;
  font-size: 12px;
}

.assignment-tabs button.active {
  border-color: var(--accent);
  background: #e9eef8;
  color: #28466e;
  font-weight: 700;
}

.staffing-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) repeat(3, minmax(112px, 140px));
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfe;
}

.staffing-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.staffing-title span {
  flex: 0 0 auto;
  min-width: 58px;
  border-radius: 6px;
  padding: 5px 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

.staffing-row.sapia .staffing-title span {
  background: var(--sapia-soft);
  color: #9b4f00;
}

.staffing-row.trust .staffing-title span {
  background: var(--trust-soft);
  color: #14633b;
}

.staffing-title strong {
  min-width: 0;
  font-size: 14px;
}

.staffing-slot {
  display: grid;
  grid-template-columns: 18px 34px minmax(0, 1fr);
  gap: 4px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.staffing-row .staffing-count {
  width: 34px;
  min-height: 30px;
  padding: 4px;
  text-align: center;
}

.staffing-row .staffing-time {
  width: 100%;
  min-height: 30px;
  padding: 4px 6px;
  font-size: 12px;
  text-align: center;
}

@media (max-width: 760px) {
  #app {
    padding: 12px;
  }

  .topbar,
  .section-head {
    display: grid;
    justify-content: stretch;
  }

  h1 {
    font-size: 21px;
  }

  .login-panel,
  .legend,
  .button-row,
  .request-submit-row {
    justify-content: start;
  }

  th,
  td {
    min-width: 68px;
    height: 44px;
    padding: 4px;
    font-size: 12px;
  }

  .name-col {
    min-width: 76px;
  }

  .request-grid {
    grid-template-columns: repeat(7, minmax(44px, 1fr));
    gap: 4px;
    overflow-x: auto;
  }

  .request-day {
    min-height: 76px;
    padding: 6px;
  }

  .request-actions {
    gap: 3px;
  }

  .request-actions button {
    min-height: 30px;
    padding: 0 3px;
  }

  .my-calendar {
    gap: 5px;
  }

  .my-day {
    min-height: 64px;
    padding: 6px;
  }

  .my-day span {
    font-size: 11px;
  }

  .surgery-grid {
    grid-template-columns: repeat(7, minmax(64px, 1fr));
    gap: 4px;
    overflow-x: auto;
  }

  .surgery-day {
    min-height: 118px;
    padding: 6px;
  }

  .surgery-tabs {
    gap: 3px;
  }

  .surgery-tabs button {
    min-height: 30px;
    padding: 0 3px;
    font-size: 10px;
  }

  .member-row,
  .staffing-row {
    grid-template-columns: 1fr;
  }
}
