/* ==========================================================================
   Longview
   The grid is the whole app, so it gets the whole window. Chrome is one 44px
   bar; everything else is days.
   ========================================================================== */

:root {
  --bg:        #ffffff;
  --fg:        #111113;
  --muted:     #8a8a90;
  --faint:     #b8b8be;
  --line:      #e7e7ea;
  --line-firm: #d4d4d9;
  --weekend:   #fafafa;
  --outside:   #f4f4f5;
  --today:     #111113;
  --sheet:     #ffffff;
  --shadow:    0 12px 40px rgba(0,0,0,.16), 0 2px 6px rgba(0,0,0,.06);

  --cell-min:  54px;
  --bar-h:     15px;
  --bar-gap:   2px;
  --hdr-h:     15px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0e0e10;
    --fg:        #f2f2f4;
    --muted:     #7e7e86;
    --faint:     #5a5a62;
    --line:      #232327;
    --line-firm: #33333a;
    --weekend:   #141417;
    --outside:   #1a1a1e;
    --today:     #f2f2f4;
    --sheet:     #17171a;
    --shadow:    0 12px 40px rgba(0,0,0,.6), 0 2px 6px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* The hidden attribute must beat any class that sets `display`. Without this,
   .modal and .drop (display:grid) ignore it and show on load. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--fg);
  font: 400 13px/1.3 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
        Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.bar {
  flex: 0 0 auto;
  height: 44px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.bar > .icon:last-child { justify-self: end; }

.yearnav { display: flex; align-items: center; gap: 4px; }
.yearnav h1 {
  font-size: 15px; font-weight: 600; letter-spacing: -0.01em;
  min-width: 4.2ch; text-align: center; font-variant-numeric: tabular-nums;
}

.icon {
  width: 30px; height: 30px; display: grid; place-items: center;
  background: none; border: 0; border-radius: 7px; cursor: pointer;
  color: var(--fg); opacity: .75;
}
.icon:hover { background: var(--line); opacity: 1; }
.icon:focus-visible { outline: 2px solid var(--fg); outline-offset: 1px; }
.icon svg {
  width: 18px; height: 18px; fill: none;
  stroke: currentColor; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ------------------------------------------------------------------ grid */

#grid {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* Rows take their content height, then share whatever is left over, so the
   year fills the window instead of stopping halfway down it. */
.row { position: relative; flex: 1 0 auto; }

/* Background layer: one cell per day, full row height. */
.rowbg {
  position: absolute; inset: 0;
  display: grid;
  pointer-events: none;
}
.cell { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.cell.weekend { background: var(--weekend); }
.cell.outside { background: var(--outside); }
.cell.blank   { background: var(--outside); border-right-color: transparent; }
.cell.mstart  { border-left: 1px solid var(--line-firm); margin-left: -1px; }
.cell.today   { box-shadow: inset 0 0 0 1.5px var(--today); }

/* Foreground layer: day labels on row 1, event bars on rows 2+. */
.rowfg {
  position: relative;
  display: grid;
  grid-auto-rows: calc(var(--bar-h) + var(--bar-gap));
  padding-bottom: 3px;
}

.dhdr {
  grid-row: 1;
  height: var(--hdr-h);
  display: flex; align-items: center; gap: 4px;
  padding: 3px 4px 0;
  font-size: 9.5px; font-weight: 500; letter-spacing: .04em;
  color: var(--faint);
  text-transform: uppercase;
  white-space: nowrap; overflow: hidden;
  cursor: pointer;
}
.dhdr:hover { color: var(--fg); }
.dhdr .dn { font-variant-numeric: tabular-nums; }
.dhdr.today .dn { color: var(--fg); font-weight: 700; }
.dhdr.outside { opacity: .45; }

/* Month marker: a black chip, the only strong mark in the grid. */
.mchip {
  display: inline-block;
  background: var(--fg); color: var(--bg);
  font-size: 9px; font-weight: 700; letter-spacing: .06em;
  padding: 1.5px 4px; border-radius: 3px;
  margin-right: 1px;
}

/* --------------------------------------------------------------- events */

.bar-ev {
  height: var(--bar-h);
  align-self: start;
  display: flex; align-items: center;
  padding: 0 5px;
  margin: 0 1px;
  border-radius: 4px;
  font-size: 10.5px; font-weight: 500; line-height: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer;
  border: 0;
  text-align: left;
  width: calc(100% - 2px);
}
.bar-ev:hover  { filter: brightness(.94); }
.bar-ev:focus-visible { outline: 2px solid var(--fg); outline-offset: 1px; }
/* A bar clipped by a row wrap loses the rounding on the cut edge. */
.bar-ev.cut-l { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: 0; }
.bar-ev.cut-r { border-top-right-radius: 0; border-bottom-right-radius: 0; margin-right: 0; width: calc(100% - 1px); }
.bar-ev.cut-l.cut-r { width: 100%; }

/* -------------------------------------------------------------- overlays */

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.28); z-index: 40; }

.panel {
  position: fixed; top: 0; left: 0; bottom: 0; width: min(360px, 88vw);
  background: var(--sheet); border-right: 1px solid var(--line);
  z-index: 50; overflow-y: auto; padding: 14px 18px 40px;
  box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.panel-head h2 { font-size: 15px; font-weight: 600; }
.panel section { padding: 14px 0; border-top: 1px solid var(--line); }
.panel h3 { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.muted { color: var(--muted); font-size: 12px; line-height: 1.5; }
.muted code { font-family: ui-monospace, Menlo, monospace; font-size: 11px; }

.check { display: flex; align-items: center; gap: 8px; padding: 5px 0; cursor: pointer; font-size: 13px; }
.check input { width: 15px; height: 15px; accent-color: var(--fg); }

.callist { display: flex; flex-direction: column; gap: 2px; }
.calrow { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 13px; }
.calrow .dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.calrow .nm { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calrow .rm { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 2px; }
.calrow .rm:hover { color: #d33; }

.btn {
  font: inherit; font-size: 12.5px; font-weight: 500;
  padding: 7px 12px; border-radius: 7px;
  border: 1px solid var(--line-firm); background: var(--bg); color: var(--fg);
  cursor: pointer;
}
.btn:hover { background: var(--line); }
.btn.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.btn.primary:hover { filter: brightness(1.15); }
.btn.danger { color: #d33; border-color: #e3b4b4; }
.btn.danger:hover { background: #fdeaea; }
.btn.file { display: inline-block; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; }

.keys { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; font-size: 12px; align-items: center; }
.keys dd { color: var(--muted); }
kbd {
  font: inherit; font-size: 10.5px; padding: 2px 5px;
  border: 1px solid var(--line-firm); border-bottom-width: 2px;
  border-radius: 4px; background: var(--bg);
}

/* ----------------------------------------------------------------- modal */

.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(0,0,0,.28); padding: 16px; }
.sheet {
  width: min(400px, 100%); background: var(--sheet);
  border-radius: 12px; padding: 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 13px;
}
.sheet h2 { font-size: 15px; font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); border: 0; }
.field2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field input[type="text"], .field input[type="date"] {
  font: inherit; font-size: 13px; color: var(--fg);
  padding: 8px 10px; border: 1px solid var(--line-firm); border-radius: 7px;
  background: var(--bg); width: 100%;
}
.field input:focus-visible { outline: 2px solid var(--fg); outline-offset: -1px; }
.field legend { font-size: 12px; color: var(--muted); margin-bottom: 5px; }

.swatches { display: flex; gap: 7px; flex-wrap: wrap; }
.sw { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.sw[aria-pressed="true"] { border-color: var(--fg); }

.sheet-foot { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.spacer { flex: 1 1 auto; }

/* ------------------------------------------------------------ misc chrome */

.drop { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; background: rgba(0,0,0,.45); color: #fff; font-size: 16px; font-weight: 600; }
.drop span { border: 2px dashed rgba(255,255,255,.7); padding: 28px 44px; border-radius: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 12px);
  background: var(--fg); color: var(--bg);
  padding: 9px 15px; border-radius: 8px; font-size: 12.5px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 80;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

@media print {
  .bar, .panel, .scrim, .modal, .toast, .drop { display: none !important; }
  body { overflow: visible; }
  #grid { overflow: visible; }
  .cell.weekend { background: #f6f6f6 !important; }
}

/* Google calendar list can run to dozens of entries, so it gets a filter,
   bulk toggles and its own scroll area. */
.calbar { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.calbar input[type="search"] {
  font: inherit; font-size: 12px; flex: 1 1 auto; min-width: 0;
  padding: 5px 8px; border: 1px solid var(--line-firm); border-radius: 6px;
  background: var(--bg); color: var(--fg);
}
.calbar input:focus-visible { outline: 2px solid var(--fg); outline-offset: -1px; }
.linkish {
  font: inherit; font-size: 12px; font-weight: 500;
  background: none; border: 0; color: var(--fg); cursor: pointer;
  padding: 4px 6px; border-radius: 5px; text-decoration: underline;
}
.linkish:hover { background: var(--line); }

#gCalList { max-height: 320px; overflow-y: auto; }
.calrow[hidden] { display: none; }

.credit { font-size: 11.5px; line-height: 1.55; }
.credit a { color: var(--fg); }
.muted.warn { color: #b45309; font-weight: 500; }
@media (prefers-color-scheme: dark) { .muted.warn { color: #f0b429; } }

/* ============================================================== statistics */

.baractions { display: flex; align-items: center; gap: 2px; justify-self: end; }
/* The home link is an anchor wearing .icon, so it needs the decoration off
   that the buttons never had. The gap falls on its right: it leads the group,
   and it separates leaving the app from the two actions that act inside it. */
.baractions .home { margin-right: 6px; text-decoration: none; }
.icon[aria-pressed="true"] { background: var(--line); opacity: 1; }

#stats { flex: 1 1 auto; overflow-y: auto; }
.swrap { max-width: 940px; margin: 0 auto; padding: 26px 20px 70px; }
.empty { color: var(--muted); font-size: 14px; line-height: 1.6; max-width: 46ch; margin: 40px auto; text-align: center; }

.sgroup { margin-bottom: 38px; }
.sgroup h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; margin-bottom: 4px; }
.sdesc { color: var(--muted); font-size: 12.5px; line-height: 1.55; margin-bottom: 12px; max-width: 62ch; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.tile { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 13px 14px 15px; }
.tv { font-size: 25px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tl { font-size: 12px; margin-top: 3px; }
.tn { font-size: 11px; color: var(--muted); margin-top: 4px; line-height: 1.4; }

.sfield { margin-top: 14px; max-width: 560px; }
.sfield input { font-size: 12.5px; }

.smatch { margin-top: 12px; font-size: 12.5px; }
.smatch summary { cursor: pointer; color: var(--muted); }
.smatch ul { list-style: none; margin-top: 8px; max-height: 260px; overflow-y: auto;
             border-left: 2px solid var(--line); padding-left: 10px; }
.smatch li { padding: 3px 0; }
.md { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11.5px; }

/* Bars: one series, so no legend. Values sit above each bar. */
.chart { display: grid; grid-template-columns: 34px 1fr; gap: 0 8px; margin-top: 22px; }
.yaxis { position: relative; height: 190px; }
.ytick { position: absolute; right: 0; transform: translateY(-50%); font-size: 10.5px;
         color: var(--muted); font-variant-numeric: tabular-nums; }
.plot { position: relative; height: 190px; }
.gridline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.bars { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(12, 1fr);
        gap: 6px; align-items: end; }
.bcol { position: relative; height: 100%; display: flex; align-items: flex-end; }
.bfill { width: 100%; background: #2a78d6; border-radius: 4px 4px 0 0; min-height: 2px; }
.bnum { position: absolute; top: -16px; left: 0; right: 0; text-align: center; font-size: 11px;
        font-weight: 600; font-variant-numeric: tabular-nums; }
.xaxis { grid-column: 2; display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; padding-top: 5px; }
.blab { font-size: 10.5px; color: var(--muted); text-align: center; }
@media (prefers-color-scheme: dark) { .bfill { background: #3987e5; } }

/* Heatmap: sequential single hue. Counts are printed in the cells, which is
   the relief the light end of the ramp needs. */
.heat { display: flex; flex-direction: column; gap: 2px; max-width: 560px; }
.hrow { display: grid; grid-template-columns: 34px repeat(7, 1fr); gap: 2px; }
.hh { font-size: 10.5px; color: var(--muted); text-align: right; padding-right: 6px; align-self: center;
      font-variant-numeric: tabular-nums; }
.hc { height: 22px; border-radius: 3px; display: grid; place-items: center;
      font-size: 10px; font-variant-numeric: tabular-nums; color: var(--muted);
      border: 1px solid var(--line); }
.hc.on { color: #fff; border-color: transparent; font-weight: 500; }
.hlab { border: 0; background: none !important; color: var(--muted); font-size: 10.5px; height: auto; }

.stable { border-collapse: collapse; font-size: 12px; margin-top: 10px; }
.stable th, .stable td { border: 1px solid var(--line); padding: 3px 8px; text-align: right;
                         font-variant-numeric: tabular-nums; }
.stable thead th { color: var(--muted); font-weight: 500; }
.stable tbody th { color: var(--muted); font-weight: 400; text-align: left; }

@media (max-width: 560px) {
  .bars { height: 150px; gap: 3px; }
  .blab { font-size: 9px; }
}
.pill { font-size: 10px; padding: 1px 5px; border-radius: 4px; background: var(--line); color: var(--muted); }
