:root {
  --bg: #ffffff;
  --surface: #ffffff;

  --border: #e5e7eb;
  --border-hover: #d7dbe2;

  --text: #1f2937;
  --text-soft: #6b7280;
  --text-muted: #94a3b8;

  --shadow: 0 16px 40px rgba(17, 24, 39, 0.06);

  --page-padding-x: 24px;
  --page-padding-top: 10px;
  --topbar-height: 72px;
  --control-height: 44px;
  --radius: 10px;

  --violet-50: #faf7ff;
  --violet-100: #f4efff;
  --violet-150: #efe7ff;
  --violet-200: #e9ddff;
  --violet-300: #d7c2ff;
  --violet-400: #b79af8;
  --violet-500: #8b5cf6;
  --violet-600: #6f4bd8;
  --violet-700: #5a36b1;

  --green-50: #ecfdf3;
  --green-100: #dcfce7;
  --green-700: #166534;

  --amber-50: #fffbeb;
  --amber-100: #fef3c7;
  --amber-700: #92400e;

  --danger-500: #dc2626;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

.page {
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: var(--page-padding-top) var(--page-padding-x) 24px;
  background: #fff;
}

/* Topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--topbar-height);
  padding: 8px 0;
  background: var(--surface);
  flex-shrink: 0;
}

.topbar--stacked {
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
}

.topbar__main {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar__sub {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-top: 6px;
  padding-bottom: 2px;
  border-bottom: 1px solid #eef2f7;
}

/* Main layout */

.layout {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding-top: 8px;
}

.week-grid-card {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.week-grid-viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: #d9dee7 transparent;
}

.week-grid-viewport::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.week-grid-viewport::-webkit-scrollbar-track {
  background: transparent;
}

.week-grid-viewport::-webkit-scrollbar-thumb {
  background: #d9dee7;
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.week-grid-viewport::-webkit-scrollbar-thumb:hover {
  background: #cbd5e1;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.week-grid-viewport::-webkit-scrollbar-corner {
  background: transparent;
}

.week-grid-scroll {
  width: 100%;
}

/* Buttons and controls */

.toolbar-btn,
.icon-btn {
  height: var(--control-height);
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    border-color 0.18s ease,
    background-color 0.18s ease,
    color 0.18s ease,
    box-shadow 0.18s ease;
}

.toolbar-btn:hover,
.icon-btn:hover,
.period-box:hover {
  border-color: var(--border-hover);
  background: #fcfcfd;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
  font-size: 14px;
  font-weight: 400;
  white-space: nowrap;
}

.toolbar-btn--small {
  height: 38px;
  padding: 0 14px;
}

.toolbar-btn--dark {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}

.toolbar-btn--dark:hover {
  background: #111827;
  border-color: #111827;
}

.toolbar-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: var(--control-height);
  padding: 0;
}

.icon-btn span {
  display: inline-block;
  font-size: 24px;
  line-height: 1;
  transform: translateY(-1px);
  color: #4b5563;
}

/* Period controls */

.period-wrap {
  position: relative;
}

.period-box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 420px;
  height: var(--control-height);
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.period-box__label {
  margin-bottom: 2px;
  font-size: 10px;
  line-height: 1;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.period-box__value {
  font-size: 14px;
  line-height: 1.2;
  font-weight: 400;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.period-popover {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  width: 360px;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 30;
}

.period-popover.is-hidden {
  display: none;
}

.period-popover__title {
  margin-bottom: 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.period-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field--full {
  grid-column: 1 / -1;
}

.field__label {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-soft);
}

.field__control {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.field__control:focus {
  border-color: #cbd5e1;
  box-shadow: 0 0 0 3px rgba(111, 75, 216, 0.08);
}

.period-popover__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.period-copy-mode-hint {
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--text-soft);
  user-select: none;
}

.period-copy-mode-hint.is-hidden {
  display: none;
}

.period-week-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding: 2px;
}

.period-week-list__item {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition:
    border-color 0.18s ease,
    background-color 0.18s ease,
    color 0.18s ease,
    box-shadow 0.18s ease;
}

.period-week-list__item:hover {
  border-color: var(--border-hover);
  background: #fcfcfd;
}

.period-week-list__item.is-empty {
  color: var(--text-muted);
}

.period-week-list__item.is-current {
  border-color: #d6dbe4;
  background: #f8fafc;
  color: #111827;
}

.period-week-list__item.is-selected {
  background: var(--violet-150);
  border-color: var(--violet-300);
  color: var(--violet-700);
}

.period-week-list__item.is-range-start,
.period-week-list__item.is-range-end {
  background: var(--violet-600);
  border-color: var(--violet-600);
  color: #ffffff;
}

.period-week-list__label {
  font-size: 13px;
  font-weight: 400;
  line-height: 1.2;
}

/* Mini calendar */

.mini-calendar {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid #f1f5f9;
}

.mini-calendar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.mini-calendar__title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  text-transform: capitalize;
}

.mini-calendar__nav {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: #4b5563;
  cursor: pointer;
  transition: border-color 0.18s ease, background-color 0.18s ease, color 0.18s ease;
}

.mini-calendar__nav:hover {
  border-color: var(--border-hover);
  background: #fafafa;
  color: var(--text);
}

.mini-calendar__weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}

