:root {
  color-scheme: light;
  --page: #eef2f7;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #dbe3ee;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-soft: #e8f3ff;
  --danger: #dc2626;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(circle at 12% -10%, rgba(37, 99, 235, 0.16), transparent 32rem),
    radial-gradient(circle at 95% 10%, rgba(139, 92, 246, 0.12), transparent 28rem),
    var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 1480px);
  margin: 0 auto;
  padding: 26px clamp(14px, 3vw, 34px) 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
  padding: 18px 22px;
  border-radius: var(--radius);
  background: linear-gradient(120deg, #1d4ed8 0%, #2563eb 55%, #4f46e5 100%);
  color: #fff;
  box-shadow: 0 18px 40px rgba(29, 78, 216, 0.24);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.35);
  font-size: 24px;
  font-weight: 850;
  letter-spacing: -0.04em;
}

.eyebrow {
  margin: 0 0 2px;
  color: rgba(255, 255, 255, 0.76);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(20px, 3vw, 28px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 9px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 11px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:focus-visible,
.icon-btn:focus-visible,
.view-btn:focus-visible,
select:focus-visible,
input:focus-visible,
.day-cell:focus-visible,
.mini-title:focus-visible {
  outline: 3px solid rgba(96, 165, 250, 0.7);
  outline-offset: 2px;
}

.btn-primary {
  background: #fff;
  color: var(--blue-dark);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.16);
}

.btn-primary.is-active {
  background: #0f172a;
  color: #fff;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.24);
}

.btn-quiet {
  background: #f1f5f9;
  border-color: var(--line);
  color: #334155;
}

.btn-quiet:hover {
  background: #e2e8f0;
}

.btn-icon {
  font-size: 15px;
  line-height: 1;
}

.import-btn input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}

.panel {
  background: var(--card);
  border: 1px solid rgba(219, 227, 238, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.calendar-panel {
  padding: clamp(18px, 2.5vw, 28px);
  min-width: 0;
}

.side-panel {
  padding: 22px;
  position: sticky;
  top: 18px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.panel-head.compact {
  margin-bottom: 14px;
}

.panel-head h2,
.side-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.panel-head p {
  margin: 4px 0 0;
  font-size: 13px;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: #334155;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.icon-btn:hover {
  background: #e8f3ff;
  border-color: #bfdbfe;
}

.month-nav input {
  height: 36px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 700;
}

.toolbar {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px;
  margin-bottom: 16px;
  border-radius: 16px;
  background: #f8fafc;
  border: 1px solid #e8edf4;
}

.view-switch {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: #e2e8f0;
}

.view-btn {
  min-width: 58px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #475569;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.view-btn.is-active {
  background: #fff;
  color: var(--blue-dark);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.1);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field > span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field select {
  height: 36px;
  min-width: 160px;
  padding: 0 32px 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background-color: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
}

.field select:disabled {
  background: #eef2f7;
  color: #94a3b8;
  cursor: not-allowed;
}

.toolbar .btn-quiet {
  margin-left: auto;
  height: 36px;
  min-height: 36px;
}

.edit-hint {
  margin-bottom: 14px;
  padding: 10px 13px;
  border-radius: 11px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
  font-size: 13px;
  font-weight: 650;
}

.calendar {
  min-width: 0;
}

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

.weekdays {
  margin-bottom: 8px;
}

.weekdays span {
  padding: 6px 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.day-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  min-height: 78px;
  padding: 6px 4px;
  border-radius: 13px;
  border: 1.5px solid var(--cell-border, var(--line));
  background: var(--cell-bg, #fff);
  color: var(--cell-fg, var(--ink));
  cursor: default;
  overflow: hidden;
  transition: transform 0.13s ease, box-shadow 0.13s ease, opacity 0.18s ease;
}

.day-cell.is-empty {
  --cell-bg: #ffffff;
  --cell-fg: #94a3b8;
  --cell-border: #e2e8f0;
}

.day-cell.is-outside,
.mini-cell.is-outside {
  background: transparent;
  border-color: transparent;
  pointer-events: none;
}

.day-number {
  align-self: flex-start;
  margin-left: 7px;
  font-size: 12px;
  font-weight: 750;
  opacity: 0.78;
}

.shift-code {
  font-size: clamp(13px, 1.5vw, 19px);
  font-weight: 850;
  letter-spacing: 0.045em;
  line-height: 1;
}

.day-cell.is-dimmed,
.legend-item.is-dimmed {
  opacity: 0.18;
  filter: grayscale(0.7);
}

.day-cell.is-today::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 2px solid currentColor;
  border-radius: 9px;
  opacity: 0.55;
}

body.is-editing .day-cell:not(.is-outside) {
  cursor: crosshair;
}

body.is-editing .day-cell:not(.is-outside):hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.18);
}

.calendar.is-editing .days-grid {
  touch-action: none;
  user-select: none;
}

.panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #edf1f6;
}

