:root {
  --bg: #f4f1ea;
  --surface: #fffdf9;
  --line: #d8ddd7;
  --text: #1f2430;
  --muted: #66707c;
  --accent: #1f766e;
  --accent-strong: #165851;
  --accent-soft: #d9ece9;
  --danger: #c84d4d;
  --danger-soft: #fde8e8;
  --warn: #b07a17;
  --warn-soft: #fff0d8;
  --shadow: 0 18px 40px rgba(24, 34, 42, 0.08);
  --radius: 24px;
  --max-width: 1180px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(31, 118, 110, 0.08), transparent 24%),
    linear-gradient(180deg, #faf7f0 0%, #f2eee5 100%);
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.shell { min-height: 100vh; padding: 24px 16px 100px; }
.topbar, .page, .print-sheet { width: min(100%, var(--max-width)); margin: 0 auto; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  padding: 18px 20px;
  background: rgba(255, 253, 249, 0.78);
  border: 1px solid rgba(216, 221, 215, 0.9);
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), #48a497);
  color: white;
  font-size: 26px;
}

.eyebrow { margin: 0; color: var(--muted); }
.brand h1 { margin: 0; font-size: 1.5rem; }
.header-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.page, .stats-grid, .two-col, .three-col, .four-col, .field-grid, .history-grid {
  display: grid;
  gap: 16px;
}