.mini-calendar__weekday {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 26px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.mini-calendar__weekday.is-weekend {
  color: #9f5f6f;
}

.mini-calendar__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.mini-calendar__day {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1 / 1;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition:
    transform 0.12s ease,
    border-color 0.18s ease,
    background-color 0.18s ease,
    color 0.18s ease,
    box-shadow 0.18s ease;
}

.mini-calendar__day:hover {
  background: #fafafa;
  border-color: #e5e7eb;
}

.mini-calendar__day-number {
  position: relative;
  z-index: 1;
  font-size: 13px;
  font-weight: 400;
  line-height: 1;
}

.mini-calendar__day.is-outside {
  color: #b6beca;
  background: #fcfcfd;
}

.mini-calendar__day.is-weekend:not(.is-selected) {
  color: #7f5563;
}

.mini-calendar__day.is-today:not(.is-selected) {
  border-color: #d8c8f4;
  background: var(--violet-50);
}

.mini-calendar__day.is-offday::after {
  content: '';
  position: absolute;
  inset: 4px;
  border: 2px solid var(--danger-500);
  border-radius: 999px;
  pointer-events: none;
}

.mini-calendar__day.is-selected {
  background: var(--violet-600);
  color: #fff;
  box-shadow: 0 6px 16px rgba(111, 75, 216, 0.22);
}

.mini-calendar__day.is-selected.is-offday::after {
  border-color: rgba(255, 255, 255, 0.94);
}

/* Table */

.week-grid {
  width: 100%;
  min-width: 1100px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  background: #fff;
}

.week-grid th,
.week-grid td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.week-grid th:last-child,
.week-grid td:last-child {
  border-right: none;
}

/* Sticky header and first column */

.week-grid thead th {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 54px;
  padding: 10px 12px;
  background: #fff;
  text-align: center;
  vertical-align: middle;
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
}

.week-grid thead .week-grid__day {
  z-index: 25;
  background: #fff;
}

.week-grid thead .week-grid__day.is-weekend {
  background: #fff;
}

.week-grid thead .week-grid__day.is-offday {
  background: linear-gradient(180deg, var(--violet-100) 0%, var(--violet-200) 100%);
  color: var(--violet-700);
}

.week-grid thead .week-grid__day.is-offday .week-grid__day-title {
  color: var(--violet-700);
  font-weight: 500;
}

.week-grid thead .week-grid__day.is-offday .week-grid__day-date {
  color: #6f56a8;
}

.week-grid__corner {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 35;
  width: 220px;
  min-width: 220px;
  color: var(--text-soft);
  text-align: center;
  background: #fff;
}

.week-grid__label-cell {
  position: sticky;
  left: 0;
  z-index: 10;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 300;
  color: var(--text-soft);
  white-space: normal;
  text-align: left;
  vertical-align: middle;
  background: #fff;
}

.week-grid__label-cell--group,
.week-grid__label-cell--subrow {
  background: #fff;
}

.week-grid tbody td {
  height: 52px;
  background: #fff;
  text-align: center;
  vertical-align: middle;
}

.week-grid__corner-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.week-grid__back-btn {
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
  font-weight: 400;
  cursor: pointer;
}

.week-grid__back-btn:hover {
  border-color: var(--border-hover);
  background: #fcfcfc;
}

.week-grid__day {
  width: calc((100% - 220px) / 7);
  cursor: pointer;
  background: #fff;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.week-grid__day:hover {
  background: #f8fafc;
}

.week-grid__day.is-offday {
  background: linear-gradient(180deg, var(--violet-100) 0%, var(--violet-200) 100%);
  color: var(--violet-700);
}

.week-grid__day-title-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.week-grid__day-title {
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  text-align: center;
}

.week-grid__day-date {
  margin-top: 3px;
  font-size: 12px;
  font-weight: 300;
  color: var(--text-soft);
  text-align: center;
}

.week-grid__day.is-offday .week-grid__day-title {
  color: var(--violet-700);
  font-weight: 500;
}

.week-grid__day.is-offday .week-grid__day-date {
  color: #6f56a8;
}

.week-grid__offday-badge {
  display: none;
}

.week-grid__cell {
  position: relative;
  padding: 0;
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
  background: #fff;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

.week-grid__cell.is-readonly {
  cursor: default;
}

.week-grid__cell-value {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 51px;
  padding: 0;
  margin: 0;
  border-radius: 0;
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  background: transparent;
}

.week-grid__cell--mark .week-grid__cell-value,
.week-grid__cell--mark .week-grid__sum {
  font-weight: 500;
  letter-spacing: 0.02em;
}

.week-grid tbody td.week-grid__cell.week-grid__cell--one {
  background: var(--green-100) !important;
}

.week-grid tbody td.week-grid__cell.week-grid__cell--custom {
  background: var(--amber-100) !important;
}

.week-grid__cell.is-offday,
.week-grid__cell.is-offday.is-weekend {
  background: #fff;
}

.week-grid__cell.is-offday .week-grid__sum {
  color: var(--text);
}

.week-grid__cell.is-offday.week-grid__cell--filled {
  box-shadow: none;
}

.week-grid__cell-input {
  display: block;
  width: 100%;
  height: 51px;
  margin: 0;
  padding: 0 8px;
  border: 0;
  border-radius: 0;
  outline: none;
  text-align: center;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 400;
}

.week-grid__sum {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
  background: #fff;
}

.week-grid__sum.is-empty {
  background: transparent;
  color: var(--text-soft);
}

.week-grid__cell.is-range-preview {
  background: rgba(111, 75, 216, 0.12);
  box-shadow: inset 0 0 0 1px rgba(111, 75, 216, 0.28);
}

/* Position cell */

.position-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: 100%;
}

.position-cell__title {
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  line-height: 1.2;
}

.position-cell__person-wrap {
  position: relative;
}

.position-cell__person-trigger {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 300;
  line-height: 1.2;
  cursor: pointer;
  text-decoration-line: underline;
  text-decoration-style: dashed;
  text-decoration-color: #b8c0cc;
  text-underline-offset: 3px;
}

.position-cell__person-trigger:hover {
  color: var(--text);
  text-decoration-color: #94a3b8;
}

.position-cell__person-trigger.is-static {
  display: inline-flex;
  align-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-soft);
  cursor: default;
  text-decoration: none;
  font: inherit;
}

