:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --border: #e6e9ef;
  --text: #1f2733;
  --muted: #6b7484;
  --accent: #3b82f6;
  --accent-dark: #2563eb;
  --public: #2563eb;
  --private: #8b5cf6;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .12);
  --radius: 10px;
}

* { box-sizing: border-box; }

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

/* ---------- header ---------- */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: .85rem 1.25rem;
  background: linear-gradient(135deg, #1e293b, #334155);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow);
}
header h1 { font-size: 1.15rem; margin: 0; font-weight: 650; letter-spacing: .2px; }
#identity { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
#identity span { font-size: .9rem; opacity: .9; }
#identity form { display: flex; gap: .4rem; }
#identity input {
  padding: .45rem .6rem;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: .9rem;
  min-width: 180px;
}

/* ---------- buttons ---------- */
button {
  cursor: pointer;
  padding: .5rem .85rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  font-size: .88rem;
  font-weight: 500;
  transition: background .12s, border-color .12s, transform .05s;
}
button:hover { background: #f0f3f8; }
button:active { transform: translateY(1px); }

/* primary actions: register, new event, save */
#identity button#newEvent,
#regForm button,
#eventForm button[type="submit"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
#identity button#newEvent:hover,
#regForm button:hover,
#eventForm button[type="submit"]:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

#identity button#logout { background: transparent; border-color: rgba(255,255,255,.3); color: #fff; }
#identity button#logout:hover { background: rgba(255,255,255,.12); }

/* ---------- week nav ---------- */
nav#weeknav {
  display: flex;
  gap: .5rem;
  align-items: center;
  padding: .75rem 1.25rem;
}
#weekLabel { font-weight: 650; margin-left: .35rem; color: var(--text); }
#thisWeek { font-weight: 600; }

main { padding: 0 1.25rem 2.5rem; }

/* ---------- calendar grid ---------- */
#calendar {
  display: grid;
  grid-template-columns: 52px repeat(7, minmax(90px, 1fr));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.day-head {
  text-align: center;
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
  padding: .55rem .2rem;
  background: #fafbfd;
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.day-head.corner { border-left: none; background: #fafbfd; }
.day-head.today { color: var(--accent-dark); background: #eef4ff; }

.time-col { position: relative; background: #fafbfd; }
.day-col { position: relative; border-left: 1px solid var(--border); }
.day-col.today { background: #f7faff; }

.hour-cell {
  height: 44px;
  border-top: 1px solid #f1f3f7;
  font-size: .68rem;
  color: var(--muted);
}
.time-col .hour-cell { padding: 2px 4px 0 0; text-align: right; }

/* "+" affordance on hover of an empty hour */
.day-col .hour-cell { position: relative; }
.day-col .hour-cell::after {
  content: "+";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(59, 130, 246, .06);
  opacity: 0;
  transition: opacity .1s;
  pointer-events: none;
}
.day-col .hour-cell:hover::after { opacity: 1; }

/* ---------- events ---------- */
.event {
  position: absolute;
  left: 3px;
  right: 3px;
  border-radius: 7px;
  padding: 3px 6px;
  font-size: .72rem;
  line-height: 1.2;
  overflow: hidden;
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 2;
  transition: transform .06s, box-shadow .12s;
}
.event:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); z-index: 3; }
.event.public { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.event.private { background: linear-gradient(135deg, #a78bfa, #8b5cf6); }
.event strong { font-weight: 600; }
.event .badge { font-size: .62rem; opacity: .9; margin-top: 1px; }

/* ---------- upcoming list ---------- */
#upcoming { margin-top: 1.75rem; }
#upcoming h2 { font-size: 1rem; margin: 0 0 .6rem; color: var(--text); }
#upcomingList { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .5rem; }
#upcomingList li {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .4rem;
  padding: .7rem .9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: .9rem;
}
#upcomingList li strong { font-weight: 600; }
.tag {
  font-size: .68rem;
  font-weight: 600;
  padding: .12rem .5rem;
  border-radius: 999px;
  color: #fff;
  text-transform: capitalize;
}
.tag.public { background: var(--public); }
.tag.private { background: var(--private); }
#upcomingList button { margin-left: auto; font-size: .78rem; padding: .35rem .65rem; }
#upcomingList button + button { margin-left: .4rem; }

/* ---------- modals ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .5);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}
.modal-overlay.hidden { display: none; }
.modal-card {
  background: var(--surface);
  padding: 1.5rem;
  border-radius: 14px;
  width: min(440px, 100%);
  display: flex;
  flex-direction: column;
  gap: .75rem;
  box-shadow: var(--shadow-lg);
  animation: pop .14s ease-out;
}
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-card h2 { margin: 0 0 .25rem; font-size: 1.15rem; }
.modal-card .hint { margin: 0; font-size: .85rem; color: var(--muted); }
.modal-card label { display: flex; flex-direction: column; font-size: .82rem; font-weight: 500; gap: .25rem; color: var(--muted); }
.modal-card input,
.modal-card textarea,
.modal-card select {
  padding: .55rem .65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .92rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
}
.modal-card input:focus,
.modal-card textarea:focus,
.modal-card select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.modal-card textarea { resize: vertical; min-height: 64px; }
.modal-card .row { display: flex; gap: .6rem; }
.modal-card .row label { flex: 1; }
.modal-card fieldset { border: 1px solid var(--border); border-radius: 8px; padding: .6rem .75rem; margin: 0; }
.modal-card fieldset legend { font-size: .8rem; font-weight: 600; color: var(--muted); padding: 0 .3rem; }
.modal-card fieldset label { flex-direction: row; align-items: center; gap: .4rem; font-weight: 400; color: var(--text); padding: .15rem 0; }
.modal-card .row:last-child { margin-top: .35rem; }
.modal-card .row:last-child button { flex: 1; }
.error { color: var(--danger); min-height: 1rem; margin: 0; font-size: .82rem; }
.hidden { display: none; }

@media (max-width: 640px) {
  #calendar { grid-template-columns: 44px repeat(7, minmax(64px, 1fr)); overflow-x: auto; }
  header { flex-direction: column; align-items: flex-start; }
}
