:root {
  color-scheme: light;
  --ink: #172223;
  --muted: #627173;
  --line: #d6dfdc;
  --surface: #ffffff;
  --surface-soft: #f4f8f6;
  --canvas: #edf3f1;
  --brand: #075c57;
  --brand-dark: #06443f;
  --brand-soft: #dff1ec;
  --morning: #f5c84b;
  --morning-soft: #fff3c5;
  --evening: #9760bd;
  --evening-soft: #f1e1fb;
  --off: #52a179;
  --off-soft: #dff2e6;
  --overtime: #d75259;
  --overtime-soft: #ffe1e3;
  --maneuver: #217c92;
  --maneuver-soft: #d8eff4;
  --shadow: 0 16px 40px rgba(15, 42, 39, 0.08);
  --radius: 16px;
  --p1: 52px;
  --p2: 78px;
  --p3: 230px;
  --p4: 132px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--canvas);
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 2% -15%, #cfece3 0, transparent 31rem),
    linear-gradient(180deg, #f5f8f7 0%, var(--canvas) 38rem);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(7, 92, 87, 0.27);
  outline-offset: 2px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 82px;
  padding: 17px clamp(20px, 4vw, 64px);
  color: #f9fffd;
  background: linear-gradient(112deg, #043c39, #0b625a 65%, #19746a);
  box-shadow: 0 6px 16px rgba(7, 62, 57, 0.17);
}

.brand,
.header-actions,
.month-control,
.schedule-heading,
.section-heading,
.dialog-heading,
.dialog-actions,
.notice,
.pool-preview,
.legend,
.app-footer {
  display: flex;
  align-items: center;
}

.brand {
  gap: 13px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 13px;
  color: #ffe69a;
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--brand);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.brand .eyebrow,
.print-heading .eyebrow {
  color: #a9e7d8;
}

h1,
h2,
p {
  margin-top: 0;
}

.brand h1 {
  margin: 0;
  color: inherit;
  font-size: clamp(18px, 2vw, 23px);
  letter-spacing: -0.025em;
}

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

.app-shell {
  width: min(1600px, calc(100% - 36px));
  margin: 24px auto 48px;
}

.control-bar,
.settings-panel,
.schedule-section,
.people-section,
.notice {
  border: 1px solid rgba(205, 220, 215, 0.92);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.93);
  box-shadow: var(--shadow);
}

.control-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px;
}

.month-control {
  gap: 6px;
}

