:root {
  --hour-height: 48px;          /* pixels per hour, drives all positioning */
  --gutter-width: 56px;
  --accent: #1a73e8;
  --grid-line: #e4e6eb;
  --text: #202124;
  --muted: #70757a;
  --bg: #fff;
  --event-bg: #1a73e8;
  --event-text: #fff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ---- Toolbar ---- */
#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--grid-line);
  flex: 0 0 auto;
}
#toolbar h1 {
  font-size: 1rem;
  font-weight: 500;
  margin: 0 4px;
  white-space: nowrap;
}
.spacer { flex: 1 1 auto; }

.btn {
  font: inherit;
  border: 1px solid var(--grid-line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}
.btn:hover { background: #f1f3f4; }
.btn.icon { padding: 6px 10px; font-size: 1.1rem; line-height: 1; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { border-color: #d93025; color: #d93025; }

/* ---- All-day row ---- */
#allday-row {
  display: flex;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--grid-line);
  min-height: 28px;
}
#allday-gutter { width: var(--gutter-width); flex: 0 0 auto; }
#allday-cells { display: flex; flex: 1 1 auto; }
.allday-cell { flex: 1 1 0; border-left: 1px solid var(--grid-line); padding: 2px; }
.allday-chip {
  background: var(--event-bg); color: var(--event-text);
  font-size: 0.72rem; border-radius: 4px; padding: 1px 5px;
  margin-bottom: 2px; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---- Scrolling grid ---- */
#grid-scroll { flex: 1 1 auto; overflow-y: auto; }
#grid { position: relative; display: flex; }

#time-gutter {
  width: var(--gutter-width);
  flex: 0 0 auto;
  position: relative;
}
.hour-label {
  position: absolute;
  right: 6px;
  font-size: 0.68rem;
  color: var(--muted);
  transform: translateY(-50%);
}

#day-columns { display: flex; flex: 1 1 auto; position: relative; }
.day-col {
  flex: 1 1 0;
  position: relative;
  border-left: 1px solid var(--grid-line);
}
.hour-line {
  position: absolute;
  left: 0; right: 0;
  border-top: 1px solid var(--grid-line);
  pointer-events: none;
}

/* Sticky day headers */
#day-headers {
  display: flex;
  flex: 0 0 auto;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
  border-bottom: 1px solid var(--grid-line);
}
#day-headers .corner { width: var(--gutter-width); flex: 0 0 auto; }
.day-head {
  flex: 1 1 0;
  text-align: center;
  padding: 4px 0;
  border-left: 1px solid var(--grid-line);
  cursor: pointer;
}
.day-head .dow { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; }
.day-head .dom { font-size: 1.25rem; line-height: 1.1; }
.day-head.today .dom {
  background: var(--accent); color: #fff;
  border-radius: 50%; width: 1.7em; height: 1.7em;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ---- Event blocks ---- */
.event {
  position: absolute;
  background: var(--event-bg);
  color: var(--event-text);
  border-radius: 5px;
  padding: 2px 5px;
  font-size: 0.74rem;
  overflow: hidden;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.35);
}
.event.selected { outline: 2px solid #fbbc04; z-index: 3; }
.event .ev-title { font-weight: 600; }
.event .ev-time { opacity: 0.85; font-size: 0.68rem; }
.event { touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.event.dragging { z-index: 10; opacity: 0.9; box-shadow: 0 2px 10px rgba(0,0,0,0.3); cursor: grabbing; }

/* Resize grips at the top and bottom edges of an event. */
.ev-handle {
  position: absolute; left: 0; right: 0; height: 8px;
  cursor: ns-resize; touch-action: none;
}
.ev-handle.top { top: 0; }
.ev-handle.bottom { bottom: 0; }

/* Disable native scrolling under an active drag. */
body.dragging-active { overflow: hidden; touch-action: none; }
body.dragging-active #grid-scroll { overflow: hidden; }

.btn:disabled { opacity: 0.4; cursor: default; }

/* ---- Blip overlay (future health records) ---- */
#blip-layer {
  position: absolute;
  left: var(--gutter-width); top: 0; right: 0; bottom: 0;
  pointer-events: none;
}
.blip {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 1rem;
  pointer-events: auto;
  cursor: pointer;
}

/* ---- Detail panel ---- */
#detail-panel {
  position: fixed;
  z-index: 20;
  background: #fff;
  box-shadow: 0 -2px 16px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
}
#detail-panel.hidden { display: none; }
#detail-panel label { display: flex; flex-direction: column; font-size: 0.78rem; color: var(--muted); gap: 3px; }
#detail-panel label.checkbox { flex-direction: row; align-items: center; gap: 6px; }
#detail-panel input[type=text],
#detail-panel input[type=datetime-local],
#detail-panel textarea {
  font: inherit; color: var(--text);
  border: 1px solid var(--grid-line); border-radius: 6px; padding: 7px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head #panel-title-label { font-weight: 600; color: var(--text); }
.row { display: flex; gap: 8px; }
.row label { flex: 1 1 0; }
.panel-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }

/* Mobile: panel slides up from the bottom, full width. */
@media (max-width: 767px) {
  #detail-panel { left: 0; right: 0; bottom: 0; border-radius: 14px 14px 0 0; }
}
/* Desktop: panel docks to the right. */
@media (min-width: 768px) {
  #detail-panel { top: 0; right: 0; bottom: 0; width: 340px; border-radius: 0; }
}

.hidden { display: none !important; }
