:root {
  color-scheme: dark;
  --bg: #050507;
  --bg-soft: #111116;
  --surface: rgba(28, 28, 32, 0.78);
  --surface-strong: rgba(44, 44, 50, 0.9);
  --surface-solid: #1c1c20;
  --field: rgba(255, 255, 255, 0.08);
  --ink: #f5f5f7;
  --muted: #a1a1aa;
  --line: rgba(255, 255, 255, 0.13);
  --blue: #0a84ff;
  --blue-press: #409cff;
  --green: #30d158;
  --red: #ff453a;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f5f7;
  --bg-soft: #ffffff;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-strong: rgba(255, 255, 255, 0.94);
  --surface-solid: #ffffff;
  --field: rgba(255, 255, 255, 0.86);
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(60, 60, 67, 0.18);
  --blue: #007aff;
  --blue-press: #0068d8;
  --green: #34c759;
  --red: #ff3b30;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.12);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  min-width: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% -10%, color-mix(in srgb, var(--blue) 26%, transparent), transparent 28rem),
    radial-gradient(circle at 100% 0%, color-mix(in srgb, var(--green) 13%, transparent), transparent 22rem),
    linear-gradient(180deg, var(--bg-soft) 0%, var(--bg) 58%, #000 100%);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  line-height: 1.45;
}

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

button,
.secondary-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  color: #fff;
  background: var(--blue);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  touch-action: manipulation;
  transition: transform 140ms cubic-bezier(0.2, 0.8, 0.2, 1), background 140ms ease, opacity 140ms ease;
}

button:active,
.secondary-button:active,
.day-cell.pressing {
  transform: scale(0.97);
}

button:hover,
.secondary-button:hover {
  background: var(--blue-press);
}

.secondary-button {
  color: var(--ink);
  background: rgba(118, 118, 128, 0.18);
}

.secondary-button:hover {
  background: rgba(118, 118, 128, 0.28);
}

.danger-button {
  color: var(--red);
  background: color-mix(in srgb, var(--red) 14%, transparent);
}

.danger-button:hover {
  color: #fff;
  background: var(--red);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.icon-button {
  width: 44px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.shell {
  width: min(1080px, calc(100vw - 32px));
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 0 max(28px, env(safe-area-inset-bottom));
}

.login-view {
  min-height: calc(100vh - 64px);
  display: grid;
  place-items: center;
}

.login-panel,
.editor-panel,
.calendar-panel,
.admin-panel,
.topbar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
}

.login-panel {
  width: min(420px, 100%);
  padding: 32px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(30px, 4vw, 42px);
  line-height: 1.08;
  letter-spacing: -0.02em;
  font-weight: 780;
}

h2 {
  font-size: 21px;
  line-height: 1.16;
  letter-spacing: -0.01em;
  font-weight: 760;
}

form {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.login-form {
  margin-top: 28px;
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  background: var(--field);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: color-mix(in srgb, var(--blue) 72%, white);
  background: var(--surface-solid);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--blue) 16%, transparent);
}

input::placeholder {
  color: color-mix(in srgb, var(--muted) 75%, transparent);
}

.error {
  min-height: 22px;
  margin: 0;
  color: var(--red);
}

.app-view {
  display: grid;
  gap: 16px;
}

.topbar {
  position: sticky;
  top: 12px;
  z-index: 3;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  padding: 16px;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.top-actions input {
  width: 156px;
  min-height: 44px;
}

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

.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.admin-body {
  display: grid;
  gap: 12px;
}

.admin-panel.collapsed .admin-body {
  display: none;
}

.user-switcher {
  min-width: 260px;
}

.user-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.user-row {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.user-row strong,
.user-row span {
  display: block;
}

.user-row strong {
  font-size: 15px;
}

.user-row span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.user-row button {
  min-height: 36px;
  flex: 0 0 auto;
}

.user-form {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: end;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: start;
}

.calendar-panel {
  padding: 14px;
  max-width: 100%;
}

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

.week-row {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.day-cell {
  position: relative;
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  background: var(--surface-strong);
  cursor: pointer;
  text-align: left;
  overflow: hidden;
  will-change: transform;
  display: grid;
  place-items: center;
}

.day-cell:hover,
.day-cell.active {
  border-color: color-mix(in srgb, var(--blue) 68%, transparent);
  background: color-mix(in srgb, var(--blue) 12%, var(--surface-strong));
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--blue) 14%, transparent);
}

.day-cell.outside {
  opacity: 0.38;
}

.day-number {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 780;
  line-height: 1;
  width: 100%;
}

.shift-dot {
  position: absolute;
  left: 50%;
  bottom: 9px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--blue);
  transform: translateX(-50%);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 16%, transparent);
}

