:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #65717a;
  --line: #dce3e8;
  --soft: #f4f7f9;
  --paper: #ffffff;
  --blue: #1f6feb;
  --blue-soft: #e8f1ff;
  --green: #087f5b;
  --green-soft: #e6fcf5;
  --red: #c92a2a;
  --red-soft: #fff0f0;
  --amber: #b7791f;
  --amber-soft: #fff4e6;
  --violet: #6741d9;
  --violet-soft: #f0ebff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  background:
    linear-gradient(180deg, rgba(31, 111, 235, .10), rgba(8, 127, 91, .06) 280px, transparent 520px),
    #eef3f6;
  color: var(--ink);
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.toolbar {
  background: rgba(255, 255, 255, .78);
  border: 1px solid rgba(220, 227, 232, .9);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 18px;
  padding: 18px;
  box-shadow: 0 8px 30px rgba(23, 32, 38, .06);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 22px;
}

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

.file-button,
.secondary-button,
.danger-button {
  border: 0;
  border-radius: 8px;
  background: var(--blue);
  color: white;
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
  padding: 12px 16px;
  transition: background .2s, opacity .2s;
}

.file-button:hover,
.secondary-button:hover,
.danger-button:hover {
  opacity: .88;
}

.file-button input {
  display: none;
}

.secondary-button {
  background: #27313a;
}

.danger-button {
  background: #c92a2a;
}

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

.toolbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.empty-state,
.panel,
.stats article {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.empty-state {
  min-height: 320px;
  display: grid;
  place-items: center;
  padding: 32px;
  text-align: center;
}

.empty-state p {
  color: var(--muted);
  line-height: 1.5;
  margin-top: 10px;
  max-width: 520px;
}

.hidden {
  display: none !important;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.period-panel {
  align-items: end;
  background: rgba(255, 255, 255, .86);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(23, 32, 38, .05);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(170px, 220px) minmax(210px, 260px) minmax(220px, 1fr);
  margin-bottom: 12px;
  padding: 14px;
}

.period-panel label,
.period-range span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 7px;
  text-transform: uppercase;
}

.period-panel input,
.period-panel select {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 15px;
  min-height: 42px;
  padding: 9px 11px;
  width: 100%;
}

.period-range {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 42px;
  padding: 10px 12px;
}

.period-range strong {
  display: block;
  font-size: 15px;
}

.stats article,
.person-summary article {
  min-width: 0;
  padding: 16px;
}

.stats article:nth-child(1) {
  background: var(--blue-soft);
  border-color: #bfdbfe;
}

.stats article:nth-child(2) {
  background: var(--violet-soft);
  border-color: #d0bfff;
}

.stats article:nth-child(3) {
  background: var(--red-soft);
  border-color: #ffc9c9;
}

.stats article:nth-child(4) {
  background: var(--amber-soft);
  border-color: #ffd8a8;
}

.clickable-stat {
  cursor: pointer;
  transition: border-color .2s, box-shadow .2s, transform .2s;
}

.clickable-stat:hover,
.clickable-stat.active {
  border-color: currentColor;
  box-shadow: 0 8px 24px rgba(23, 32, 38, .14);
}

.clickable-stat:focus-visible {
  outline: 3px solid rgba(31, 111, 235, .25);
  outline-offset: 2px;
}

.clickable-stat.active {
  transform: translateY(-1px);
}

.stats span,
.person-summary span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-bottom: 8px;
}

.stats strong,
.person-summary strong {
  display: block;
  font-size: clamp(20px, 3vw, 28px);
  line-height: 1.05;
}

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

.panel {
  min-height: 520px;
  padding: 18px;
  box-shadow: 0 8px 24px rgba(23, 32, 38, .05);
}

