/* ============================================================
   iPad Family Calendar - styles
   Tuned for a 1024x768 iPad in landscape, but scales sensibly.
   ============================================================ */

:root {
  --bg:        #0d1117;
  --panel:     #141a22;
  --panel-2:   #1b2430;
  --line:      #263041;
  --line-soft: #1c2431;
  --text:      #e9eff7;
  --muted:     #8a97a8;
  --dim:       #5d6a7a;
  --accent:    #4c8dff;
  --danger:    #ff5d5d;
  --ok:        #37d67a;

  --gutter: 3.6em;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: clamp(14px, 1.55vw, 19px);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

/* ---------------- app shell ---------------- */

#app {
  display: flex;
  height: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ---------------- Today at a Glance ---------------- */

#today-panel {
  width: clamp(240px, 28vw, 350px);
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 1.1em 1.1em 0.6em;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.clock {
  font-size: 3.1em;
  font-weight: 300;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.today-date {
  margin-top: 0.35em;
  font-size: 1.05em;
  color: var(--muted);
}

.today-label {
  margin: 1.1em 0 0.5em;
  font-size: 0.72em;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
}

.today-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -0.3em;
  padding: 0 0.3em;
}

.tev {
  display: flex;
  gap: 0.7em;
  padding: 0.62em 0.1em;
  border-top: 1px solid var(--line-soft);
}
.tev:first-child { border-top: 0; }

.tev-bar {
  width: 5px;
  flex: none;
  border-radius: 3px;
  background: var(--accent);
}

.tev-body { min-width: 0; flex: 1; }

.tev-time {
  font-size: 0.82em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.tev-title {
  font-size: 1.12em;
  font-weight: 600;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.tev-loc {
  font-size: 0.8em;
  color: var(--dim);
  margin-top: 0.15em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tev.is-past { opacity: 0.42; }

.tev.is-now {
  background: rgba(76, 141, 255, 0.11);
  border-radius: var(--radius);
  padding-left: 0.5em;
  padding-right: 0.5em;
  margin-left: -0.4em;
  margin-right: -0.4em;
}
.tev.is-now .tev-time { color: var(--accent); font-weight: 600; }

.today-empty {
  color: var(--dim);
  font-size: 1.05em;
  padding: 1.4em 0;
  line-height: 1.5;
}

/* ---------------- top bar ---------------- */

#topbar {
  display: flex;
  align-items: center;
  gap: 0.9em;
  padding: 0.7em 1em;
  border-bottom: 1px solid var(--line);
  flex: none;
}

.tabs {
  display: flex;
  background: var(--panel-2);
  border-radius: var(--radius);
  padding: 3px;
  flex: none;
}

.tab {
  padding: 0.42em 0.95em;
  border-radius: 7px;
  color: var(--muted);
  font-size: 0.92em;
  font-weight: 600;
}
.tab.is-active {
  background: var(--accent);
  color: #fff;
}

.nav { display: flex; align-items: center; gap: 0.25em; flex: none; }

.navbtn {
  min-width: 2.1em;
  height: 2.1em;
  padding: 0 0.6em;
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 0.95em;
  line-height: 1;
}
.today-btn { font-weight: 600; font-size: 0.85em; }

.range-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 1.15em;
  font-weight: 600;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  display: flex;
  align-items: center;
  gap: 0.45em;
  color: var(--dim);
  font-size: 0.78em;
  flex: none;
  white-space: nowrap;
}
.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ok);
  flex: none;
}
.status.is-loading .dot { background: var(--accent); animation: pulse 1.1s infinite; }
.status.is-error   .dot { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: 0.25 } }

/* ---------------- view area ---------------- */

