:root {
  --page: #eef2f3;
  --panel: #ffffff;
  --panel-muted: #f7f9fa;
  --ink: #17212b;
  --ink-soft: #384753;
  --muted: #6b7784;
  --line: #d9e0e3;
  --line-strong: #b9c4ca;
  --primary: #13745e;
  --primary-hover: #0d5c4b;
  --blue: #245f9e;
  --blue-soft: #e8f0f8;
  --green-soft: #e6f4ef;
  --amber: #94640c;
  --amber-soft: #fff3d8;
  --red: #b33a3a;
  --red-soft: #fff0f0;
  --shadow: 0 18px 45px rgba(31, 45, 55, 0.11);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  color-scheme: light;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

body.dialog-open {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.button-link {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 7px 12px;
  color: var(--ink);
  background: #fff;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(36, 95, 158, 0.14);
  transition: border-color 140ms ease, background-color 140ms ease, color 140ms ease, box-shadow 140ms ease;
}

button:hover,
.button-link:hover {
  border-color: var(--blue);
  color: var(--blue);
}

button:focus-visible,
.button-link:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(36, 95, 158, 0.18);
  outline-offset: 1px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

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

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

button.danger {
  border-color: #e0b5b5;
  color: var(--red);
  background: #fff;
}

button.danger:hover {
  border-color: var(--red);
  background: var(--red-soft);
}

.compact-btn {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 13px;
}

a {
  color: var(--blue);
  overflow-wrap: anywhere;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 100;
  transform: translateY(-140%);
  border: 1px solid var(--blue);
  border-radius: 6px;
  padding: 8px 12px;
  color: #fff;
  background: var(--blue);
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform 140ms ease;
}

.skip-link:focus-visible {
  transform: translateY(0);
}

.app-shell {
  width: min(1360px, 100%);
  margin: 0 auto;
  padding: calc(22px + env(safe-area-inset-top)) calc(22px + env(safe-area-inset-right)) calc(22px + env(safe-area-inset-bottom)) calc(22px + env(safe-area-inset-left));
}

.employee-shell {
  max-width: 1180px;
}

.login-panel {
  width: min(430px, calc(100vw - 32px));
  margin: 10vh auto 0;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.brand-block {
  margin-bottom: 22px;
}

.brand-block h1,
.topbar h1 {
  margin: 7px 0 0;
  font-size: 30px;
  line-height: 1.15;
  font-weight: 760;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.eyebrow,
.section-kicker {
  display: block;
  color: var(--primary);
  font-size: 12px;
  font-weight: 760;
}

.topbar {
  display: flex;
  gap: 20px;
  align-items: flex-end;
  justify-content: space-between;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.topbar > div,
.brand-block,
.section-head > div,
.preview-toolbar > div {
  min-width: 0;
}

.topbar-actions,
.row-actions,
.link-row,
.preview-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

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

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

.summary-item {
  min-width: 0;
  min-height: 76px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.summary-item span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 680;
}

.summary-item strong {
  display: block;
  margin-top: 6px;
  font-size: 28px;
  line-height: 1;
  font-weight: 780;
  font-variant-numeric: tabular-nums;
}

.tabs {
  display: flex;
  gap: 6px;
  margin: 0 0 14px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e2e8eb;
  overflow-x: auto;
}

.tabs button {
  min-width: 92px;
  border-color: transparent;
  background: transparent;
  white-space: nowrap;
}

.tabs button.active,
.tabs button[aria-current="page"] {
  border-color: var(--line);
  color: var(--primary-hover);
  background: var(--panel);
  box-shadow: 0 2px 10px rgba(31, 45, 55, 0.08);
}

.workspace-section {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-head h2,
.preview-toolbar h3 {
  margin: 3px 0 0;
  font-size: 22px;
  line-height: 1.2;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.stack-form,
.grid-form {
  display: grid;
  gap: 12px;
}

.grid-form {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: end;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-muted);
}

.settings-form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.schedule-form {
  grid-template-columns: 0.9fr 0.8fr 2.2fr 1.2fr auto;
}

.task-form {
  grid-template-columns: 1.2fr 1fr 0.72fr 1fr auto;
}

label {
  display: grid;
  min-width: 0;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 680;
}

.checkbox-label {
  display: flex;
  min-height: 38px;
  align-items: center;
  gap: 9px;
  color: var(--ink);
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
  accent-color: var(--primary);
}

.table-check {
  min-height: auto;
}

.weekday-field {
  display: flex;
  min-height: 38px;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
}

.weekday-field legend {
  padding: 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 680;
}

.weekday-field label {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  gap: 5px;
  color: var(--ink);
  font-size: 13px;
}

.weekday-field input {
  width: 15px;
  min-height: 15px;
  accent-color: var(--primary);
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
  -webkit-tap-highlight-color: rgba(36, 95, 158, 0.12);
}

textarea {
  resize: vertical;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  border-color: var(--blue);
}

input::placeholder,
textarea::placeholder {
  color: #9aa5ad;
}

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

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

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

th {
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 760;
  background: #f1f5f6;
}

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

tbody tr:hover {
  background: #fbfcfd;
}

td input,
td select,
td textarea {
  min-width: 150px;
}

.message,
.error-text,
.muted-line {
  margin: 0 0 14px;
}

.message {
  padding: 10px 12px;
  border: 1px solid #b6d8ce;
  border-radius: 6px;
  color: #0f5948;
  background: var(--green-soft);
}

.message.error,
.error-text {
  color: var(--red);
}

.message.error {
  border-color: #e6bbbb;
  background: var(--red-soft);
}

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

.status {
  display: inline-flex;
  min-width: 52px;
  min-height: 24px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

.status.success {
  color: #0f5b48;
  background: var(--green-soft);
}

.status.error {
  color: var(--amber);
  background: var(--amber-soft);
}

.history-list td:nth-child(4) {
  max-width: 420px;
}

.qr-code {
  display: block;
  width: 86px;
  height: 86px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.progress-edit {
  display: grid;
  grid-template-columns: minmax(96px, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.expected-control {
  display: grid;
  grid-template-columns: minmax(116px, 0.42fr) minmax(120px, 0.58fr);
  gap: 8px;
}

.expected-control-inline {
  min-width: 260px;
}

.expected-control.is-fixed-option input {
  color: var(--muted);
  background: #eef3f4;
}

.date-input {
  cursor: pointer;
}

.calendar-popover {
  position: absolute;
  z-index: 30;
  width: min(320px, calc(100vw - 24px));
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  overscroll-behavior: contain;
}

.calendar-head {
  display: grid;
  grid-template-columns: 68px 1fr 68px;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.calendar-head strong {
  text-align: center;
}

.calendar-head button {
  min-height: 30px;
  padding: 4px 8px;
  font-size: 13px;
}

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

.calendar-weekdays {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  text-align: center;
}

.calendar-day,
.calendar-blank {
  min-height: 42px;
}

.calendar-day {
  display: grid;
  gap: 1px;
  align-content: center;
  border-color: var(--line);
  padding: 4px 2px;
  font-size: 13px;
}

.calendar-day small {
  display: block;
  min-height: 14px;
  color: var(--red);
  font-size: 10px;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-day.is-weekend {
  background: #f7f9fa;
}

.calendar-day.is-holiday {
  border-color: #e7b4b4;
  background: var(--red-soft);
}

.calendar-day.is-selected {
  border-color: var(--primary);
  color: #fff;
  background: var(--primary);
}

.calendar-day.is-selected small {
  color: #fff;
}

.progress-edit span {
  min-width: 46px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

.preview-dialog {
  width: min(1180px, calc(100vw - 28px));
  height: min(860px, calc(100vh - 28px));
  max-width: none;
  max-height: none;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overscroll-behavior: contain;
}

.preview-dialog::backdrop {
  background: rgba(19, 29, 38, 0.58);
}

.preview-panel {
  display: grid;
  height: 100%;
  grid-template-rows: auto minmax(0, 1fr);
}

.preview-toolbar {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-muted);
}

.preview-toolbar p {
  margin: 7px 0 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

iframe {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 460px;
  border: 0;
  background: #fff;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (max-width: 1040px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

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

  .grid-form,
  .settings-form,
  .schedule-form,
  .task-form {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: calc(12px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  }

  .topbar,
  .workspace-section,
  .login-panel {
    padding: 14px;
  }

  .brand-block h1,
  .topbar h1 {
    font-size: 24px;
  }

  .summary-strip,
  .compact-summary,
  .grid-form,
  .settings-form,
  .schedule-form,
  .task-form {
    grid-template-columns: 1fr;
  }

  .summary-item {
    min-height: 68px;
  }

  .summary-item strong {
    font-size: 24px;
  }

  .tabs button {
    min-width: auto;
  }

  .table-wrap {
    border: 0;
    overflow: visible;
    background: transparent;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
  }

  thead {
    display: none;
  }

  tr {
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: minmax(92px, 0.36fr) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    border-bottom: 1px solid var(--line);
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 760;
  }

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

  td input,
  td select,
  td textarea {
    min-width: 0;
  }

  .empty-cell {
    display: block;
  }

  .empty-cell::before {
    content: none;
  }

  .row-actions,
  .topbar-actions,
  .preview-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .expected-control,
  .expected-control-inline {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .row-actions button,
  .topbar-actions button,
  .preview-actions button,
  .preview-actions .button-link {
    width: 100%;
  }

  .qr-code {
    width: 120px;
    height: 120px;
  }

  .calendar-popover {
    left: 12px !important;
    right: 12px;
    width: auto;
  }

  .preview-dialog {
    width: 100vw;
    height: 100vh;
    border-radius: 0;
  }

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