.position-cell__person-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  max-width: 280px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 16px 40px rgba(17, 24, 39, 0.14);
  z-index: 50;
}

.position-cell__person-menu.is-hidden {
  display: none;
}

.position-cell__person-option {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 12px;
  font-weight: 300;
  cursor: pointer;
}

.position-cell__person-option:hover {
  background: #f8fafc;
}

.position-cell__person-option.is-active {
  background: #f3f4f6;
  font-weight: 400;
}

.position-cell__person-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  color: #111827;
}

.position-cell__person-check:hover {
  background: #f8fafc;
}

.position-cell__person-check input {
  margin: 0;
}

/* Footer */

.week-grid tfoot td,
.week-grid tfoot th {
  border-right: 1px solid var(--border);
  border-bottom: none;
  border-top: 1px solid var(--border);
  background: #fff;
}

.week-grid tfoot td:last-child,
.week-grid tfoot th:last-child {
  border-right: none;
}

.week-grid__footer-label {
  position: sticky;
  left: 0;
  z-index: 12;
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
  font-weight: 300;
  color: var(--text);
  background: #fff;
}

.week-grid__footer-cell {
  height: 46px;
  text-align: center;
  vertical-align: middle;
  background: #fff;
}

.week-grid__footer-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 300;
  color: var(--text);
  background: #f8fafc;
}