.view-root {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.loading-note {
  padding: 2em;
  color: var(--dim);
  text-align: center;
  line-height: 1.6;
}
.loading-note .why { font-size: 0.85em; margin-top: 0.6em; }

/* ---------------- access key prompt ---------------- */

.keyprompt {
  max-width: 34em;
  margin: 0 auto;
  padding: 2em 1.5em;
  text-align: center;
}
.keyprompt h2 { margin: 0 0 0.4em; font-size: 1.5em; font-weight: 600; }
.keyprompt p { margin: 0 0 1.4em; color: var(--muted); line-height: 1.5; }

.keyprompt input {
  width: 100%;
  padding: 0.75em 0.9em;
  font: inherit;
  font-size: 1em;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  /* body sets user-select:none, which would stop paste working in here */
  user-select: text;
  -webkit-user-select: text;
}
.keyprompt input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.keybtn {
  margin-top: 0.9em;
  padding: 0.7em 1.4em;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.keymsg { margin-top: 0.8em; color: var(--muted); font-size: 0.9em; min-height: 1.2em; }
.keyprompt .why { margin-top: 1.2em; color: var(--dim); font-size: 0.82em; }

/* ---------------- month view ---------------- */

.month { display: flex; flex-direction: column; height: 100%; }

.month-head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.month-head div {
  padding: 0.45em 0.6em;
  font-size: 0.72em;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
}

.month-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: 1fr;
}

.mcell {
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  padding: 0.3em 0.32em;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.mcell:nth-child(7n) { border-right: 0; }
.mcell.is-outside { opacity: 0.32; }
.mcell.is-weekend { background: rgba(255,255,255,0.014); }
.mcell.is-today { background: rgba(76,141,255,0.10); }

.mnum {
  font-size: 0.82em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 0.2em;
  flex: none;
}
.mcell.is-today .mnum {
  color: #fff;
  background: var(--accent);
  border-radius: 999px;
  width: 1.85em;
  height: 1.85em;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mchips { flex: 1; min-height: 0; overflow: hidden; }

.chip {
  display: block;
  font-size: 0.72em;
  line-height: 1.25;
  padding: 0.2em 0.4em;
  margin-bottom: 2px;
  border-radius: 5px;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip.is-light { color: #10151c; }
.chip .t { opacity: 0.8; font-variant-numeric: tabular-nums; }

.more {
  font-size: 0.68em;
  color: var(--dim);
  padding-left: 0.35em;
}

/* ---------------- day + week time grid ---------------- */

.tg { display: flex; flex-direction: column; height: 100%; }

.tg-head, .tg-allday, .tg-body { display: grid; }

.tg-head {
  border-bottom: 1px solid var(--line);
  flex: none;
}
.tg-head .corner { border-right: 1px solid var(--line-soft); }
.tg-daylabel {
  padding: 0.45em 0.5em;
  text-align: center;
  border-right: 1px solid var(--line-soft);
}
.tg-daylabel:last-child { border-right: 0; }
.tg-daylabel .dow {
  font-size: 0.68em;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
}
.tg-daylabel .dnum {
  font-size: 1.25em;
  font-weight: 600;
  line-height: 1.3;
}
.tg-daylabel.is-today .dnum {
  color: #fff;
  background: var(--accent);
  border-radius: 999px;
  width: 1.6em;
  height: 1.6em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tg-daylabel.is-today .dow { color: var(--accent); }

.tg-allday {
  border-bottom: 1px solid var(--line);
  flex: none;
  max-height: 5.2em;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.tg-allday.is-empty { display: none; }
.tg-allday .corner {
  border-right: 1px solid var(--line-soft);
  font-size: 0.6em;
  color: var(--dim);
  padding: 0.5em 0.4em;
  text-align: right;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.tg-allday .cell {
  border-right: 1px solid var(--line-soft);
  padding: 0.22em 0.25em;
  min-width: 0;
  overflow: hidden;
}
.tg-allday .cell:last-child { border-right: 0; }

/* The scroll container. If the day does not fit at a readable size, this
   scrolls instead of squashing the hours into slivers. */
.tg-body {
  flex: 1;
  min-height: 0;
  display: block;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* The thing being scrolled - given an explicit pixel height after render. */
.tg-canvas {
  display: grid;
  position: relative;
}

.tg-gutter {
  position: relative;
  border-right: 1px solid var(--line-soft);
}
.tg-hour {
  position: absolute;
  right: 0.45em;
  transform: translateY(-50%);
  font-size: 0.7em;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
/* The very first label sits on the top edge - drop it down so it is not cut off. */
.tg-hour.is-first { transform: translateY(0.1em); }

.tg-col {
  position: relative;
  border-right: 1px solid var(--line-soft);
  min-width: 0;
}
.tg-col:last-child { border-right: 0; }
.tg-col.is-weekend { background: rgba(255,255,255,0.014); }
.tg-col.is-today { background: rgba(76,141,255,0.07); }

.tg-line {
  position: absolute;
  left: 0; right: 0;
  height: 0;
  border-top: 1px solid var(--line-soft);
  pointer-events: none;
}

.ev {
  position: absolute;
  border-radius: 6px;
  padding: 0.22em 0.42em;
  overflow: hidden;
  color: #fff;
  font-size: 0.76em;
  line-height: 1.22;
  border-left: 3px solid rgba(0,0,0,0.28);
}
.ev.is-light { color: #10151c; border-left-color: rgba(0,0,0,0.18); }
.ev .ev-time { opacity: 0.85; font-variant-numeric: tabular-nums; }
.ev .ev-title { font-weight: 600; overflow-wrap: anywhere; }
.ev.is-past { opacity: 0.45; }

.tg-body.is-day .ev { font-size: 0.95em; padding: 0.4em 0.7em; }

.nowline {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: var(--danger);
  pointer-events: none;
  z-index: 5;
}
.nowline::before {
  content: "";
  position: absolute;
  left: -4px; top: -3px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--danger);
}

/* ---------------- legend ---------------- */

.legend {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35em 1.1em;
  padding: 0.5em 1em;
  border-top: 1px solid var(--line);
  font-size: 0.76em;
  color: var(--muted);
  max-height: 4.4em;
  overflow: hidden;
}
.legend:empty { display: none; }
.legend .li { display: flex; align-items: center; gap: 0.45em; }
.legend .sw { width: 0.85em; height: 0.85em; border-radius: 3px; flex: none; }
.legend .note { color: var(--dim); font-style: italic; }

/* ---------------- night screen ---------------- */

.sleep-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 100;
  color: #3a4351;
}
.sleep-overlay[hidden] { display: none; }

.sleep-inner {
  position: absolute;
  text-align: center;
  transition: left 1.6s ease, top 1.6s ease;
  transform: translate(-50%, -50%);
}
.sleep-clock {
  font-size: 5.4em;
  font-weight: 200;
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.sleep-sub {
  margin-top: 0.6em;
  font-size: 0.95em;
  color: #2c343f;
}

/* ---------------- portrait ---------------- */

@media (orientation: portrait) {
  #app { flex-direction: column; }

  #today-panel {
    width: 100%;
    max-height: 36vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .clock { font-size: 2.5em; }
  #today-panel .today-label { margin-top: 0.8em; }
}

/* Narrow screens (a phone, or the desktop browser while you develop). */
@media (max-width: 620px) {
  #today-panel { max-height: 42vh; }
  .range-title { font-size: 1em; }
  .status span:last-child { display: none; }
}