.search-panel {
  background: linear-gradient(180deg, #ffffff, #f8fbfd);
}

.result-panel {
  background: linear-gradient(180deg, #ffffff, #fbfcfd);
}

.search-panel label {
  color: var(--muted);
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
}

input[type="search"] {
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 16px;
  padding: 12px;
  width: 100%;
}

.filter-pill {
  background: #fff4e6;
  border: 1px solid #ffd8a8;
  border-radius: 999px;
  color: var(--amber);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  margin-top: 10px;
  padding: 8px 12px;
  width: 100%;
}

.people-list {
  margin-top: 14px;
  max-height: 610px;
  overflow: auto;
}

.person-row {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  display: block;
  padding: 12px 10px;
  text-align: left;
  width: 100%;
}

.person-row:hover,
.person-row.active {
  background: var(--soft);
}

.person-row strong {
  display: block;
  font-size: 14px;
  margin-bottom: 4px;
}

.person-row span,
.muted {
  color: var(--muted);
}

.person-empty {
  color: var(--muted);
  display: grid;
  min-height: 420px;
  place-items: center;
  text-align: center;
}

.person-header {
  align-items: start;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.person-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.person-summary article {
  background: linear-gradient(180deg, var(--soft), #ffffff);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

table {
  border-collapse: collapse;
  min-width: 760px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  padding: 11px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  position: sticky;
  top: 0;
  text-transform: uppercase;
  z-index: 1;
}

tbody tr:nth-child(even) {
  background: #fbfdfe;
}

.chip {
  border-radius: 999px;
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
}

.chip.day {
  background: #e6fcf5;
  color: var(--green);
}

.chip.night {
  background: #e7f0ff;
  color: var(--blue);
}

.chip.na {
  background: #edf0f2;
  color: var(--muted);
}

.alert-text {
  color: var(--red);
  font-weight: 700;
}

.ok-text {
  color: var(--green);
  font-weight: 700;
}

/* Toast notification */
.toast-container {
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  position: fixed;
  right: 20px;
  z-index: 1000;
  max-width: 400px;
}

.toast {
  animation: toastSlideIn .3s ease-out;
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(23, 32, 38, .15);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  padding: 14px 18px;
  pointer-events: auto;
  word-break: break-word;
}

.toast-success {
  background: #e6fcf5;
  border: 1px solid #b2dfdb;
  color: var(--green);
}

.toast-error {
  background: #fff0f0;
  border: 1px solid #ffc9c9;
  color: var(--red);
}

.toast-info {
  background: #e8f1ff;
  border: 1px solid #bfdbfe;
  color: var(--blue);
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Loading overlay */
.loading-overlay {
  align-items: center;
  background: rgba(23, 32, 38, .35);
  display: flex;
  flex-direction: column;
  gap: 16px;
  inset: 0;
  justify-content: center;
  position: fixed;
  z-index: 999;
}

.loading-overlay p {
  background: var(--paper);
  border-radius: 8px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  padding: 12px 18px;
}

.loading-spinner {
  animation: spin .6s linear infinite;
  border: 4px solid rgba(255, 255, 255, .25);
  border-radius: 50%;
  border-top-color: white;
  height: 36px;
  width: 36px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 860px) {
  .toolbar,
  .person-header {
    align-items: stretch;
    flex-direction: column;
  }

  .stats,
  .period-panel,
  .workbench {
    grid-template-columns: 1fr;
  }

  .toolbar-actions {
    flex-direction: column;
  }

  .toolbar-actions .file-button,
  .toolbar-actions .secondary-button,
  .toolbar-actions .danger-button {
    text-align: center;
    width: 100%;
  }

  .person-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding: 10px 0 18px;
  }

  .toolbar,
  .panel {
    padding: 14px;
  }

  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 20px;
  }

  .file-button,
  .secondary-button,
  .danger-button {
    width: 100%;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats article,
  .person-summary article {
    padding: 13px;
  }

  .stats span,
  .person-summary span {
    font-size: 12px;
  }

  .person-summary {
    grid-template-columns: 1fr;
  }

  .people-list {
    max-height: 320px;
  }

  th,
  td {
    font-size: 13px;
    padding: 10px 8px;
  }
}

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

@media print {
  body {
    background: white;
  }

  .toolbar,
  .search-panel,
  .stats,
  .secondary-button,
  .danger-button {
    display: none !important;
  }

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

  .workbench {
    display: block;
  }

  .panel {
    border: 0;
    min-height: 0;
    padding: 0;
  }
}