.week-grid__footer-value.is-empty {
  background: transparent;
  color: var(--text-soft);
}

.week-grid__footer-row--hours .week-grid__footer-label,
.week-grid__footer-row--fot .week-grid__footer-label {
  font-weight: 500;
}

.week-grid__footer-row--hours .week-grid__footer-label,
.week-grid__footer-row--hours .week-grid__footer-cell {
  background: #f6f1ff;
  color: #5b3db3;
}

.week-grid__footer-row--fot .week-grid__footer-label,
.week-grid__footer-row--fot .week-grid__footer-cell {
  background: #efe7ff;
  color: #4f36a3;
}

.week-grid__footer-row--hours .week-grid__footer-value,
.week-grid__footer-row--fot .week-grid__footer-value {
  background: transparent;
  min-width: 100%;
  min-height: 46px;
  padding: 0;
  border-radius: 0;
  font-weight: 500;
}

.week-grid__footer-row--hours .week-grid__footer-value {
  color: #5b3db3;
}

.week-grid__footer-row--fot .week-grid__footer-value {
  color: #4f36a3;
}

.week-grid__footer-row--hours .week-grid__footer-value.is-empty,
.week-grid__footer-row--fot .week-grid__footer-value.is-empty {
  color: #7b728f;
}

.week-grid__footer-row--hours .week-grid__footer-cell.is-offday {
  background: #f2ebff;
}

.week-grid__footer-row--fot .week-grid__footer-cell.is-offday {
  background: #eadfff;
}

.week-grid__footer-row--hours .week-grid__footer-cell.is-offday .week-grid__footer-value {
  color: #5334ab;
}

.week-grid__footer-row--fot .week-grid__footer-cell.is-offday .week-grid__footer-value {
  color: #472d99;
}

.week-grid__separator-row th,
.week-grid__separator-row td {
  height: 32px;
  padding: 0;
  border-top: none !important;
  border-bottom: none !important;
  border-right: 1px solid #e4d8fb;
  background: #ccb4f8;
}

.week-grid__separator-row th:last-child,
.week-grid__separator-row td:last-child {
  border-right: none;
}

/* Context menu and tooltip */

.day-context-menu {
  position: fixed;
  min-width: 220px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(17, 24, 39, 0.08);
  z-index: 1000;
}

.day-context-menu.is-hidden {
  display: none;
}

.day-context-menu__item {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
}

.day-context-menu__item:hover {
  background: #f8fafc;
}

.day-context-menu__item.is-disabled,
.day-context-menu__item:disabled {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

.week-grid__drag-tooltip {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  padding: 8px 10px;
  border-radius: 10px;
  background: #111827;
  color: #fff;
  font-size: 12px;
  line-height: 1;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(17, 24, 39, 0.18);
}

.week-grid__drag-tooltip.is-hidden {
  display: none;
}

/* Plan / Fact tabs */

.mode-switch {
  display: inline-flex;
  align-items: flex-end;
  gap: 34px;
  padding: 0 2px;
  border: none;
  background: transparent;
  border-radius: 0;
}

.mode-switch__btn {
  position: relative;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-soft);
  font: inherit;
  font-size: 17px;
  font-weight: 400;
  line-height: 1;
  padding: 0 2px 14px;
  border-radius: 0;
  cursor: pointer;
  transition: color 0.18s ease;
}

.mode-switch__btn:hover {
  background: transparent;
  color: var(--text);
}

.mode-switch__btn::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  border-radius: 999px;
  background: transparent;
  transition: background-color 0.18s ease, transform 0.18s ease;
  transform: scaleX(0.7);
  transform-origin: center;
}