.month-control label {
  display: grid;
  gap: 2px;
  min-width: 156px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.month-control input {
  width: 100%;
  padding: 4px 0;
  border: 0;
  color: var(--ink);
  background: transparent;
  font-size: 15px;
  font-weight: 750;
}

.control-divider {
  width: 1px;
  height: 28px;
  margin: 0 2px;
  background: var(--line);
}

.autosave-status {
  margin: 0 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.button,
.icon-button,
.link-button {
  border: 0;
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.button {
  min-height: 36px;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
}

.button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.button-primary {
  color: #fff;
  background: var(--brand);
  box-shadow: 0 4px 10px rgba(5, 92, 87, 0.18);
}

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

.button-quiet {
  border-color: #ccdbd6;
  color: #254442;
  background: #fff;
}

.button-quiet:hover {
  border-color: #8ebeb3;
  background: #f3fbf8;
}

.button-danger {
  color: #ad2635;
  background: #fff1f2;
}

.button-danger:hover {
  background: #ffe1e4;
}

.icon-button {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid #cedcd8;
  border-radius: 8px;
  color: var(--brand-dark);
  background: #fff;
  font-size: 25px;
  line-height: 1;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1.35fr repeat(3, 1fr);
  gap: 13px;
  margin: 18px 0;
}

.summary-card {
  min-height: 116px;
  padding: 18px 19px;
  border: 1px solid rgba(209, 221, 217, 0.9);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 6px 18px rgba(14, 49, 45, 0.04);
}

.summary-card--main {
  color: #eafbf6;
  border: 0;
  background: linear-gradient(135deg, #075c57, #0a7a70);
}

.summary-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.summary-card--main .summary-label {
  color: #bfe9dd;
}

.summary-card strong {
  display: block;
  margin: 10px 0 3px;
  font-size: clamp(21px, 2vw, 28px);
  line-height: 1;
  letter-spacing: -0.035em;
}

.summary-card small {
  color: var(--muted);
  font-size: 12px;
}

.summary-card--main small {
  color: #c8eee5;
}

.summary-card--off strong {
  color: #278058;
}

.summary-card--warning strong {
  color: #c83d49;
}

.notice {
  gap: 12px;
  margin: 0 0 18px;
  padding: 13px 16px;
  border-color: #f2c98b;
  background: #fff8e9;
  box-shadow: none;
}

.notice-icon {
  display: grid;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  color: #7b4a00;
  background: #ffe0a8;
  font-weight: 900;
}

.notice strong {
  font-size: 13px;
}

.notice p {
  margin: 2px 0 0;
  color: #765822;
  font-size: 12px;
}

.settings-panel {
  margin: 0 0 18px;
  overflow: clip;
}

.settings-panel summary {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 16px 18px;
  cursor: pointer;
  list-style: none;
}

.settings-panel summary::-webkit-details-marker {
  display: none;
}

.settings-panel summary::before {
  content: "+";
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border: 1px solid #b6ccc5;
  border-radius: 50%;
  color: var(--brand);
  font-size: 17px;
  font-weight: 400;
}

.settings-panel[open] summary::before {
  content: "−";
}

.settings-title {
  color: #183c39;
  font-size: 15px;
  font-weight: 800;
}

.settings-hint {
  color: var(--muted);
  font-size: 12px;
}

.settings-body {
  display: grid;
  grid-template-columns: minmax(360px, 1.25fr) minmax(210px, 0.8fr) minmax(260px, 1fr);
  gap: 18px;
  padding: 2px 18px 18px;
  border-top: 1px solid #e1e9e6;
}

.setting-group {
  padding-top: 15px;
}

.setting-group h2 {
  margin: 0 0 10px;
  color: #38524f;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

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

.form-grid--compact {
  grid-template-columns: 1.2fr 0.8fr 0.8fr;
}

label {
  display: grid;
  gap: 5px;
}

label > span {
  color: #5c6b6a;
  font-size: 11px;
  font-weight: 750;
}

input,
select {
  min-width: 0;
  min-height: 36px;
  padding: 7px 9px;
  border: 1px solid #cbd9d5;
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
}

input:hover,
select:hover {
  border-color: #97bcb3;
}

.toggle-label {
  display: flex;
  grid-column: 1 / -1;
  align-items: flex-start;
  gap: 9px;
  padding-top: 1px;
  cursor: pointer;
}

.toggle-label input {
  width: 17px;
  min-height: 17px;
  margin: 2px 0 0;
  accent-color: var(--brand);
}

.toggle-label span {
  display: grid;
  gap: 1px;
  color: var(--ink);
}

.toggle-label strong {
  font-size: 12px;
}

.toggle-label small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.cycle-preview,
.dialog-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.pool-preview {
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 7px;
}

.legend-chip {
  display: inline-flex;
  padding: 6px 8px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 800;
}

.legend-chip--morning {
  color: #775400;
  background: var(--morning-soft);
}

.legend-chip--evening {
  color: #673f83;
  background: var(--evening-soft);
}

.legend-chip--maneuver {
  color: #146378;
  background: var(--maneuver-soft);
}

.group-settings {
  display: grid;
  gap: 8px;
}

.group-setting-row {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) 1.1fr;
  align-items: center;
  gap: 8px;
}

.group-setting-row label {
  min-width: 0;
}

.group-setting-row input,
.group-setting-row select {
  min-height: 32px;
  padding-block: 5px;
  font-size: 12px;
}

.schedule-section,
.people-section {
  overflow: hidden;
}

.schedule-heading,
.section-heading {
  justify-content: space-between;
  gap: 24px;
  padding: 18px 20px 11px;
}

.schedule-heading h2,
.section-heading h2 {
  margin: 0;
  color: #163f3b;
  font-size: 20px;
  letter-spacing: -0.025em;
}

.legend {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 12px;
  color: #566968;
  font-size: 11px;
  font-weight: 700;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-dot--morning { background: var(--morning); }
.legend-dot--evening { background: var(--evening); }
.legend-dot--off { background: var(--off); }
.legend-dot--overtime { background: var(--overtime); }
.legend-dot--maneuver { background: var(--maneuver); }

.schedule-tip {
  margin: 0;
  padding: 0 20px 13px;
  color: var(--muted);
  font-size: 12px;
}

.schedule-scroll {
  width: 100%;
  overflow: auto;
  border-top: 1px solid #dce6e2;
  scrollbar-color: #9cbab3 #edf3f1;
  scrollbar-width: thin;
}

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

.schedule-table th,
.schedule-table td {
  height: 37px;
  padding: 3px 5px;
  border-right: 1px solid #d7e1de;
  border-bottom: 1px solid #d7e1de;
  text-align: center;
  vertical-align: middle;
}

.schedule-table th {
  position: sticky;
  top: 0;
  z-index: 10;
  color: #fff;
  background: #155e58;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.015em;
}

.schedule-table th.day-header {
  width: 44px;
  min-width: 44px;
  padding: 4px 2px;
}

.day-number {
  display: block;
  line-height: 1;
  font-size: 12px;
}

.day-name {
  display: block;
  margin-top: 3px;
  color: #c5e7dd;
  font-size: 8px;
  font-weight: 700;
  text-transform: uppercase;
}

.schedule-table th.weekend-header {
  color: #fff5d0;
  background: #104c47;
}

.schedule-table td {
  width: 44px;
  min-width: 44px;
  color: #243131;
  background: #fff;
}

.schedule-table tbody:last-child tr:last-child td {
  border-bottom: 0;
}

.pin {
  position: sticky;
  z-index: 4;
  background: #f8fbfa !important;
}

.schedule-table th.pin {
  z-index: 14;
  background: #155e58 !important;
}

.p1 { left: 0; width: var(--p1) !important; min-width: var(--p1) !important; }
.p2 { left: var(--p1); width: var(--p2) !important; min-width: var(--p2) !important; }
.p3 { left: calc(var(--p1) + var(--p2)); width: var(--p3) !important; min-width: var(--p3) !important; text-align: left !important; }
.p4 { left: calc(var(--p1) + var(--p2) + var(--p3)); width: var(--p4) !important; min-width: var(--p4) !important; text-align: left !important; box-shadow: 2px 0 4px rgba(17, 63, 59, 0.08); }

.group-title td {
  height: 29px;
  padding: 5px 10px;
  border-right: 0;
  color: #fbfffd;
  background: #0f7168;
  text-align: left;
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.075em;
  text-transform: uppercase;
}

.group-title--maneuver td {
  background: #216b7b;
}

.row-number,
.registry {
  color: #4c5d5c;
  font-variant-numeric: tabular-nums;
}

.person-name {
  color: #223b39;
  font-weight: 750;
}

.service {
  color: #607270;
}

.weekend:not(.cell--off) {
  background-image: linear-gradient(rgba(241, 247, 244, 0.42), rgba(241, 247, 244, 0.42));
}

.schedule-cell {
  position: relative;
  padding: 2px !important;
  cursor: pointer;
  transition: filter 120ms ease, transform 120ms ease;
}

.schedule-cell:hover {
  z-index: 3;
  filter: brightness(0.96) saturate(1.08);
  outline: 2px solid rgba(6, 92, 87, 0.32);
  outline-offset: -2px;
}

.schedule-cell:focus-visible {
  z-index: 3;
  outline: 3px solid #074e49;
  outline-offset: -3px;
}

.cell-value {
  display: block;
  color: inherit;
  font-size: 12px;
  font-weight: 850;
  line-height: 1.02;
  font-variant-numeric: tabular-nums;
}

.cell-meta {
  display: block;
  margin-top: 2px;
  color: inherit;
  font-size: 8px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.06em;
}

.cell--morning { color: #6c5000 !important; background-color: var(--morning-soft) !important; }
.cell--evening { color: #5a3973 !important; background-color: var(--evening-soft) !important; }
.cell--off { color: #196041 !important; background-color: var(--off-soft) !important; }
.cell--overtime { color: #9b2635 !important; background-color: var(--overtime-soft) !important; }
.cell--maneuver { color: #145d70 !important; background-color: var(--maneuver-soft) !important; }
.cell--plain { color: #4a5a5a !important; background-color: #eef2f1 !important; }

.cell--manual::after {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  content: "";
  opacity: 0.68;
}

.section-heading {
  padding-bottom: 16px;
  border-bottom: 1px solid #dce6e2;
}

.section-heading p:not(.eyebrow) {
  max-width: 700px;
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.people-section {
  margin-top: 18px;
}

.people-table-wrap {
  overflow-x: auto;
}

.people-table {
  width: 100%;
  min-width: 760px;
  border-spacing: 0;
  border-collapse: collapse;
}

.people-table th,
.people-table td {
  padding: 9px 10px;
  border-bottom: 1px solid #e1e9e6;
  text-align: left;
}

.people-table th {
  color: #59706c;
  background: #f5f9f7;
  font-size: 10px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.people-table tr:last-child td {
  border-bottom: 0;
}

.people-table input,
.people-table select {
  width: 100%;
  min-height: 31px;
  padding: 5px 7px;
  border-color: transparent;
  background: transparent;
  font-size: 12px;
}

.people-table input:hover,
.people-table select:hover,
.people-table input:focus,
.people-table select:focus {
  border-color: #a9c5bd;
  background: #fff;
}

.mini-button {
  padding: 5px 7px;
  border: 0;
  border-radius: 6px;
  color: #a22b38;
  background: #fff0f1;
  font-size: 11px;
  font-weight: 800;
}

.mini-button:hover {
  background: #ffdfe2;
}

.app-footer {
  justify-content: space-between;
  gap: 16px;
  padding: 17px 3px;
  color: var(--muted);
  font-size: 12px;
}

.app-footer p {
  margin: 0;
}

.link-button {
  padding: 3px 0;
  color: #9b3038;
  background: transparent;
  font-size: 12px;
  font-weight: 750;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.dialog {
  width: min(490px, calc(100% - 28px));
  padding: 0;
  border: 0;
  border-radius: 17px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 30px 80px rgba(1, 43, 40, 0.28);
}

.dialog::backdrop {
  background: rgba(10, 47, 44, 0.45);
  backdrop-filter: blur(2px);
}

.dialog form {
  margin: 0;
}

.dialog-heading {
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 20px 15px;
  border-bottom: 1px solid #e2ebe8;
}

.dialog-heading h2 {
  margin: 0;
  color: #164640;
  font-size: 19px;
}

.dialog-heading p:not(.eyebrow) {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.dialog-close {
  width: 31px;
  height: 31px;
  border: 0;
  border-radius: 8px;
  color: #4e5e5c;
  background: #f0f5f3;
  font-size: 24px;
  line-height: 1;
}

.dialog-close:hover {
  color: #234743;
  background: #e2ece8;
}

.dialog-body {
  padding: 18px 20px;
}

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

.dialog-actions {
  gap: 8px;
  padding: 14px 20px 20px;
  border-top: 1px solid #e2ebe8;
}

.dialog-actions-spacer {
  flex: 1;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.only-print {
  display: none;
}

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

  .settings-body .setting-group:last-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  :root {
    --p1: 43px;
    --p2: 62px;
    --p3: 155px;
    --p4: 105px;
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 13px;
    padding: 16px 18px;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .app-shell {
    width: min(100% - 22px, 1600px);
    margin-top: 13px;
  }

  .control-bar {
    align-items: stretch;
  }

  .month-control {
    width: 100%;
  }

  .month-control label {
    flex: 1;
  }

  .control-divider,
  .autosave-status {
    display: none;
  }

  .control-bar > .button {
    flex: 1 1 145px;
  }

  .summary-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 9px;
  }

  .summary-card {
    min-height: 95px;
    padding: 14px;
  }

  .summary-card--main {
    grid-column: span 2;
  }

  .settings-panel summary {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 5px 10px;
  }

  .settings-hint {
    width: calc(100% - 30px);
    margin-left: 30px;
  }

  .settings-body {
    grid-template-columns: 1fr;
  }

  .settings-body .setting-group:last-child {
    grid-column: auto;
  }

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

  .form-grid--compact label:first-child {
    grid-column: span 2;
  }

  .schedule-heading,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 15px 15px 10px;
  }

  .legend {
    justify-content: flex-start;
  }

  .schedule-tip {
    padding-inline: 15px;
  }

  .schedule-table th,
  .schedule-table td {
    font-size: 10px;
  }

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

@media print {
  @page {
    size: A4 landscape;
    margin: 9mm;
  }

  :root {
    --p1: 30px;
    --p2: 52px;
    --p3: 145px;
    --p4: 95px;
  }

  html,
  body {
    background: #fff;
  }

  body {
    font-size: 9px;
  }

  .no-print,
  .app-header,
  .settings-panel,
  .people-section,
  .app-footer,
  .notice {
    display: none !important;
  }

  .only-print {
    display: flex;
  }

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

  .print-heading {
    align-items: flex-end;
    justify-content: space-between;
    margin: 0 0 5mm;
    color: #103d38;
  }

  .print-heading p {
    margin: 0;
    color: #43635f;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.06em;
  }

  .print-heading h1 {
    margin: 2px 0 0;
    color: #103d38;
    font-size: 17px;
  }

  .summary-grid {
    gap: 4mm;
    margin: 0 0 4mm;
  }

  .summary-card {
    min-height: 0;
    padding: 3mm;
    box-shadow: none;
  }

  .summary-card strong {
    margin: 2mm 0 1mm;
    font-size: 16px;
  }

  .schedule-section {
    overflow: visible;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .schedule-heading {
    display: block;
    padding: 0 0 2mm;
  }

  .schedule-heading h2 {
    font-size: 14px;
  }

  .legend {
    margin-top: 1mm;
  }

  .schedule-scroll {
    overflow: visible;
    border: 1px solid #aebfbb;
  }

  .schedule-table {
    width: 100%;
    table-layout: fixed;
    font-size: 7px;
  }

  .schedule-table th,
  .schedule-table td {
    width: auto;
    min-width: 0 !important;
    height: 21px;
    padding: 1px;
  }

  .schedule-table th.day-header {
    width: auto;
    min-width: 0 !important;
  }

  .pin,
  .schedule-table th.pin {
    position: static;
    box-shadow: none;
  }

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

  .day-name {
    margin-top: 1px;
    font-size: 5.5px;
  }

  .group-title td {
    height: 17px;
    padding: 2px 4px;
    font-size: 7px;
  }

  .cell-value {
    font-size: 8px;
  }

  .cell-meta {
    margin-top: 0;
    font-size: 5px;
  }
}
