/* Batphone styles. Dark theme by default; large text; strong focus outlines. */

:root,
[data-theme='dark'] {
  --bg: #121212;
  --surface: #1e1e1e;
  --text: #f2f2f2;
  --muted: #cfcfcf;
  --link: #9cc2ff;
  --link-visited: #d0b3ff;
  --border: #8a8a8a;
  --focus: #ffd166;
  --focus-text: #121212;
  --button-bg: #9cc2ff;
  --button-text: #0b1a33;
  --button2-bg: transparent;
  --button2-text: #f2f2f2;
  --error: #ff9b91;
  --error-bg: #3a1714;
  --success: #86e3ae;
  --success-bg: #11301f;
  --info: #9cc2ff;
  --info-bg: #14233d;
}

[data-theme='light'] {
  --bg: #ffffff;
  --surface: #f3f3f3;
  --text: #111111;
  --muted: #3d3d3d;
  --link: #0b4fc2;
  --link-visited: #5b2a9e;
  --border: #6b6b6b;
  --focus: #ffd166;
  --focus-text: #111111;
  --button-bg: #0b4fc2;
  --button-text: #ffffff;
  --button2-bg: transparent;
  --button2-text: #111111;
  --error: #a4231a;
  --error-bg: #fdecea;
  --success: #146c2e;
  --success-bg: #e8f5ec;
  --info: #0b4fc2;
  --info-bg: #e8f0fe;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 125%; /* 20px base */
  -webkit-text-size-adjust: 100%;
}

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

.wrap {
  max-width: 64rem;
  margin: 0 auto;
  padding: 0 1rem;
}

h1 { font-size: 2rem; line-height: 1.2; margin: 1.5rem 0 1rem; }
h2 { font-size: 1.4rem; line-height: 1.25; margin: 2rem 0 0.75rem; }
p, ul, dl { margin: 0 0 1rem; }

a { color: var(--link); text-underline-offset: 0.15em; }
a:visited { color: var(--link-visited); }
a:hover { text-decoration-thickness: 3px; }

:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 2px;
}
a:focus-visible {
  background: var(--focus);
  color: var(--focus-text);
  outline-color: var(--focus);
  text-decoration: none;
}

main:focus { outline: none; }

.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -10rem;
  padding: 0.5rem 1rem;
  background: var(--focus);
  color: var(--focus-text);
  z-index: 10;
}
.skip-link:focus { top: 0.5rem; }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Header and footer */
.site-header { background: var(--surface); border-bottom: 2px solid var(--border); }
.header-inner { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.5rem; padding-top: 0.5rem; padding-bottom: 0.5rem; }
.brand { font-weight: 700; font-size: 1.3rem; color: var(--text); text-decoration: none; }
.brand:visited { color: var(--text); }
.main-nav { flex: 1; }
.nav-list { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 1.25rem; list-style: none; margin: 0; padding: 0; }
.nav-list a { display: inline-block; padding: 0.4rem 0; }
.nav-list a[aria-current='page'] { font-weight: 700; text-decoration-thickness: 3px; }
/* Sign out lives in the footer; on phones it's also at the end of the menu. */
.nav-signout { display: none; }
.footer-user { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 1rem; }
.link-button {
  min-height: 0;
  padding: 0.25rem 0;
  border: 0;
  background: none;
  color: var(--link);
  font-weight: 400;
  text-decoration: underline;
  text-underline-offset: 0.15em;
}
.link-button:hover { text-decoration-thickness: 3px; }
.signout { margin: 0; }
.menu-button { display: none; }

/* Phones: a single "Menu" button; the menu opens as a full-width list. */
@media (max-width: 48rem) {
  .header-inner { flex-wrap: wrap; }
  .js .menu-button { display: inline-block; margin-left: auto; }
  .js .main-nav { display: none; flex-basis: 100%; }
  .js .main-nav.open { display: block; }
  .nav-list { flex-direction: column; align-items: stretch; gap: 0; }
  .nav-list li { border-top: 1px solid var(--border); }
  .nav-list a { display: block; padding: 0.75rem 0.25rem; }
  .nav-signout { display: block; padding: 0.75rem 0 0.5rem; }
  .oncall-bar { font-size: 0.9rem; }
  h1 { font-size: 1.6rem; margin-top: 1rem; }
}
.site-footer { margin-top: 3rem; border-top: 2px solid var(--border); background: var(--surface); }
.footer-inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; padding-top: 1rem; padding-bottom: 1rem; }
.footer-inner p { margin: 0; color: var(--muted); }