.hero, .card, .panel, .print-sheet {
  background: var(--surface);
  border: 1px solid rgba(216, 221, 215, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero {
  padding: 24px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 20px;
}

.hero h2 {
  margin: 0 0 8px;
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 0.95;
}

.hero p { margin: 0; color: var(--muted); font-size: 1.05rem; }
.hero-actions, .switch-row, .inline-actions, .chip-row, .legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-start;
}

.button, .secondary-button, .danger-button, .ghost-button {
  min-height: 48px;
  padding: 0 18px;
  border-radius: 16px;
  border: 1px solid transparent;
  transition: 0.2s ease;
}

.button { background: var(--accent); color: white; }
.button:hover, .button:focus-visible { background: var(--accent-strong); }
.secondary-button {
  background: white;
  border-color: var(--line);
  color: var(--text);
}
.secondary-button:hover, .secondary-button:focus-visible,
.ghost-button:hover, .ghost-button:focus-visible {
  border-color: var(--accent);
  color: var(--accent-strong);
}
.ghost-button { background: transparent; border-color: var(--line); color: var(--muted); }
.danger-button { background: var(--danger); color: white; }
.danger-button:hover, .danger-button:focus-visible { background: #a63d3d; }

.stats-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.two-col { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.three-col { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.four-col { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.stat-card, .mini-card {
  padding: 20px;
  border-radius: 22px;
  background: linear-gradient(180deg, #fffefb 0%, #f9f6ef 100%);
  border: 1px solid rgba(216, 221, 215, 0.9);
}

.stat-label, .mini-label, .field-label {
  color: var(--muted);
  font-size: 0.95rem;
}

.stat-value {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 700;
  margin: 8px 0 6px;
}

.stat-detail { color: var(--muted); margin: 0; }
.card, .panel { padding: 24px; }
.card h3, .panel h3, .panel h4 { margin-top: 0; }

.section-heading, .month-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.month-controls h3, .month-controls h4 { margin: 0; min-width: 180px; }

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

.week-strip {
  display: grid;
  gap: 14px;
}

.week-strip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

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

.week-card {
  min-height: 112px;
  padding: 14px 12px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fffefb 0%, #f7f2ea 100%);
  display: grid;
  gap: 18px;
  text-align: left;
  color: var(--text);
}

.week-card.selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.week-card.is-outside {
  opacity: 0.58;
}

.week-card-top {
  display: grid;
  gap: 6px;
}

.week-card-weekday {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.week-card-date {
  font-size: 1.45rem;
  font-weight: 700;
}

.week-card-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
}

.week-card-status span:last-child {
  white-space: nowrap;
}

.calendar-cell, .calendar-head {
  min-height: 56px;
  padding: 8px;
  border-radius: 16px;
}

.calendar-head {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 600;
  min-height: auto;
}

.calendar-cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid var(--line);
  background: #fffefb;
}

.calendar-cell button { all: unset; cursor: pointer; }
.calendar-cell.selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.calendar-cell.empty {
  background: transparent;
  border-style: dashed;
  opacity: 0.4;
}

.calendar-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.dot { width: 10px; height: 10px; border-radius: 999px; }
.dot-ok { background: #a8d8b7; }
.dot-extra { background: #8ecfd1; }
.dot-incomplete { background: #f2dca5; }
.dot-absence { background: #f4b6b6; }
.dot-leave { background: #c8d8f8; }
.dot-holiday { background: #d8dde4; }
.dot-off { background: #ece8dc; }

.field-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.field, .switch-field { display: grid; gap: 8px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 13px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fffefb;
  color: var(--text);
}

.field textarea { min-height: 110px; resize: vertical; }

.switch, .chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fffefb;
}

.chip { color: var(--muted); background: white; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
}

table { width: 100%; border-collapse: collapse; min-width: 700px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); background: #faf7f0; }
tr:last-child td { border-bottom: none; }

.summary-list { display: grid; gap: 10px; }
.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
}

.summary-row:last-child { border-bottom: none; }
.summary-row strong:last-child, .text-accent { color: var(--accent); }
.text-danger { color: var(--danger); }

.status-banner {
  padding: 14px 16px;
  border-radius: 18px;
  font-weight: 600;
}

.status-ok { background: var(--accent-soft); color: var(--accent-strong); }
.status-warn { background: var(--warn-soft); color: var(--warn); }
.status-danger { background: var(--danger-soft); color: var(--danger); }

.muted { color: var(--muted); }
.small { font-size: 0.92rem; }

.history-item {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fffefb;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  padding: 16px;
  display: grid;
  place-items: center;
  background: rgba(17, 24, 39, 0.4);
  z-index: 30;
}

.dialog {
  width: min(100%, 520px);
  padding: 24px;
  border-radius: 26px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.dialog-title { margin-top: 0; }
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: min(calc(100% - 20px), 760px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px;
  background: rgba(255, 253, 249, 0.92);
  border: 1px solid rgba(216, 221, 215, 0.95);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  z-index: 20;
}

.nav-button {
  min-height: 52px;
  border: none;
  border-radius: 18px;
  background: transparent;
  color: var(--muted);
}

.daily-layout {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.9fr);
}

.daily-main {
  display: grid;
  gap: 16px;
}

.daily-side {
  display: grid;
  gap: 16px;
  align-content: start;
}

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

.schedule-pill {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, #fffefb 0%, #f6f2ea 100%);
}

.schedule-time {
  display: block;
  margin-top: 6px;
  font-size: 1.25rem;
  font-weight: 700;
}

.calendar-grid.compact .calendar-cell {
  min-height: 78px;
  padding: 10px;
}

.calendar-grid.compact .calendar-cell button {
  display: grid;
  gap: 6px;
}

.calendar-day {
  font-size: 1.2rem;
  font-weight: 700;
}

.calendar-status.short {
  font-size: 0.78rem;
}

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

.quick-actions .button,
.quick-actions .secondary-button,
.quick-actions .danger-button {
  flex: 1 1 180px;
}

.day-title {
  display: grid;
  gap: 4px;
}

.panel-subtitle {
  margin: 0;
  color: var(--muted);
}

.hint-box {
  padding: 14px 16px;
  border-radius: 18px;
  background: #f4f8f7;
  border: 1px solid var(--line);
}

.hint-box strong {
  display: block;
  margin-bottom: 6px;
}

.nav-button.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
}

.print-sheet { padding: 30px; }

.lock-screen {
  min-height: calc(100vh - 220px);
  display: grid;
  place-items: center;
}

.lock-card {
  width: min(100%, 440px);
  padding: 28px;
  border-radius: 30px;
  background: var(--surface);
  border: 1px solid rgba(216, 221, 215, 0.9);
  box-shadow: var(--shadow);
}

.lock-card h2 {
  margin: 0 0 8px;
  font-size: 2rem;
}

.lock-card p {
  margin: 0 0 18px;
  color: var(--muted);
}

.pin-input {
  width: 100%;
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #fffefb;
  font-size: 1.4rem;
  letter-spacing: 0.35em;
  text-align: center;
}

.pin-error {
  margin-top: 12px;
  color: var(--danger);
  font-weight: 600;
}

@media (max-width: 720px) {
  .shell { padding: 16px 12px 110px; }
  .topbar { padding: 16px; border-radius: 24px; }
  .hero, .card, .panel { padding: 18px; }
  .calendar-cell { min-height: 74px; }
  .history-item { grid-template-columns: 1fr; }
  .bottom-nav { gap: 6px; padding: 8px; }
  .nav-button { min-height: 48px; font-size: 0.9rem; }
  .daily-layout { grid-template-columns: 1fr; }
  .schedule-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calendar-grid.compact .calendar-cell { min-height: 88px; }
  .week-grid {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: minmax(132px, 1fr);
    overflow-x: auto;
    padding-bottom: 4px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }
  .week-card {
    min-height: 104px;
    padding: 14px;
    gap: 14px;
    scroll-snap-align: start;
  }
  .week-card-date { font-size: 1.25rem; }
  .week-card-status { font-size: 0.9rem; }
  .week-strip-head { align-items: stretch; }
  .week-strip-head .ghost-button { flex: 1 1 140px; }
}

/* Sync status indicator */
.sync-status {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid transparent;
  transition: 0.2s ease;
}
.sync-status:empty { display: none; }
.sync-syncing { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-soft); }
.sync-ok      { background: var(--accent-soft); color: var(--accent-strong); border-color: var(--accent-soft); }
.sync-warn    { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-soft); }

/* Monthly calendar */
.month-calendar { display: grid; gap: 8px; }

.month-cal-header {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.month-cal-weekday {
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  padding: 4px 0 6px;
  letter-spacing: 0.03em;
}

.month-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.month-cell {
  min-height: 62px;
  padding: 8px 4px 6px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fffefb 0%, #f7f2ea 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  color: var(--text);
  transition: border-color 0.15s;
}

.month-cell:hover { border-color: var(--accent); }

.month-cell.selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1.5px var(--accent);
}

.month-cell.is-weekend {
  background: linear-gradient(180deg, #faf7f0 0%, #f2ece0 100%);
}

.month-cell-empty {
  min-height: 62px;
  border-radius: 12px;
}

.month-cell-day {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
}

.month-cell-status {
  display: flex;
  align-items: center;
  gap: 3px;
  max-width: 100%;
}

.month-status-text {
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 420px) {
  .month-cell { min-height: 54px; padding: 6px 2px 4px; gap: 3px; border-radius: 10px; }
  .month-cell-day { font-size: 0.9rem; }
  .month-status-text { font-size: 0.6rem; }
  .month-cal-weekday { font-size: 0.7rem; }
}

.time-field-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.time-field-row input[type="time"] {
  flex: 1 1 auto;
  min-width: 0;
}
.now-button {
  flex: 0 0 auto;
  min-height: 48px;
  min-width: 64px;
  padding: 0 14px;
  border-radius: 16px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s ease;
}
.now-button:hover, .now-button:focus-visible {
  background: var(--accent);
  color: white;
  outline: none;
}
.now-button:active {
  transform: scale(0.97);
}

.saved-pill {
  display: inline-block;
  margin-top: 12px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.85rem;
  font-weight: 600;
}
.saved-pill--offline {
  background: #fde7a7;
  color: #8a6d00;
}

@media print {
  body { background: white; }
  .topbar, .bottom-nav, .hero-actions, .header-actions, .month-controls button, .inline-actions {
    display: none !important;
  }
  .shell { padding: 0; }
  .page, .print-sheet { width: 100%; max-width: none; }
  .card, .panel, .print-sheet { box-shadow: none; border-color: #ddd; }
}