.panel-foot p {
  margin: 0;
}

.year-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 16px;
}

.mini-month {
  padding: 13px;
  border-radius: 15px;
  border: 1px solid var(--line);
  background: #fbfdff;
}

.mini-title {
  width: 100%;
  margin-bottom: 8px;
  padding: 4px 2px;
  border: none;
  background: transparent;
  color: #1e293b;
  cursor: pointer;
  font-size: 14px;
  font-weight: 850;
  text-align: left;
}

.mini-title:hover {
  color: var(--blue-dark);
}

.mini-weekdays,
.mini-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.mini-weekdays {
  margin-bottom: 5px;
}

.mini-weekdays span {
  color: #94a3b8;
  font-size: 9px;
  font-weight: 800;
  text-align: center;
}

.mini-cell {
  display: grid;
  place-items: center;
  height: 24px;
  min-width: 0;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--cell-border, var(--line));
  background: var(--cell-bg, #fff);
  color: var(--cell-fg, var(--ink));
  cursor: pointer;
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
}

.mini-cell:hover {
  transform: scale(1.09);
  box-shadow: 0 3px 8px rgba(15, 23, 42, 0.16);
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 22px;
}

.summary-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 12px 6px;
  border-radius: 13px;
  background: #f8fafc;
  border: 1px solid #e8edf4;
}

.summary-value {
  font-size: 22px;
  font-weight: 850;
  line-height: 1;
  color: var(--blue-dark);
}

.summary-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.summary-card-hours {
  grid-column: 1 / -1;
  background: linear-gradient(120deg, #1d4ed8, #2563eb);
  border-color: #1d4ed8;
}

.summary-card-hours .summary-value {
  color: #fff;
  font-size: 28px;
}

.summary-card-hours .summary-label {
  color: rgba(255, 255, 255, 0.82);
}

.sunday-note {
  margin: -12px 0 20px;
  line-height: 1.4;
}

.side-title {
  margin-bottom: 10px;
  font-size: 14px;
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 10px;
  transition: opacity 0.18s ease, filter 0.18s ease;
}

.legend-item:hover {
  background: #f8fafc;
}

.swatch {
  display: grid;
  place-items: center;
  width: 40px;
  height: 28px;
  flex: 0 0 auto;
  border-radius: 7px;
  border: 1px solid var(--cell-border, var(--line));
  background: var(--cell-bg, #fff);
  color: var(--cell-fg, var(--ink));
  font-size: 10px;
  font-weight: 850;
}

.swatch-empty {
  --cell-bg: #fff;
  --cell-fg: #94a3b8;
  --cell-border: #e2e8f0;
  font-size: 15px;
}

.legend-label {
  flex: 1 1 auto;
  font-size: 13px;
  font-weight: 650;
}

.legend-count {
  min-width: 26px;
  padding: 3px 6px;
  border-radius: 999px;
  background: #eef2f7;
  color: #475569;
  font-size: 11px;
  font-weight: 800;
  text-align: center;
}

.source-note {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid #edf1f6;
}

.source-note p {
  margin: 0 0 8px;
  font-size: 12px;
  line-height: 1.5;
}

.source-note code {
  padding: 1px 5px;
  border-radius: 5px;
  background: #f1f5f9;
  color: #334155;
  font-size: 11px;
  word-break: break-all;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  padding: 11px 16px;
  border-radius: 11px;
  background: #0f172a;
  color: #fff;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.28);
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.is-error {
  background: var(--danger);
}

@media (max-width: 1050px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
  }

  .legend {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  }
}

@media (max-width: 700px) {
  .app-shell {
    padding: 14px 12px 28px;
  }

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

  .topbar-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .btn {
    flex: 1 1 auto;
    padding: 0 10px;
  }

  .calendar-panel,
  .side-panel {
    padding: 16px;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar .field,
  .toolbar .field select,
  .toolbar .btn-quiet {
    width: 100%;
    min-width: 0;
  }

  .toolbar .btn-quiet {
    margin-left: 0;
  }

  .weekdays,
  .days-grid {
    gap: 5px;
  }

  .day-cell {
    min-height: 58px;
    border-radius: 9px;
  }

  .day-number {
    margin-left: 4px;
    font-size: 10px;
  }

  .shift-code {
    font-size: 12px;
  }

  .year-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }
}

@media print {
  body {
    background: #fff;
  }

  .topbar-actions,
  .toolbar,
  .edit-hint,
  .side-panel,
  .panel-foot,
  .toast {
    display: none !important;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .panel {
    border: none;
    box-shadow: none;
  }

  .day-cell {
    break-inside: avoid;
  }
}
