:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #1d2430;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #2b6cb0;
  --danger: #b42318;
  --success: #17663a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

/* Shell: fixed sidebar on the left, content on the right. */

.shell {
  display: grid;
  grid-template-columns: 224px 1fr;
  min-height: 100vh;
  align-items: start;
}

.bare { min-height: 100vh; }
.bare .workspace { max-width: 420px; margin: 4rem auto; padding: 0 1.25rem; }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  padding: 1.25rem 0.9rem;
  background: var(--card);
  border-right: 1px solid var(--line);
}

.brand { font-weight: 600; text-decoration: none; color: var(--ink); font-size: 1.05rem; }

.nav-group { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.15rem; }
.nav-group a {
  display: block;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
}
.nav-group a:hover { background: var(--bg); color: var(--ink); }
.nav-group a.active { background: #e8f0fa; color: var(--accent); font-weight: 600; }
.nav-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 0.75rem; }
.badge {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 0.72rem;
  padding: 0.05rem 0.45rem;
  margin-left: 0.2rem;
}
.nav-signout { margin: 0; }
.nav-signout .linkish { font-size: 0.9rem; }
.nav-tz { margin: 0; font-size: 0.78rem; color: var(--muted); }

.workspace { padding: 1.5rem 1.5rem 3rem; min-width: 0; }

h1 { font-size: 1.4rem; margin: 0 0 0.25rem; }
h2 { font-size: 1rem; margin: 1.5rem 0 0.5rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }

