:root {
  --bg: #f4efe6;
  --paper: #fffdf8;
  --ink: #1c241c;
  --muted: #5c675c;
  --line: #d7d0c4;
  --accent: #1f5c45;
  --accent-ink: #f4efe6;
  --danger: #8c2f2f;
  --ok: #1f5c45;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 "Segoe UI", system-ui, sans-serif;
}

a { color: var(--accent); }

.wrap { max-width: 960px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

.top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 0.75rem;
  margin-bottom: 1.25rem;
}

.brand { font-weight: 700; letter-spacing: 0.02em; text-decoration: none; color: var(--ink); }
.who {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.who-name {
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-menu { position: relative; }
.user-menu-btn {
  list-style: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}
.user-menu-btn::-webkit-details-marker { display: none; }
.user-menu-btn::marker { content: ""; }
.user-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  z-index: 20;
  min-width: 12.5rem;
  padding: 0.35rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(28, 36, 28, 0.12), 0 1px 2px rgba(28, 36, 28, 0.08);
}
.user-menu-panel a,
.user-menu-panel button {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0.5rem 0.7rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.user-menu-panel a:hover,
.user-menu-panel button:hover { background: #eadfcb; }
.user-menu-panel a[aria-current="page"] { color: var(--accent); }

nav { display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; margin-bottom: 1.25rem; }
nav a { text-decoration: none; font-weight: 600; }
nav a[aria-current="page"] { border-bottom: 2px solid var(--accent); }

.flash {
  padding: 0.7rem 0.85rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  background: #e4efe8;
  color: var(--ok);
}
.flash.error { background: #f6e4e4; color: var(--danger); }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem 1.1rem;
}

h1 { font-size: 1.35rem; margin: 0 0 0.75rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.6rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.55rem 0.4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr.row-past td { background: #e8e4dc; color: var(--muted); }
tr.row-out td { background: #f3d0d0; }
tr.row-extra td { background: #e8f0e6; }
tr.row-kind-out td { background: #f4ece4; }
tr.row-kind-extra td { background: #eaeef3; }

.muted { color: var(--muted); }
.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: #eadfcb;
}
.badge.out { background: #f6e4e4; color: var(--danger); }
.badge.done { background: #e4efe8; color: var(--ok); }
.badge.kind-out { background: #e8ddd0; color: var(--ink); }
.badge.kind-extra { background: #d5dde6; color: var(--ink); }

label { display: block; font-weight: 600; margin: 0.7rem 0 0.25rem; }
input[type="text"], input[type="password"], input[type="time"], input[type="date"], select, textarea {
  width: 100%;
  max-width: 28rem;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font: inherit;
}
textarea { min-height: 4.5rem; }
#block-form:has(#is_holiday:checked) .date-from-range,
#block-form:has(#is_holiday:checked) #date-to-wrap { display: none; }
#block-form:not(:has(#is_holiday:checked)) .date-from-day { display: none; }

.checks { display: grid; gap: 0.35rem; margin: 0.4rem 0 0.8rem; }
.checks label { font-weight: 500; margin: 0; }

.row-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.btn, button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0.4rem 0.75rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn.ghost, button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn.danger, button.danger { background: var(--danger); color: #fff; }

.login { max-width: 22rem; margin: 12vh auto; }
.actions { margin-top: 1rem; display: flex; gap: 0.6rem; align-items: center; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.8rem; }
.toolbar h1 { margin: 0; }
.card:has(> .slot-summary) { margin-bottom: 0.8rem; }
.slot-summary th:nth-child(n+2),
.slot-summary td:nth-child(n+2) { text-align: right; }
.slot-summary tfoot td { font-weight: 700; border-bottom: 0; }
.month-acc-body .slot-summary { margin-bottom: 0.85rem; }
.month-export {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 0.75rem;
}
.switch {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.switch-knob {
  width: 2.15rem;
  height: 1.2rem;
  border-radius: 999px;
  background: #cfc8bc;
  position: relative;
  flex: 0 0 auto;
}
.switch-knob::after {
  content: "";
  position: absolute;
  top: 0.15rem;
  left: 0.15rem;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  background: #fff;
}
.switch.on { color: var(--accent); }
.switch.on .switch-knob { background: var(--accent); }
.switch.on .switch-knob::after { left: auto; right: 0.15rem; }

.plan-action {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.4rem;
}
.plan-action button,
.plan-action .btn {
  min-width: 13.5rem;
  text-align: center;
}
#plan-next { scroll-margin-top: 0.75rem; }

.month-acc { padding: 0; }
.month-acc + .month-acc { margin-top: 0.75rem; }
.month-acc > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1.1rem;
  cursor: pointer;
  font-weight: 700;
}
.month-acc > summary::-webkit-details-marker { display: none; }
.month-acc > summary::marker { content: ""; }
.month-acc > summary::after {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}
.month-acc[open] > summary::after {
  transform: rotate(-135deg);
}
.month-acc-body { padding: 0 1.1rem 0.35rem; }
.month-acc-body tr:last-child td { border-bottom: 0; }

.confirm-dialog {
  width: min(22rem, calc(100% - 2rem));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.1rem 1.2rem;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(28, 36, 28, 0.12), 0 1px 2px rgba(28, 36, 28, 0.08);
}
.confirm-dialog::backdrop {
  background: rgba(28, 36, 28, 0.45);
}
.confirm-dialog p {
  margin: 0 0 1rem;
  font-weight: 600;
}
.confirm-dialog .actions {
  margin-top: 0;
  justify-content: flex-end;
}

@media (max-width: 40rem) {
  .toolbar { flex-wrap: wrap; align-items: flex-start; }

  .card:has(.plan) {
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
  }

  .plan, .plan tbody { display: block; width: 100%; }
  .plan thead { display: none; }
  .plan tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "date time"
      "name status"
      "action action";
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(28, 36, 28, 0.12), 0 1px 2px rgba(28, 36, 28, 0.08);
    margin: 0 0 0.75rem;
    overflow: hidden;
    padding: 0;
  }
  .plan tbody tr:last-child { margin-bottom: 0; }
  .plan tbody tr.row-past { background: #e8e4dc; }
  .plan tbody tr.row-out { background: #f3d0d0; }
  .plan tbody tr.row-extra { background: #e8f0e6; }
  .plan td {
    border: 0;
    padding: 10px;
    min-width: 0;
    overflow-wrap: anywhere;
    background: transparent;
  }
  .plan-date {
    grid-area: date;
    font-weight: 600;
    border-bottom: 1px solid var(--line);
  }
  .plan-time {
    grid-area: time;
    color: var(--muted);
    text-align: right;
    border-bottom: 1px solid var(--line);
  }
  .plan-name { grid-area: name; }
  .plan-status { grid-area: status; text-align: right; }
  .plan-action {
    grid-area: action;
    border-top: 1px solid var(--line);
  }
  .plan-action:not(:has(form)):not(:has(.btn)) { display: none; }
  .plan-action form { margin: 0; }
  .plan-action button,
  .plan-action .btn {
    width: 100%;
    min-width: 0;
    min-height: 2.5rem;
  }
}