/* Buttons */
button,
.button {
  display: inline-block;
  min-height: 2.75rem;
  padding: 0.5rem 1.25rem;
  border: 2px solid var(--button-bg);
  border-radius: 0.3rem;
  background: var(--button-bg);
  color: var(--button-text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.button:visited { color: var(--button-text); }
.button-secondary {
  background: var(--button2-bg);
  color: var(--button2-text);
  border-color: var(--border);
}
button:focus-visible,
.button:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 2px;
  background: var(--focus);
  color: var(--focus-text);
  border-color: var(--focus);
}
.button-row { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.5rem; margin: 1.5rem 0; }

/* Forms */
.field { margin: 0 0 1.5rem; }
fieldset { border: 0; padding: 0; margin: 0 0 1.5rem; }
legend { font-weight: 700; font-size: 1.1rem; margin-bottom: 0.5rem; }
label { display: block; font-weight: 700; margin-bottom: 0.25rem; }
.hint { color: var(--muted); margin: 0 0 0.4rem; }
input[type='text'],
input[type='email'],
input[type='password'],
input[type='date'],
select {
  width: 100%;
  max-width: 30rem;
  min-height: 2.75rem;
  padding: 0.4rem 0.6rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 0.2rem;
}
.input-short { max-width: 10rem; }
input:focus-visible,
select:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 0;
  box-shadow: inset 0 0 0 2px var(--text);
}
.choice {
  display: grid;
  grid-template-columns: 2.25rem 1fr;
  align-items: start;
  column-gap: 0.5rem;
  margin-bottom: 1rem;
}
.choice input { width: 1.75rem; height: 1.75rem; margin: 0.15rem 0 0; accent-color: var(--button-bg); }
.choice label { font-weight: 400; margin: 0; }
.choice .hint { grid-column: 2; }
.field-has-error { border-left: 5px solid var(--error); padding-left: 1rem; }
.field-has-error input,
.field-has-error select { border-color: var(--error); }
.field-error { color: var(--error); font-weight: 700; margin: 0 0 0.4rem; }

.error-summary {
  border: 4px solid var(--error);
  padding: 1rem 1.25rem;
  margin: 0 0 2rem;
}
.error-summary h2 { margin-top: 0; }
.error-summary ul { margin: 0; padding-left: 1.25rem; }
.error-summary a { color: var(--error); font-weight: 700; }

/* Banners */
.banner { padding: 1rem 1.25rem; margin: 1.5rem 0 0; border-left: 6px solid; }
.banner-success { background: var(--success-bg); border-color: var(--success); }
.banner-error { background: var(--error-bg); border-color: var(--error); }
.banner-info { background: var(--info-bg); border-color: var(--info); }

/* Tables: rows become stacked cards on narrow screens */
table { width: 100%; border-collapse: collapse; margin: 0 0 1.5rem; }
th, td { text-align: left; vertical-align: top; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }
thead th { border-bottom: 3px solid var(--border); }
.plain-list { list-style: none; padding: 0; margin: 0; }
@media (max-width: 45rem) {
  table.responsive thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.responsive tr { display: block; border: 2px solid var(--border); border-radius: 0.3rem; margin-bottom: 1rem; padding: 0.5rem 0; }
  table.responsive td { display: block; border: 0; padding: 0.25rem 0.75rem; }
  table.responsive td::before { content: attr(data-label) ': '; font-weight: 700; }
}

/* Summary lists */
.summary-list div { display: flex; flex-wrap: wrap; gap: 0 1rem; padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.summary-list dt { font-weight: 700; min-width: 14rem; }
.summary-list dd { margin: 0; }

.filters { background: var(--surface); padding: 0.5rem 1.25rem 0.25rem; border-radius: 0.3rem; }
.filters h2 { margin-top: 0.75rem; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 0 1.5rem; }
.pager { display: flex; gap: 2rem; margin: 1rem 0; }

code { font-size: 0.95em; background: var(--surface); padding: 0.1em 0.3em; border-radius: 0.2rem; }

dialog {
  max-width: 32rem;
  padding: 1.5rem;
  color: var(--text);
  background: var(--surface);
  border: 3px solid var(--focus);
  border-radius: 0.4rem;
}
dialog::backdrop { background: rgb(0 0 0 / 0.7); }
dialog h2 { margin-top: 0; }

/* On-call bar under the header */
.oncall-bar { background: var(--success-bg); border-bottom: 2px solid var(--success); padding: 0.5rem 0; }
.oncall-bar.oncall-none { background: var(--error-bg); border-bottom-color: var(--error); }
.oncall-list { padding-left: 1.5rem; }

/* Extra form bits */
.field-row { display: flex; flex-wrap: wrap; gap: 0 1.5rem; }
.field-row .field { min-width: 10rem; }
input[type='time'],
input[type='tel'] {
  min-height: 2.75rem;
  padding: 0.4rem 0.6rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 0.2rem;
}
input[type='time']:focus-visible,
input[type='tel']:focus-visible { outline: 4px solid var(--focus); outline-offset: 0; }
.input-medium { width: 100%; max-width: 16rem; }
.day-choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); }
.button-danger { background: var(--error); border-color: var(--error); color: var(--bg); }
.inline-form { display: flex; flex-wrap: wrap; align-items: end; gap: 0.5rem 1rem; margin: 0 0 1rem; }
.inline-form label { margin: 0; }
.inline-form input { width: auto; }
.week-heading { margin-top: 0; }
.week-nav, .view-switch { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; margin: 0 0 1rem; }
.view-switch a[aria-current='page'] { font-weight: 700; text-decoration-thickness: 3px; }
.row-gap td { background: var(--error-bg); }