.mode-switch__btn.is-active {
  background: transparent;
  color: var(--violet-600);
  box-shadow: none;
}

.mode-switch__btn.is-active::after {
  background: var(--violet-600);
  transform: scaleX(1);
}

/* Fact selection modal */

.fact-selection-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.fact-selection-modal.is-hidden {
  display: none;
}

.fact-selection-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.22);
  backdrop-filter: blur(6px);
}

.fact-selection-modal__dialog {
  position: relative;
  width: min(680px, calc(100vw - 32px));
  margin: 0;
  background: #fff;
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 20px;
  box-shadow:
    0 24px 60px rgba(15, 23, 42, 0.16),
    0 8px 24px rgba(15, 23, 42, 0.08);
  padding: 28px;
}

.fact-selection-modal__title {
  font-size: 20px;
  line-height: 1.25;
  font-weight: 600;
  color: #0f172a;
  letter-spacing: -0.02em;
  margin-bottom: 10px;
}

.fact-selection-modal__text {
  font-size: 15px;
  line-height: 1.55;
  color: #475569;
  margin-bottom: 22px;
}

.fact-selection-modal__actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
}

.fact-selection-modal__btn {
  appearance: none;
  height: 46px;
  padding: 0 18px;
  border-radius: 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color 0.18s ease,
    border-color 0.18s ease,
    color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.12s ease;
}

.fact-selection-modal__btn:active {
  transform: translateY(1px);
}

.fact-selection-modal__btn--secondary {
  flex: 1 1 0;
  min-width: 0;
  border: 1px solid #8b5cf6;
  background: #8b5cf6;
  color: #fff;
  box-shadow: 0 8px 20px rgba(139, 92, 246, 0.22);
}

.fact-selection-modal__btn--secondary:hover {
  background: #7c3aed;
  border-color: #7c3aed;
  box-shadow: 0 10px 24px rgba(124, 58, 237, 0.26);
}

.fact-selection-modal__btn--primary {
  flex: 1 1 0;
  min-width: 0;
  border: 1px solid #c4b5fd;
  background: #fff;
  color: #6d28d9;
}

.fact-selection-modal__btn--primary:hover {
  background: #faf7ff;
  border-color: #a78bfa;
}

.fact-selection-modal__btn:not(.fact-selection-modal__btn--primary):not(.fact-selection-modal__btn--secondary) {
  flex: 0 0 auto;
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #64748b;
}

.fact-selection-modal__btn:not(.fact-selection-modal__btn--primary):not(.fact-selection-modal__btn--secondary):hover {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #334155;
}

/* Responsive */

@media (max-width: 900px) {
  .topbar__main {
    align-items: stretch;
  }

  .topbar__sub {
    justify-content: flex-start;
    padding-top: 8px;
  }

  .mode-switch {
    width: auto;
    gap: 24px;
  }

  .mode-switch__btn {
    flex: 0 0 auto;
    justify-content: flex-start;
    font-size: 16px;
    padding-bottom: 12px;
  }
}

@media (max-width: 760px) {
  .page {
    padding: 8px 14px 16px;
  }

  .topbar {
    flex-wrap: wrap;
    padding: 6px 0;
  }

  .period-wrap,
  .period-box,
  .period-popover {
    width: 100%;
    min-width: 0;
  }

  .period-form {
    grid-template-columns: 1fr;
  }

  .period-week-list {
    grid-template-columns: 1fr;
  }

  .layout {
    padding-top: 6px;
  }

  .week-grid-card {
    border-radius: 10px;
  }

  .week-grid {
    min-width: 920px;
  }

  .week-grid__corner {
    width: 180px;
    min-width: 180px;
  }

  .mini-calendar__day {
    min-height: 36px;
  }
}

@media (max-width: 720px) {
  .fact-selection-modal__dialog {
    width: min(520px, calc(100vw - 24px));
    padding: 22px;
    border-radius: 18px;
  }

  .fact-selection-modal__actions {
    flex-direction: column;
    align-items: stretch;
  }

  .fact-selection-modal__btn,
  .fact-selection-modal__btn--secondary,
  .fact-selection-modal__btn--primary {
    width: 100%;
    flex: none;
  }
}