:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --border: #d8dee8;
  --text: #172033;
  --muted: #637083;
  --primary: #0f766e;
  --primary-strong: #115e59;
  --danger: #b42318;
  --shadow: 0 8px 24px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 28px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

h1 {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0;
}

p {
  margin: 0;
  color: var(--muted);
}

main {
  padding: 18px 28px 32px;
}

.header-actions,
.toolbar,
.tabs,
.legend {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

input,
select {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 6px 8px;
}

button,
.button {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 7px 11px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

button:hover,
.button:hover {
  border-color: #aab4c2;
}

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

.primary:hover {
  border-color: var(--primary-strong);
  background: var(--primary-strong);
}

.danger {
  border-color: #fecaca;
  color: var(--danger);
}

.tabs {
  margin-bottom: 12px;
}

.tab.active {
  background: #172033;
  border-color: #172033;
  color: #fff;
}

.status {
  min-height: 24px;
  margin-bottom: 12px;
  color: var(--muted);
}

.status.error {
  color: var(--danger);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar {
  justify-content: space-between;
  margin-bottom: 12px;
}

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

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

.swatch {
  width: 14px;
  height: 14px;
  border: 1px solid rgba(0, 0, 0, 0.16);
  border-radius: 3px;
}

.matrix-wrap,
.table-wrap {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.matrix-wrap {
  overflow-x: hidden;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
}

th,
td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 6px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 700;
  color: #334155;
}

tfoot th {
  border-top: 2px solid var(--border);
  background: #e2e8f0;
}

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

th:last-child,
td:last-child {
  border-right: 0;
}

.matrix {
  table-layout: fixed;
  min-width: 0;
}

.matrix th.day {
  position: relative;
  width: auto;
  text-align: center;
  padding: 4px 2px;
  font-size: 11px;
  line-height: 1.05;
}

.matrix th.day span,
.matrix th.day strong {
  display: block;
}

.day-head {
  position: relative;
  min-height: 28px;
}

.matrix th.weekend {
  background: #d9dee7;
}

.matrix td.weekend {
  background: #f1f3f6;
}

.matrix td.weekend select {
  border-color: #c5cbd5;
}

.matrix th.person,
.matrix td.person {
  position: sticky;
  left: 0;
  z-index: 2;
  width: 150px;
  background: #fff;
}

.matrix td.person {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.matrix th.person {
  z-index: 3;
  background: var(--surface-2);
}

.matrix td.meta,
.matrix th.meta {
  width: 44px;
  padding: 4px;
  text-align: right;
}

.matrix select {
  appearance: none;
  width: 100%;
  min-width: 0;
  height: 26px;
  min-height: 26px;
  padding: 2px 1px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
}

.matrix.dragging-fill {
  cursor: col-resize;
  user-select: none;
}

.matrix td.fill-preview {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  background: #ccfbf1;
}

.cell-shell {
  position: relative;
}

.plan-warning {
  position: absolute;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  min-height: 14px;
  border: 1px solid #fff;
  border-radius: 50%;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 1px 2px rgba(23, 32, 51, 0.18);
  pointer-events: auto;
}

.matrix th.day .plan-warning {
  display: inline-flex;
}

.plan-warning.open {
  background: var(--danger);
}

.plan-warning.confirmed {
  background: var(--primary);
}

.day-warning {
  top: -2px;
  right: 1px;
}

.cell-warning {
  left: -3px;
  top: -5px;
}

.fill-handle {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 10px;
  height: 10px;
  min-height: 10px;
  padding: 0;
  border: 1px solid rgba(15, 118, 110, 0.65);
  border-radius: 2px;
  background: var(--primary);
  cursor: col-resize;
  opacity: 0;
  touch-action: none;
}

.cell-shell:hover .fill-handle {
  opacity: 1;
}

.matrix.dragging-fill .fill-handle {
  opacity: 0;
}

.matrix.dragging-fill .fill-handle.drag-origin {
  opacity: 1;
}

.fill-handle:focus-visible {
  opacity: 1;
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.comment-dot {
  position: absolute;
  right: -2px;
  top: -4px;
  width: 8px;
  height: 8px;
  min-height: 8px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid #fff;
  background: #f59e0b;
  opacity: 0;
}

.comment-dot.has-comment,
.cell-shell:hover .comment-dot,
.comment-dot:focus-visible {
  opacity: 1;
}

.comment-dot:not(.has-comment) {
  background: #94a3b8;
}

.comment-dot:focus-visible {
  outline: 2px solid #f59e0b;
  outline-offset: 2px;
}

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

.user-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}

.current-user {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  display: grid;
  gap: 12px;
  width: min(340px, 90vw);
  padding: 26px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0;
}

.login-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
}

.month-nav button {
  min-width: 34px;
  padding: 7px 8px;
  font-weight: 700;
}

.data-table tr.clickable {
  cursor: pointer;
}

.data-table tr.clickable:hover td {
  background: #f0fdfa;
}

.data-table tr.selected-row td {
  background: #ccfbf1;
}

.year-wrap {
  margin-bottom: 16px;
}

.year-matrix td {
  height: 26px;
  padding: 2px 1px;
  text-align: center;
}

.year-matrix td.no-day {
  background: var(--surface-2);
}

.year-code {
  display: block;
  min-width: 0;
  padding: 3px 0;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.month-link {
  min-height: auto;
  border: 0;
  background: none;
  padding: 0;
  color: var(--primary-strong);
  font-weight: 600;
  cursor: pointer;
}

.month-link:hover {
  text-decoration: underline;
  border: 0;
}

.section-title {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 700;
}

#statisticsView .section-title {
  margin-top: 16px;
}

#statisticsView .table-wrap {
  margin-bottom: 8px;
}

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

.notice em {
  font-style: normal;
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.form-grid > * {
  min-width: 0;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  color: var(--text);
  font-size: 14px;
}

.check-field input {
  min-height: auto;
}

.data-table input,
.data-table select {
  width: 100%;
}

.data-table .flag-cell {
  min-width: 190px;
}

.mini-check {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin: 1px 6px 1px 0;
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
}

.mini-check input {
  width: auto;
  min-height: auto;
}

.data-table td.actions {
  white-space: nowrap;
  width: 1%;
}

.data-table .number {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.statistics-table {
  min-width: 980px;
}

.positive {
  color: var(--primary-strong);
  font-weight: 700;
}

.negative {
  color: var(--danger);
  font-weight: 700;
}

.warning-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.warning-panel {
  min-width: 0;
}

.warning-card {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100%;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.warning-card.warning {
  border-color: #f59e0b;
}

.warning-card.ok {
  border-color: #99f6e4;
}

.warning-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.warning-card-header h3 {
  margin: 0 0 3px;
  font-size: 14px;
  line-height: 1.2;
}

.warning-card-header p {
  font-size: 12px;
}

.warning-card-status {
  display: flex;
  align-items: flex-end;
  flex-direction: column;
  gap: 5px;
  white-space: nowrap;
}

.warning-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
}

.warning-chip.warning {
  border-color: #f59e0b;
  background: #fffbeb;
  color: #92400e;
}

.warning-chip.ok {
  border-color: #5eead4;
  background: #f0fdfa;
  color: var(--primary-strong);
}

.warning-chip.muted {
  color: var(--muted);
  font-weight: 600;
}

.warning-items {
  display: grid;
  align-content: start;
}

.warning-item {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) auto;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.warning-item:last-child {
  border-bottom: 0;
}

.warning-item.warning {
  background: #fff8e6;
}

.warning-item.confirmed {
  background: #f8fafc;
  color: var(--muted);
}

.warning-date {
  color: #334155;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.warning-content {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.warning-meta,
.warning-message {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 8px;
  min-width: 0;
}

.warning-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.warning-message {
  color: var(--text);
}

.warning-type {
  color: #92400e;
  font-weight: 800;
}

.warning-confirmed {
  color: var(--muted);
  font-size: 12px;
}

.warning-actions {
  display: flex;
  align-items: flex-start;
}

.warning-actions button {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
}

.warning-empty {
  padding: 14px 12px;
  color: var(--muted);
  font-size: 13px;
}

.warning-empty.ok {
  background: #f0fdfa;
  color: var(--primary-strong);
}

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

.help-section {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.help-section h2 {
  margin: 0 0 12px;
  font-size: 16px;
  line-height: 1.2;
}

.help-section dl {
  display: grid;
  gap: 12px;
  margin: 0;
}

.help-section dt {
  margin-bottom: 3px;
  color: #334155;
  font-size: 13px;
  font-weight: 800;
}

.help-section dd {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.inactive {
  color: var(--muted);
  background: #f8fafc;
}

@media (max-width: 900px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
    padding: 18px;
  }

  main {
    padding: 14px;
  }

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

  .warning-board {
    grid-template-columns: 1fr;
  }

  .help-layout {
    grid-template-columns: 1fr;
  }
}

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

  .warning-card-header {
    flex-direction: column;
  }

  .warning-card-status {
    align-items: flex-start;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .warning-item {
    grid-template-columns: 1fr;
  }

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