:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5b6573;
  --border: #d9dee5;
  --primary: #1f5fbf;
  --primary-dark: #174a96;
  --office: #2f6fd6;
  --office-bg: #e3edfc;
  --home: #1e8a4c;
  --home-bg: #e1f4e8;
  --sick: #c43b3b;
  --sick-bg: #fbe5e5;
  --vacation: #a87400;
  --vacation-bg: #fdf1d3;
  --holiday-bg: #ece7f6;
  --holiday: #6a4fa3;
  --open: #d97706;
  --plus: #1e7a43;
  --minus: #b42318;
  --radius: 12px;
  --gap: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
}

a { color: var(--primary); }
a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

h1 { font-size: 1.5rem; margin: 0 0 .75rem; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
}

.muted { color: var(--muted); font-weight: normal; }
.hint { color: var(--muted); font-size: .9rem; margin: .5rem 0 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.nav {
  display: flex;
  max-width: 960px;
  margin: 0 auto;
  overflow-x: auto;
}
.nav a {
  flex: 1 0 auto;
  padding: 14px 12px;
  text-align: center;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 3px solid transparent;
  min-height: 48px;
}
.nav a.is-current { color: var(--primary); border-bottom-color: var(--primary); }

.flash { padding: 12px 14px; border-radius: var(--radius); margin: 0 0 var(--gap); }
.flash-ok { background: var(--home-bg); color: #14532d; }
.flash-error { background: var(--sick-bg); color: #7f1d1d; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--border);
  font-size: .85rem;
  margin: 0 0 .75rem;
}
.badge-holiday { background: var(--holiday-bg); color: var(--holiday); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--minus); border-color: #f0b4b4; }
.btn-small { min-height: 40px; padding: 6px 12px; font-size: .9rem; }

.status { margin: 0 0 var(--gap); font-size: 1.05rem; }

.type-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: var(--gap);
}
.type-btn {
  min-height: 96px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  font: inherit;
  font-size: 1.25rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform .05s ease;
}
.type-btn:active { transform: scale(.98); }
.type-btn.type-office { background: var(--office-bg); color: var(--office); }
.type-btn.type-home { background: var(--home-bg); color: var(--home); }
.type-btn.type-sick { background: var(--sick-bg); color: var(--sick); }
.type-btn.type-vacation { background: var(--vacation-bg); color: var(--vacation); }
.type-btn.is-active { border-color: currentColor; box-shadow: inset 0 0 0 2px currentColor; }
.type-btn.is-active::after { content: " ✓"; }

.adjust {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: var(--gap);
}
.adjust summary {
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 600;
  min-height: 48px;
}
.adjust-body { padding: 0 16px 16px; }

.field-label { display: block; font-weight: 600; margin: 12px 0 6px; }

.stepper { display: flex; align-items: stretch; gap: 8px; }
.stepper input { width: 6rem; text-align: center; font-size: 1.25rem; }
.step-btn {
  width: 56px;
  min-height: 52px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 1.5rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
}

input[type="text"], input[type="number"], input[type="password"], input[type="date"], input[type="file"] {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.stepper input[type="number"] { width: 6.5rem; }

label { display: block; }
.stack > * + * { margin-top: 12px; }
.stack label, .row-2 label, .inline-form label { font-weight: 600; }
.stack label input, .row-2 label input, .inline-form label input { margin-top: 6px; font-weight: normal; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 12px;
  font-weight: normal !important;
  cursor: pointer;
}
.check input { width: 22px; height: 22px; margin: 2px 0 0; flex: 0 0 auto; }

.row-2 { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 640px) {
  .row-2 { grid-template-columns: 1fr 1fr; }
}
.custom-range { align-items: end; margin-bottom: var(--gap); }
@media (min-width: 640px) {
  .custom-range { grid-template-columns: 1fr 1fr auto; }
}

.radio-row { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px 16px; }
.radio-row legend { font-weight: 600; margin-bottom: 6px; }
.radio { display: flex; align-items: center; gap: 6px; min-height: 44px; }
.radio input { width: 20px; height: 20px; }

.banner {
  background: #fff7e6;
  border: 1px solid #f5d08a;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: var(--gap);
}
.banner p { margin: 0 0 10px; }
.banner-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.kpis {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: var(--gap) 0;
}
@media (min-width: 640px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
}
.kpi-label { color: var(--muted); font-size: .85rem; }
.kpi-value { font-size: 1.4rem; font-weight: 700; }
.kpi-sub { color: var(--muted); font-size: .85rem; }
.kpi-warn { border-color: #f5d08a; background: #fff7e6; }
.is-plus { color: var(--plus); }
.is-minus { color: var(--minus); }

.links-row { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.links-row a { min-height: 44px; display: inline-flex; align-items: center; }

.pager {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 8px;
  margin-bottom: var(--gap);
}
.pager h1, .pager h2 { margin: 0; text-align: center; }
.pager .btn { padding: 0; font-size: 1.4rem; }

.cal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; }
.cal-row, .cal-body { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head span { text-align: center; color: var(--muted); font-size: .8rem; font-weight: 600; padding: 4px 0; }
.cal-cell {
  position: relative;
  min-height: 58px;
  border-radius: 8px;
  padding: 4px;
  text-decoration: none;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 2px solid transparent;
}
.cal-cell.is-empty { background: transparent; }
.cal-cell.is-off { background: transparent; color: var(--muted); }
.cal-cell.is-today { border-color: var(--text); }
.cal-cell.type-office { background: var(--office-bg); }
.cal-cell.type-home { background: var(--home-bg); }
.cal-cell.type-sick { background: var(--sick-bg); }
.cal-cell.type-vacation { background: var(--vacation-bg); }
.cal-cell.is-holiday { background: var(--holiday-bg); }
.cal-cell.is-open { border-style: dashed; border-color: var(--open); }
.cal-cell.is-short::after, .cal-cell.is-doctor::after {
  position: absolute;
  top: 3px;
  right: 5px;
  font-size: .75rem;
  font-weight: 700;
}
.cal-cell.is-short::after { content: "!"; color: var(--minus); }
.cal-cell.is-doctor::after { content: "A"; color: var(--holiday); }
.cal-day { font-weight: 700; font-size: .95rem; }
.cal-sub { font-size: .7rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.legend { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .85rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.dot { width: 14px; height: 14px; border-radius: 4px; display: inline-block; border: 1px solid var(--border); }
.dot.type-office { background: var(--office-bg); }
.dot.type-home { background: var(--home-bg); }
.dot.type-sick { background: var(--sick-bg); }
.dot.type-vacation { background: var(--vacation-bg); }
.dot.is-holiday { background: var(--holiday-bg); }
.dot.is-open { border: 2px dashed var(--open); }
.mark-short { color: var(--minus); font-weight: 700; }
.mark-doctor { color: var(--holiday); font-weight: 700; }

.tabs { display: flex; gap: 4px; background: var(--border); padding: 4px; border-radius: var(--radius); margin-bottom: var(--gap); }
.tabs a { flex: 1; text-align: center; padding: 10px 6px; border-radius: 9px; text-decoration: none; color: var(--text); font-weight: 600; min-height: 44px; }
.tabs a.is-current { background: var(--surface); color: var(--primary); }

.chart-box, .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: var(--gap) 0;
}
.chart { width: 100%; height: auto; display: block; }
.chart-axis { stroke: var(--muted); stroke-width: 1; }
.chart-label { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.bar-plus { fill: #7cc59a; }
.bar-minus { fill: #ec9a9a; }
.chart-line { fill: none; stroke: var(--primary); stroke-width: 2.5; stroke-linejoin: round; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; background: var(--surface); }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.table th:first-child, .table td:first-child { text-align: left; }
.table thead th { color: var(--muted); font-weight: 600; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0 0 12px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.inline-form { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; }
.inline-form label { flex: 1 1 220px; }

.device-list { list-style: none; padding: 0; margin: 0; }
.device-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.device-list li:last-child { border-bottom: 0; }

.backup-import { margin-top: 16px; }
.danger-zone { margin: var(--gap) 0; }
.logout { margin-top: 24px; }

.auth-box {
  max-width: 420px;
  margin: 10vh auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(92vw, 520px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #1c2430;
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .2);
  z-index: 20;
}
.toast[hidden] { display: none; }
.toast-undo {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, .5);
  color: #fff;
  border-radius: 8px;
  min-height: 40px;
  padding: 6px 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.day-title .muted { font-size: 1rem; display: block; }

code { background: var(--bg); padding: 1px 4px; border-radius: 4px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
