:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1d2433;
  --muted: #6b7486;
  --border: #e3e7ee;
  --accent: #0f6e78;
  --accent-soft: #e2f1f2;
  --holiday: #c0392b;
  --weekend: #f8f9fb;

  --c-gfa: #8e44ad;
  --c-cong: #2563eb;
  --c-rec: #7cc8f2;
  --c-des: #f28c28;
  --c-nog: #e05656;
  --c-fer: #22a35a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3, h4 { margin: 0; }

button { font: inherit; cursor: pointer; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 26px;
  font-weight: 700;
}
.brand h1 { font-size: 19px; }
.subtitle { margin: 2px 0 0; font-size: 13px; color: var(--muted); }

.user-box { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-name { font-weight: 600; font-size: 14px; margin-right: 4px; }
.admin-badge {
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- Layout ---------- */
.layout {
  max-width: 1100px;
  margin: 20px auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
}

/* ---------- Calendar toolbar ---------- */
.cal-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
}
.month-nav { display: flex; align-items: center; gap: 8px; }
.month-nav h2 { font-size: 20px; min-width: 170px; text-align: center; text-transform: capitalize; }

.icon-btn {
  width: 34px; height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 18px;
  line-height: 1;
}
.icon-btn:hover { background: var(--bg); }

.ghost-btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 6px 12px;
}
.ghost-btn:hover { background: var(--bg); }
.ghost-btn.small { font-size: 12px; padding: 4px 10px; }

.loc-box { display: flex; align-items: center; gap: 10px; }
.loc-label { font-size: 13px; color: var(--muted); }
.loc-label.warn { color: var(--holiday); font-weight: 600; }
.segmented {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px;
}
.segmented button {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: 7px;
  color: var(--muted);
  font-weight: 500;
}
.segmented button.active {
  background: var(--accent);
  color: #fff;
}

.cal-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0 10px;
  font-size: 13px;
}
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.nog-counter {
  padding: 3px 10px;
  border-radius: 999px;
  background: #fdecec;
  color: #a33;
  font-weight: 600;
}

/* ---------- Grid ---------- */
.weekdays, .grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.weekdays span {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  padding-bottom: 4px;
}

.day {
  position: relative;
  min-height: 78px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 6px 7px 14px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: transform .08s, box-shadow .08s;
}
.day:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); transform: translateY(-1px); }
.day.empty { visibility: hidden; }
.day.weekend { background: var(--weekend); }
.day.today { outline: 2px solid var(--accent); outline-offset: -1px; }

.day .num { font-weight: 600; font-size: 14px; }
.day.holiday .num { color: var(--holiday); }
.day .hol-name {
  font-size: 10px;
  color: var(--holiday);
  line-height: 1.15;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.day .my-tag {
  margin-top: auto;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.15;
}

/* Days coloured with the viewer's own tag */
.day.tagged { border-color: transparent; color: #fff; }
.day.tagged .num, .day.tagged .hol-name { color: #fff; }
.day.t-gfa  { background: var(--c-gfa); }
.day.t-cong { background: var(--c-cong); }
.day.t-rec  { background: var(--c-rec); color: #0b3550; }
.day.t-rec .num, .day.t-rec .hol-name { color: #0b3550; }
.day.t-des  { background: var(--c-des); }
.day.t-nog  { background: var(--c-nog); }
.day.t-fer  { background: var(--c-fer); }

/* Dot: someone else tagged this day, viewer did not */
.day .dot {
  position: absolute;
  bottom: 5px;
  left: 50%;
  transform: translateX(-50%);
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text);
  opacity: .55;
}

/* ---------- Legend ---------- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 16px;
  font-size: 12.5px;
  color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: none; }
.sw-gfa  { background: var(--c-gfa); }
.sw-cong { background: var(--c-cong); }
.sw-rec  { background: var(--c-rec); }
.sw-des  { background: var(--c-des); }
.sw-nog  { background: var(--c-nog); }
.sw-fer  { background: var(--c-fer); }
.swatch.dot-swatch { border-radius: 50%; width: 7px; height: 7px; background: var(--text); opacity: .55; }

/* ---------- Recap ---------- */
.recap-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.recap-head h2 { font-size: 17px; }
.recap-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.admin-btn {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 6px 12px;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
}
.admin-btn.wide { width: 100%; padding: 10px; margin-top: 8px; }
.admin-btn:disabled { opacity: .6; cursor: wait; }
.admin-btn.small { font-size: 12px; padding: 5px 11px; }
.admin-btn:hover { filter: brightness(1.1); }
.admin-btn[hidden] { display: none; }
.table-wrap { overflow-x: auto; }
.recap {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.recap th, .recap td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  white-space: nowrap;
}
.recap th { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.recap th .swatch { margin-right: 4px; vertical-align: -1px; }
.recap td:first-child, .recap th:first-child { text-align: left; }
.recap tr.me td { background: var(--accent-soft); font-weight: 600; }
.recap td.zero { color: #c4c9d3; }
.recap td.full { color: #a33; font-weight: 700; }
.loc-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
}

/* ---------- Dialog ---------- */
dialog {
  border: 0;
  border-radius: 14px;
  padding: 0;
  width: min(460px, calc(100vw - 32px));
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(20, 28, 40, .45); }
.dialog-inner { padding: 18px; }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.dialog-head h3 { font-size: 18px; text-transform: capitalize; }
.holiday-pill {
  margin: 6px 0 0;
  display: inline-block;
  font-size: 12px;
  padding: 2px 9px;
  border-radius: 999px;
  background: #fbeaea;
  color: var(--holiday);
}
.dialog-inner h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 16px 0 8px; }

.tag-options { display: flex; flex-direction: column; gap: 6px; }
.tag-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  text-align: left;
}
.tag-opt:hover:not(:disabled) { background: var(--bg); }
.tag-opt.selected { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.tag-opt.selected::after { content: "✓"; margin-left: auto; color: var(--accent); }
.tag-opt:disabled { opacity: .4; cursor: not-allowed; }
.tag-opt .note { margin-left: auto; font-size: 11px; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; min-height: 1em; }

.tag-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.tag-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--bg);
}
.tag-list li .author { font-weight: 600; }
.tag-list li .where { margin-left: auto; font-size: 11px; color: var(--muted); }
.tag-list .empty-msg { background: none; color: var(--muted); font-style: italic; }

/* ---------- Admin ---------- */
body:not(.is-admin) .admin-only,
body.is-admin .member-only { display: none !important; }
.admin-note { color: var(--muted); font-style: italic; }

.add-user { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 10px; }
.add-user input[name="name"] {
  flex: 1 1 220px;
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.users-table td:last-child { text-align: right; }
.users-table .ghost-btn + .ghost-btn { margin-left: 6px; }
.danger { color: var(--holiday); }

.creds { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0 0 6px; }
.creds dt { color: var(--muted); font-size: 13px; }
.creds dd { margin: 0; font-family: ui-monospace, monospace; font-size: 15px; user-select: all; }

/* ---------- Forms / login ---------- */
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.field input {
  font: inherit;
  font-size: 15px;
  color: var(--text);
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.form-error { color: var(--holiday); font-size: 13px; margin: 0 0 8px; }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); padding: 26px; }
.login-card .brand { margin-bottom: 22px; }

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .day { min-height: 58px; padding: 4px 4px 12px; }
  .day .hol-name, .day .my-tag { display: none; }
  .weekdays, .grid { gap: 3px; }
  .month-nav h2 { min-width: 130px; font-size: 17px; }
}