.page-header { margin-bottom: 1rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card.narrow { max-width: 380px; margin: 3rem auto; }

label { display: block; margin: 0.75rem 0 0.25rem; font-weight: 500; font-size: 0.9rem; }
input[type="text"], input[type="password"], input[type="date"], input[type="time"],
input[type="number"], select, textarea {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.row { display: flex; gap: 1rem; flex-wrap: wrap; }
.row > div { flex: 1 1 160px; }

fieldset { border: 1px solid var(--line); border-radius: 6px; margin: 1rem 0 0; padding: 0.5rem 0.9rem 0.9rem; }
legend { font-size: 0.85rem; color: var(--muted); padding: 0 0.4rem; }
.checkbox { display: flex; align-items: center; gap: 0.5rem; font-weight: 400; }
.checkbox input { width: auto; }

button, .button {
  display: inline-block;
  margin-top: 1.25rem;
  padding: 0.55rem 1rem;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}
button:hover, .button:hover { filter: brightness(1.08); }
.button.secondary { background: var(--line); color: var(--ink); margin-left: 0.5rem; }

.inline { display: inline; }
.linkish {
  background: none;
  color: var(--accent);
  padding: 0;
  margin: 0;
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
}
.linkish.danger { color: var(--danger); }

table.events { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
table.events th, table.events td { text-align: left; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.events th { background: #fafbfc; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
table.events tr:last-child td { border-bottom: 0; }
td.when { white-space: nowrap; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
td.actions form { display: inline; }
td.actions a { margin-left: 0.75rem; }

.flash { padding: 0.7rem 0.9rem; border-radius: 6px; border: 1px solid var(--line); background: var(--card); }
.flash-success { border-color: #a7d7bb; background: #edf8f1; color: var(--success); }
.flash-error { border-color: #f0b4ae; background: #fdf1f0; color: var(--danger); }
.flash-info { border-color: #bcd3ea; background: #eef5fc; color: var(--accent); }

.pill { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.78rem; background: var(--line); }
.pill-created { background: #e3f2e8; color: var(--success); }
.pill-updated { background: #e8f0fa; color: var(--accent); }
.pill-deleted { background: #fbe9e7; color: var(--danger); }
.pill-ok { background: #e3f2e8; color: var(--success); }
.pill-error { background: #fbe9e7; color: var(--danger); }
.pill-pending { background: #fdf3e3; color: #8a5a00; }

code { background: #eef1f4; padding: 0.05rem 0.3rem; border-radius: 4px; font-size: 0.9em; }

.placeholder { max-width: 620px; }

/* ------------------------------------------------------------------ */
/* Calendar                                                            */
/* ------------------------------------------------------------------ */

.cal-bar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.cal-bar h1 { font-size: 1.25rem; margin: 0; }
.cal-nav { display: flex; align-items: center; gap: 0.35rem; }
.cal-views { display: flex; gap: 0.35rem; margin-left: auto; }

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
  font-size: 1.15rem;
  line-height: 1;
}
.icon-button:hover { border-color: var(--accent); color: var(--accent); }

.button.ghost {
  margin-top: 0;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 0.45rem 0.8rem;
}
.button.ghost:hover { border-color: var(--accent); color: var(--accent); filter: none; }
.button.ghost.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.ghost.small { padding: 0.3rem 0.6rem; font-size: 0.85rem; }

.cal-sub { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.cal-filter { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; margin-left: auto; }
.filter-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.cal-filter .check {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  font-weight: 400;
  font-size: 0.9rem;
}
.cal-filter .check input { width: auto; }
.cal-filter button { margin-top: 0; }
.clear-filter { font-size: 0.85rem; color: var(--muted); }
.clear-filter:hover { color: var(--accent); }

/* One colour per calendar account, so a busy week is readable at a glance.
   The class is assigned by account order in config.json (see
   app.account_colours), which keeps an account's colour stable as others come
   and go. Every event surface reads the same three variables. */
.acct-0 { --evt-bg: #e8f0fa; --evt-fg: #1b4f7f; --evt-line: #4a90d9; }
.acct-1 { --evt-bg: #e6f4ea; --evt-fg: #1e5b33; --evt-line: #47a06b; }
.acct-2 { --evt-bg: #fdf1dc; --evt-fg: #7a4b12; --evt-line: #d99125; }
.acct-3 { --evt-bg: #efe9fb; --evt-fg: #4a3f8f; --evt-line: #8a72d9; }
.acct-4 { --evt-bg: #fdeaea; --evt-fg: #8c2f36; --evt-line: #d9585f; }
.acct-5 { --evt-bg: #e2f4f4; --evt-fg: #14535a; --evt-line: #3aa0a8; }
.acct-6 { --evt-bg: #eae7f7; --evt-fg: #3b3163; --evt-line: #6f5fb8; }
.acct-7 { --evt-bg: #f4ebe4; --evt-fg: #6b4a2f; --evt-line: #a9784f; }

/* The filter shows the same colour beside each name, so the grid can be read
   without hovering. */
.swatch {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 3px;
  background: var(--evt-line, var(--muted));
  flex: none;
}

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

.month { background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.month-head {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  background: #fafbfc;
  border-bottom: 1px solid var(--line);
}
.month-dow {
  padding: 0.5rem 0.6rem;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.month-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}
.month-row:last-child { border-bottom: 0; }
.month-cell {
  min-height: 6.5rem;
  padding: 0.3rem 0.35rem 0.45rem;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.month-cell:last-child { border-right: 0; }
.month-cell.weekend { background: #fbfcfd; }
.month-cell.outside { background: #fafbfc; }
.month-cell.outside .month-cell-head a { color: #b8bec8; }
.month-cell.today { background: #eef5fc; }
.month-cell-head { display: flex; justify-content: flex-end; }
.month-cell-head a {
  font-size: 0.82rem;
  color: var(--muted);
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}
.month-cell-head a:hover { color: var(--accent); }
.month-cell.today .month-cell-head a { color: var(--accent); font-weight: 700; }

.chip {
  display: block;
  padding: 0.12rem 0.35rem;
  border-radius: 4px;
  font-size: 0.78rem;
  background: var(--evt-bg, #e8f0fa);
  color: var(--evt-fg, #1b4f7f);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.chip:hover { filter: brightness(0.95); }
.chip-time { font-variant-numeric: tabular-nums; margin-right: 0.3rem; opacity: 0.85; }
.chip-more { font-size: 0.74rem; color: var(--muted); text-decoration: none; }
.chip-more:hover { color: var(--accent); }

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

.timegrid {
  --gutter: 3.8rem;
  --hour-h: 3rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.tg-head {
  display: grid;
  grid-template-columns: var(--gutter) repeat(var(--days), minmax(0, 1fr));
  background: #fafbfc;
  border-bottom: 1px solid var(--line);
}
.tg-corner { border-right: 1px solid var(--line); }
.tg-dayhead { padding: 0.4rem 0.25rem; text-align: center; border-right: 1px solid var(--line); min-width: 0; }
.tg-dayhead:last-child { border-right: 0; }
.tg-dayhead.weekend { background: #f6f8fa; }
.tg-dayhead.today { background: #eef5fc; }
.tg-dow { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.tg-dom { font-size: 1.05rem; color: var(--ink); text-decoration: none; font-variant-numeric: tabular-nums; }
.tg-dayhead.today .tg-dom { color: var(--accent); font-weight: 700; }

.tg-allday {
  display: grid;
  grid-template-columns: var(--gutter) minmax(0, 1fr);
  border-bottom: 1px solid var(--line);
  background: #fcfdfe;
}
.tg-allday-label {
  grid-column: 1;
  grid-row: 1 / span var(--allday-rows);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 0.15rem 0.5rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  border-right: 1px solid var(--line);
}
.tg-bars {
  display: grid;
  grid-template-columns: repeat(var(--days), minmax(0, 1fr));
  grid-template-rows: repeat(var(--allday-rows), 1.7rem);
  align-content: start;
}
.bar {
  margin: 0 2px;
  align-self: center;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.78rem;
  background: var(--evt-bg, #e9e5fb);
  color: var(--evt-fg, #4a3f8f);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.bar:hover { filter: brightness(0.95); }

.tg-scroll { max-height: 68vh; overflow-y: auto; }
.tg-body { display: grid; grid-template-columns: var(--gutter) minmax(0, 1fr); }
.tg-hours { border-right: 1px solid var(--line); }
.tg-hour {
  height: var(--hour-h);
  border-top: 1px solid var(--line);
}
.tg-hour span {
  display: block;
  text-align: right;
  padding-right: 0.5rem;
  font-size: 0.7rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  transform: translateY(-0.62em);
}

.tg-cols { display: grid; grid-template-columns: repeat(var(--days), minmax(0, 1fr)); }
.tg-col {
  position: relative;
  height: calc(var(--hour-h) * 24);
  border-right: 1px solid var(--line);
  background-image: repeating-linear-gradient(
    to bottom,
    var(--line) 0 1px,
    transparent 1px var(--hour-h)
  );
  min-width: 0;
}
.tg-col:last-child { border-right: 0; }
.tg-col.weekend { background-color: #fbfcfd; }

.slot { position: absolute; left: 0; right: 0; height: calc(100% / 24); display: block; z-index: 1; }
.slot:hover { background: #eef5fc; }

.block {
  position: absolute;
  z-index: 2;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0.15rem 0.35rem;
  border-radius: 5px;
  border-left: 3px solid var(--evt-line, var(--accent));
  background: var(--evt-bg, #e8f0fa);
  color: var(--evt-fg, #1b4f7f);
  font-size: 0.78rem;
  text-decoration: none;
  min-width: 0;
}
.block:hover { filter: brightness(0.95); }
.block-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.block-time { font-size: 0.7rem; opacity: 0.85; font-variant-numeric: tabular-nums; }
.block.continues-before { border-top-left-radius: 0; border-top-right-radius: 0; }
.block.continues-after { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }

@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav-foot { margin-top: 0; }
  .timegrid { --gutter: 2.8rem; }
}