.day-cell.day-off .shift-dot {
  background: var(--green);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 16%, transparent);
}

.today-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.editor-panel {
  position: sticky;
  top: 104px;
  padding: 18px;
  max-width: 100%;
  overflow: visible;
}

.editor-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.day-off-toggle {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--field);
}

.day-off-toggle input {
  order: 2;
  width: 22px;
  height: 22px;
  min-height: auto;
  padding: 0;
  flex: 0 0 auto;
  accent-color: var(--green);
}

.day-off-toggle span {
  flex: 1 1 auto;
}

#shiftForm.is-day-off .time-grid {
  opacity: 0.48;
}

#shiftForm.is-day-off .time-grid input {
  cursor: not-allowed;
}

.time-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

#shiftForm,
#shiftForm > input,
#shiftForm > label,
#shiftForm .time-grid,
#shiftForm textarea,
#shiftForm button[type="submit"] {
  width: 100%;
  max-width: 100%;
}

#shiftForm input:not([type="checkbox"]),
#shiftForm textarea {
  display: block;
  min-inline-size: 0;
  inline-size: 100%;
  max-inline-size: 100%;
}

.form-message {
  min-height: 22px;
  margin: 0;
  color: color-mix(in srgb, var(--blue) 75%, white);
  font-weight: 700;
}

[hidden] {
  display: none !important;
}

@media (max-width: 880px) {
  .shell {
    width: min(100% - 20px, 720px);
    padding-top: max(12px, env(safe-area-inset-top));
  }

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

  .topbar {
    position: static;
    top: 8px;
    align-items: start;
  }

  .top-actions {
    justify-content: start;
  }

  .user-switcher {
    min-width: 0;
  }

  .user-form {
    grid-template-columns: 1fr 1fr;
  }

  .user-form button {
    grid-column: span 2;
  }

  .editor-panel {
    position: static;
  }

  .day-cell {
    min-height: 70px;
    padding: 8px;
  }
}

@media (max-width: 560px) {
  body {
    background:
      radial-gradient(circle at 15% 0%, color-mix(in srgb, var(--blue) 22%, transparent), transparent 18rem),
      linear-gradient(180deg, var(--bg-soft) 0%, var(--bg) 100%);
  }

  .shell {
    width: min(420px, calc(100vw - 24px));
    width: min(420px, calc(100svw - 24px));
    max-width: calc(100% - 24px);
    padding: max(8px, env(safe-area-inset-top)) 0 max(12px, env(safe-area-inset-bottom));
  }

  .login-view {
    min-height: calc(100vh - 20px);
  }

  .login-panel {
    padding: 24px;
  }

  .app-view {
    gap: 10px;
    justify-items: center;
  }

  .topbar,
  .admin-panel,
  .calendar-panel,
  .editor-panel {
    width: 100%;
    max-width: 100%;
  }

  .topbar {
    top: 6px;
    margin: 0;
    padding: 12px;
    gap: 12px;
  }

  .top-title {
    min-width: 0;
  }

  h1 {
    font-size: 28px;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 44px 44px minmax(0, 1fr) 44px;
    width: 100%;
    gap: 8px;
  }

  .top-actions #logoutButton {
    grid-column: span 4;
  }

  .top-actions input {
    width: 100%;
  }

  .admin-panel {
    padding: 12px;
  }

  .admin-head {
    align-items: center;
  }

  .admin-head .secondary-button {
    min-width: 68px;
  }

  .user-list,
  .user-form {
    grid-template-columns: 1fr;
  }

  .user-form button {
    grid-column: auto;
  }

  .calendar-panel {
    padding: 8px;
    margin-inline: auto;
  }

  .week-row,
  .calendar-grid {
    gap: 3px;
  }

  .week-row {
    font-size: 12px;
  }

  .day-cell {
    min-height: 54px;
    border-radius: 8px;
    padding: 6px;
  }

  .day-number {
    font-size: 13px;
  }

  .editor-panel {
    padding: 14px;
    margin-bottom: env(safe-area-inset-bottom);
    overflow: visible;
  }

  .editor-heading {
    align-items: center;
    flex-wrap: wrap;
  }

  .editor-heading > div {
    flex: 1 1 180px;
  }

  .editor-heading .danger-button {
    flex: 0 0 auto;
    min-height: 40px;
    padding-inline: 14px;
  }

  .time-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  input,
  select,
  textarea {
    min-height: 44px;
    padding: 11px;
  }

  #shiftForm {
    width: 100%;
    gap: 14px;
  }
}

@media (max-width: 380px) {
  .day-cell {
    min-height: 50px;
  }

  .editor-panel {
    padding: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .login-panel,
  .editor-panel,
  .calendar-panel,
  .admin-panel,
  .topbar {
    background: var(--surface-solid);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}