/* Rota week grid */
.rota-help { color: var(--muted); }
.rg-palette { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0 0 1rem; }
.rg-palette-label { color: var(--muted); }
.rg-chip {
  padding: 0.3rem 0.8rem;
  border: 2px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.rg-scroll {
  max-height: 75vh;
  overflow: auto;
  border: 2px solid var(--border);
  border-radius: 0.3rem;
}
.rg {
  --q: 0.55rem; /* height of 15 minutes */
  display: grid;
  grid-template-columns: 3.5rem repeat(7, minmax(7.5rem, 1fr));
  grid-template-rows: auto calc(var(--q) * 96);
  min-width: 56rem;
}
.rg-corner, .rg-dayhead {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  padding: 0.3rem 0.4rem;
  font-size: 0.85rem;
}
.rg-dayhead { font-weight: 700; text-align: center; border-left: 1px solid var(--border); }
.rg-today { background: var(--info-bg); }
.rg-dayname { display: block; }
.rg-hours, .rg-day {
  display: grid;
  grid-template-rows: repeat(96, var(--q));
}
.rg-hours { font-size: 0.75rem; color: var(--muted); }
.rg-hour { padding: 0 0.3rem; border-top: 1px solid var(--border); }
.rg-day {
  position: relative;
  border-left: 1px solid var(--border);
  background-image: linear-gradient(to bottom, var(--border) 1px, transparent 1px);
  background-size: 100% calc(var(--q) * 4);
  column-gap: 2px;
}
.rg-shift {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: 1px 0;
  padding: 0.15rem 0.3rem;
  border-radius: 0.25rem;
  border: 2px solid var(--text);
  background: var(--info-bg);
  color: var(--text);
  font-size: 0.75rem;
  line-height: 1.25;
  text-decoration: none;
}
.rg-shift:visited { color: var(--text); }
.rg-shift.p1 { background: var(--success-bg); }
.rg-shift.p2 { background: var(--info-bg); }
.rg-shift.p3, .rg-shift.p4, .rg-shift.p5 { background: var(--surface); border-style: dashed; }
.rg-name { font-weight: 700; }
.rg-shift:focus-visible { outline: 4px solid var(--focus); outline-offset: 1px; z-index: 4; }
.rg-shift.dragging { opacity: 0.4; }
.rg-resize {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0.6rem;
  cursor: ns-resize;
  background: linear-gradient(to bottom, transparent 40%, var(--text) 40%, var(--text) 60%, transparent 60%);
  opacity: 0.6;
}
.rg-gap {
  z-index: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 0.2rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--error);
  background: repeating-linear-gradient(135deg, var(--error-bg) 0 0.5rem, transparent 0.5rem 1rem);
  border-left: 3px solid var(--error);
  overflow: hidden;
}
.rg-drop-target { outline: 3px dashed var(--focus); outline-offset: -3px; }
.rg-ghost {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  padding: 0.3rem 0.6rem;
  border-radius: 0.3rem;
  background: var(--focus);
  color: var(--focus-text);
  font-weight: 700;
  font-size: 0.85rem;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Messages */
.badge { display: inline-block; min-width: 1.5em; padding: 0 0.35em; border-radius: 1em; background: var(--focus); color: var(--focus-text); font-weight: 700; text-align: center; }
.row-unread td { font-weight: 700; }
.message-list { list-style: none; padding: 0; }
.message { padding: 0.75rem 1rem; margin: 0 0 1rem; border-radius: 0.4rem; border: 2px solid var(--border); max-width: 42rem; }
.message-inbound { background: var(--surface); }
.message-outbound { background: var(--info-bg); margin-left: auto; }
.message-heading { font-size: 1rem; margin: 0 0 0.3rem; color: var(--muted); }
.message-body { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.message-status { margin: 0.4rem 0 0; font-weight: 700; }

/* Status page */
.status-ok { color: var(--success); }
.status-bad { color: var(--error); }

/* Settings */
textarea {
  width: 100%;
  max-width: 40rem;
  padding: 0.4rem 0.6rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 0.2rem;
}
textarea:focus-visible { outline: 4px solid var(--focus); outline-offset: 0; }
.fallback-list { padding-left: 1.5rem; }
.fallback-list li { margin-bottom: 0.75rem; }
.fallback-name { display: block; }
.fallback-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.3rem; }
.inline-action { display: inline; margin: 0; }
.button-small { min-height: 2.25rem; padding: 0.25rem 0.75rem; font-size: 0.9rem; }
