:root { --bg: #f4f1ec; --card: #fff; --text: #1f1b16; --muted: #6b645c; --line: #e3ddd4;
  --accent: #b45309; --on-accent: #fff;
  --red: #c62828; --red-bg: #fbdcdc; --yellow: #9a5b00; --yellow-bg: #fcebbd; --green: #1b7f3b; --green-bg: #d5eedd;
  --grey: #8a8580; --grey-bg: #e6e3df; }
@media (prefers-color-scheme: dark) { :root { --bg: #16130f; --card: #221e19; --text: #f1ece4; --muted: #a39a8f; --line: #3a332b;
  --accent: #f59e0b; --on-accent: #1f1b16;
  --red: #f87171; --red-bg: #4a2222; --yellow: #fbbf24; --yellow-bg: #463712; --green: #4ade80; --green-bg: #183a25;
  --grey: #7a736b; --grey-bg: #2a2621; } }
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); line-height: 1.4; }
a { color: inherit; }
/* header, date row and add-day form: one block that stays on screen on a laptop; on a phone only the date row does */
.top { position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 1px solid var(--line); }
.bar, .tabs, .pager, main { max-width: 1100px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.bar { display: flex; align-items: center; gap: 12px; padding-top: 10px; padding-bottom: 10px; }
.brand { font-weight: 700; font-size: 1.1rem; text-decoration: none; }
.who { margin-left: auto; color: var(--muted); font-size: .9rem; }
.ghost { font: inherit; font-size: .9rem; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: none; color: var(--text); cursor: pointer; }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tabs a { padding: 8px 12px 10px; color: var(--muted); text-decoration: none; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--text); border-color: var(--accent); font-weight: 600; }
main { padding-top: 16px; padding-bottom: 32px; }
h1 { font-size: 1.3rem; margin: 0 0 12px; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 0 8px; }
/* date buttons: a second row of the header, same box as .bar so the edges line up with brand and Esci */
.pager { gap: 6px; padding-top: 2px; padding-bottom: 8px; }
.pager a, .addbtn { min-width: 40px; height: 36px; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px; background: var(--bg); border: 1px solid var(--line); text-decoration: none; font-weight: 600; cursor: pointer; }
.pager .label { margin-left: auto; color: var(--muted); font-size: .9rem; white-space: nowrap; }
.addbtn { min-width: 110px; background: var(--accent); border-color: var(--accent); color: var(--on-accent); white-space: nowrap; }
.toggle { position: absolute; opacity: 0; pointer-events: none; }
.toggle:focus-visible ~ .pager .addbtn { outline: 2px solid var(--text); outline-offset: 2px; }
.addbtn .off, .toggle:checked ~ .pager .addbtn .on { display: none; }
.toggle:checked ~ .pager .addbtn .off { display: inline; }
/* add-day form: a row of the header under the buttons, scrolls inside itself when the screen is short */
.addpanel { display: none; border-top: 1px solid var(--line); max-height: calc(100vh - 150px); overflow-y: auto; }
.toggle:checked ~ .addpanel { display: block; }
.addpanel .bar { display: block; padding-top: 12px; padding-bottom: 14px; }
.addpanel .editday { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: end; }
.pager .label .short { display: none; }
@media (max-width: 480px) { .pager .label .long { display: none; } .pager .label .short { display: inline; } }
.legend { color: var(--muted); font-size: .85rem; margin: 10px 0 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.day { background: var(--s-bg); border: 2px solid var(--s); border-left-width: 8px; border-radius: 14px;
  padding: 12px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 1px 2px rgb(0 0 0 / .05); scroll-margin-top: 170px; }
.red { --s: var(--red); --s-bg: var(--red-bg); }
.yellow { --s: var(--yellow); --s-bg: var(--yellow-bg); }
.green { --s: var(--green); --s-bg: var(--green-bg); }
/* extraordinary closing: card kept so the week keeps its shape, greyed out */
.closed { --s: var(--grey); --s-bg: var(--grey-bg); color: var(--muted); }
.shut { margin: 0; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.day.past { opacity: .55; }
.day.today { outline: 2px solid var(--accent); outline-offset: 2px; }
.head { display: flex; align-items: baseline; gap: 6px; }
.date { font-size: 1.15rem; font-weight: 700; white-space: nowrap; }
.month { color: var(--muted); }
.note { margin: 0; font-size: .85rem; color: var(--muted); }
.pill { margin-left: auto; font-size: .8rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: var(--s); color: var(--card); }
.slot { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.slot .label { width: 76px; flex: none; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.slot .label small { display: block; font-size: .85rem; letter-spacing: 0; text-transform: none; color: var(--text); }
/* event slot sits above opening and closing, set apart by a line */
.slot.event { padding-bottom: 8px; border-bottom: 1px dashed var(--s); }
.names { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-weight: 600; font-size: .9rem; }
.chip form { display: inline; }
.chip .x { border: 0; background: none; color: var(--muted); font-size: 1.1rem; line-height: 1; width: 26px; height: 26px; margin: -4px -8px -4px 0; border-radius: 999px; cursor: pointer; }
.none { color: var(--s); font-weight: 600; font-size: .9rem; }
.take { flex: none; font: inherit; font-weight: 600; font-size: .9rem; min-height: 40px; padding: 0 14px; border-radius: 10px; border: 0; background: var(--accent); color: var(--on-accent); cursor: pointer; }
.green .take { background: var(--card); color: var(--accent); border: 1px solid var(--accent); }
.empty { color: var(--muted); font-size: .9rem; margin: 0; }
.btn { width: 100%; min-height: 44px; font: inherit; font-weight: 600; border: 0; border-radius: 10px; background: var(--accent); color: var(--on-accent); cursor: pointer; }
.more summary { cursor: pointer; color: var(--muted); font-size: .85rem; list-style: none; padding: 2px 0; }
.more summary::-webkit-details-marker { display: none; }
.more[open] summary { margin-bottom: 6px; }
.add { display: flex; gap: 6px; }
.title { font-weight: 700; color: var(--text); }
.editday { display: grid; gap: 6px; }
.editday label { display: grid; gap: 2px; font-size: .8rem; color: var(--muted); }
.editday input, .editday select { font: inherit; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); min-width: 0; }
.add input { flex: 1; min-width: 0; font: inherit; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); }
.box { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 10px 10px; border-bottom: 1px solid var(--line); text-align: center; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
td:first-child, th:first-child { text-align: left; position: sticky; left: 0; background: var(--card); }
td.zero { color: var(--muted); }
.log { list-style: none; margin: 0; padding: 0; }
.log li { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.log li:last-child { border-bottom: 0; }
.log small { display: block; color: var(--muted); }
.box .empty { padding: 14px; }
.login { max-width: 360px; margin: 10vh auto 0; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.login input { font: inherit; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.error { color: var(--red); margin: 0; }
.alert { background: var(--red-bg); border: 2px solid var(--red); border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; font-weight: 600; }
.alert ul { margin: 6px 0 0; padding-left: 20px; font-weight: 400; }
.alert code { overflow-wrap: anywhere; }
/* laptop and wider: whole week (6 open days) on one row, compact cards */
@media (min-width: 1200px) {
  .bar, .tabs, .pager, main { max-width: 1600px; }
  /* a week on one row: equal cards, closed days (admins) as thin strips between them */
  .grid { display: flex; gap: 8px; }
  .grid > .day { flex: 1 1 0; min-width: 0; }
  .grid > .strip { flex: 0 0 64px; }
  /* extraordinary opening on the closing day: seven cards, still one row */
  .grid.many .month { display: none; }
  .day { padding: 10px; gap: 8px; }
  .slot { flex-wrap: wrap; gap: 4px 6px; min-height: 0; }
  .slot .label { width: 100%; }
  .slot .label small { display: inline; margin-left: 6px; }
  /* names keep their width, the button wraps below when they do not fit */
  .names { flex: 1 1 auto; }
  .slot > form { margin-left: auto; }
  .take { min-height: 30px; padding: 0 10px; font-size: .8rem; }
  .add { flex-wrap: wrap; }
  .add input { flex-basis: 100%; }
}
.editday input.bad { border-color: var(--red); }
.editday input:disabled { opacity: .5; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.take.danger, .green .take.danger { background: var(--card); color: var(--red); border: 1px solid var(--red); }
/* closed day, admins only: thin strip, a row on phones and a narrow column on a laptop */
.strip { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; padding: 6px 12px; min-height: 40px;
  border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); font-size: .85rem; }
.strip .date { font-weight: 700; white-space: nowrap; }
.strip .shut { margin: 0; }
.strip .open { margin-left: auto; padding: 4px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); text-decoration: none; font-weight: 600; }
.strip.past { opacity: .55; }
@media (min-width: 1200px) {
  .strip { flex-direction: column; justify-content: center; gap: 4px; padding: 6px 4px; text-align: center; }
  .strip .open { margin-left: 0; padding: 4px 8px; }
}
/* helpers for the phone layout below; on a laptop they change nothing */
.slots, .admin { display: contents; }
.menubtn, .menu-toggle, .legend.mob { display: none; }

/* phone: a day is a compact row, date and count on the left, opening and closing side by side, admin tools behind a "⋯" */
@media (max-width: 600px) {
  .top { display: contents; }
  .sticky { position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 1px solid var(--line); }
  .addpanel { max-height: calc(100vh - 70px); }
  main { padding-top: 8px; padding-bottom: 20px; }
  h2 { margin: 14px 0 6px; }
  .legend.desk { display: none; }
  .legend.mob { display: block; margin: 4px 0 0; color: var(--muted); font-size: .85rem; }
  .legend.mob summary { cursor: pointer; padding: 4px 0; }
  .grid { gap: 6px; }
  .date { font-size: 1rem; }
  .day { display: grid; grid-template-columns: 62px 1fr; column-gap: 8px; row-gap: 4px; padding: 8px 10px; scroll-margin-top: 64px; }
  .day > .head { grid-column: 1; grid-row: 1; flex-direction: column; align-items: flex-start; gap: 4px; }
  .head .month { display: none; }
  .head .pill { margin-left: 0; }
  .day > .slots { grid-column: 2; grid-row: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; align-content: start; min-width: 0; }
  .slot.event { grid-column: 1 / -1; padding-bottom: 4px; }
  .slot { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "label label" "names take";
    gap: 2px 4px; align-items: center; min-height: 0; }
  .slot .label { grid-area: label; width: auto; white-space: nowrap; }
  .slot .label small { display: inline; margin-left: 4px; }
  .slot .names { grid-area: names; }
  .slot > form { grid-area: take; }
  .chip { padding: 1px 6px 1px 8px; font-size: .8rem; max-width: 100%; }
  .chip .x { width: 20px; margin-right: -4px; }
  /* "Prendo" becomes a "+" (the button keeps its aria-label) */
  .slot > form .take { font-size: 0; width: 32px; min-height: 36px; padding: 0; }
  .slot > form .take::after { content: "+"; font-size: 1.5rem; line-height: 1; }
  .day > .note, .day > .title { grid-column: 1 / -1; }
  .day > .shut { grid-column: 2; align-self: center; }
  .menubtn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 28px; border-radius: 8px;
    border: 1px solid var(--line); background: var(--card); color: var(--text); font-weight: 700; cursor: pointer; }
  .day > .admin { grid-column: 1 / -1; display: none; }
  .day > .menu-toggle:checked ~ .admin { display: flex; flex-direction: column; gap: 8px; }
  .strip { min-height: 36px; padding: 4px 10px; }
  /* past days, for staff nothing to do there: date and names only */
  .day.past:not(.adm) .pill, .day.past:not(.adm) .slot .label { display: none; }
  .day.past:not(.adm) .slots { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
  .day.past:not(.adm) .slot { display: contents; }
  .day.past:not(.adm) .slot ~ .slot .none { display: none; }
}
