:root {
  --bg: #f5f5f4;
  --card: #ffffff;
  --text: #1c1917;
  --muted: #57534e;
  --border: #d6d3d1;
  --accent: #1d4ed8;
  --accent-text: #ffffff;
  --bad: #b91c1c;
  --ok: #15803d;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --warn-text: #78350f;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Built-in controls (radio buttons, scrollbars, pickers) follow light/dark too. */
  color-scheme: light;
  accent-color: var(--accent);
}

/* Dark mode. data-theme is set on <html> by the script at the top of
   index.html: the phone's setting ("Auto"), or Light/Dark picked in the app. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1c1917;
  --card: #292524;
  --text: #f5f5f4;
  --muted: #a8a29e;
  --border: #44403c;
  --accent: #3b82f6;
  --bad: #f87171;
  --ok: #16a34a;
  --warn: #f59e0b;
  --warn-bg: #422006;
  --warn-text: #fde68a;
}

* {
  box-sizing: border-box;
}

/* Browsers don't pass the page font into buttons and form fields by default. */
button,
input,
select,
textarea {
  font-family: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 1.0625rem;
}

.shell {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px;
}

h1 {
  margin: 0;
  font-size: 1.75rem;
}

.muted {
  color: var(--muted);
}

/* SEL logo at the top of every screen (navy; drawn white in dark mode). */
.brand {
  margin-bottom: 20px;
}

.brand-logo {
  display: block;
  width: 200px;
  max-width: 60%;
  height: auto;
  margin: 0 auto; /* centered */
}

:root[data-theme="dark"] .brand-logo {
  filter: brightness(0) invert(1);
}

/* Read by screen readers, not shown. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.card p {
  margin: 0;
}

label {
  font-weight: 600;
}

input {
  width: 100%;
  padding: 14px 12px;
  font-size: 1.25rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

#code {
  letter-spacing: 0.3em;
  text-align: center;
}

button {
  min-height: 52px;
  padding: 12px 16px;
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  border: none;
  border-radius: 8px;
}

button:disabled {
  opacity: 0.6;
}

button.secondary {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
}

button.link {
  min-height: 44px;
  padding: 8px 0;
  color: var(--accent);
  background: none;
  font-weight: 500;
}

.links {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.error {
  color: var(--bad);
}

.error:empty {
  display: none;
}

/* Users screen */
h2 {
  margin: 0;
  font-size: 1.25rem;
}

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.small {
  font-size: 0.9rem;
}

.user.inactive {
  opacity: 0.6;
}

.user-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  padding: 2px 8px;
  font-size: 0.8rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.tag.warn {
  color: var(--bad);
  border-color: var(--bad);
}

/* Role / Company / Classification stacked: the app is at most 480px wide, too
   narrow for three dropdowns side by side ("Classification" ran over the card). */
.fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

select {
  width: 100%;
  max-width: 100%;
  min-height: 44px;
  padding: 8px;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.status:empty {
  display: none;
}

/* Clock screen */
#home {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#home > p {
  margin: 0;
}

.status-card .status-title {
  font-size: 1.35rem;
  font-weight: 700;
}

.status-card.in {
  border-left: 6px solid var(--ok);
}

.status-card.lunch {
  border-left: 6px solid var(--warn);
}

.status-card.out {
  border-left: 6px solid var(--border);
}

.badge {
  padding: 8px 12px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--warn-text);
  background: var(--warn-bg);
  border-radius: 8px;
}

.warn-box {
  padding: 10px 12px;
  color: var(--bad);
  border: 1px solid var(--bad);
  border-radius: 8px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.actions:empty {
  display: none;
}

.actions button:only-child {
  grid-column: 1 / -1;
}

button.danger {
  background: var(--bad);
}

#phase-heading {
  margin-top: 8px;
}

.phase-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

button.phase {
  justify-content: flex-start;
  text-align: left;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
}

button.phase.current {
  color: var(--accent-text);
  background: var(--ok);
  border-color: var(--ok);
  opacity: 1;
}

.footer-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

/* "Signed in as …" and Sign out, bottom right */
.account {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0;
  margin-top: 8px;
  text-align: right;
}

.account p {
  margin: 0;
}

/* Daily log */
textarea {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
}

#log-form label,
#log-form legend {
  font-weight: 600;
}

fieldset.yesno {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 0;
  padding: 0;
  border: none;
}

fieldset.yesno legend {
  width: 100%;
  margin-bottom: 6px;
}

fieldset.yesno label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-weight: 500;
}

fieldset.yesno input {
  width: 22px;
  height: 22px;
}

.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.thumbs:empty {
  display: none;
}

.thumb {
  position: relative;
}

.thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
}

button.thumb-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  min-height: 32px;
  width: 32px;
  padding: 0;
  font-size: 1.2rem;
  line-height: 1;
  color: #fff;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 50%;
}

/* Flags */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

button.tab {
  min-height: 44px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
}

button.tab.active {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

.flag {
  border-left: 6px solid var(--warn);
}

.flag.flag-open_punch {
  border-left-color: var(--bad);
}

/* Hours dashboard. Series colors validated (dataviz palette slots 1-2, light and dark). */
:root {
  --series-rd: #2a78d6; /* RD Electric */
  --series-wc: #eb6834; /* Well Connected */
  --series-other: #8a8984;
  --status-critical: #d03b3b;
  --status-warning: #fab219;
  --track: #e7e5e4;
}

:root[data-theme="dark"] {
  --series-rd: #3987e5;
  --series-wc: #d95926;
  --series-other: #75746f;
  --track: #3a3633;
}

h3 {
  margin: 0;
  font-size: 1.05rem;
}

.push-right {
  margin-left: auto;
}

.dash-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hero {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.1;
}

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.kv {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
}

/* Legend: swatch + name + value (identity is never color alone) */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 0.9rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.swatch.rd,
.seg.rd {
  background: var(--series-rd);
}

.swatch.wc,
.seg.wc {
  background: var(--series-wc);
}

.seg.other {
  background: var(--series-other);
}

/* Status tags: icon + words; the color only reinforces */
.status-tag {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  border: 1.5px solid;
  border-radius: 999px;
}

.status-tag.over {
  border-color: var(--status-critical);
}

.status-tag.over .status-icon {
  color: var(--status-critical);
}

.status-tag.ahead {
  border-color: var(--status-warning);
}

.status-tag.ahead .status-icon {
  color: var(--status-warning);
}

/* Burn bar: thin, rounded ends, a line where the schedule says we should be */
.burn-track {
  position: relative;
  height: 10px;
  background: var(--track);
  border-radius: 5px;
}

.burn-fill {
  height: 100%;
  min-width: 0;
  background: var(--series-rd);
  border-radius: 5px;
}

.burn-fill.over {
  background: var(--status-critical);
}

.burn-expected {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  margin-left: -1px;
  background: var(--text);
  border-radius: 1px;
}

.ja {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 16px;
  font-size: 0.9rem;
}

/* Weekly stacked bars (RD bottom, WC on top), 2px surface gap between segments */
.week-chart {
  position: relative;
  padding-top: 18px;
}

.week-max {
  position: absolute;
  top: 0;
  left: 0;
}

.week-bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 150px;
  margin-bottom: 24px; /* room for the week labels */
  border-bottom: 1px solid var(--border);
}

button.week-col {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: flex-end;
  align-items: stretch;
  height: 100%;
  min-height: 0;
  padding: 0 1px;
  background: transparent;
  border-radius: 4px 4px 0 0;
  position: relative;
}

button.week-col.selected {
  background: var(--track);
}

.week-stack {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  overflow: hidden;
  border-radius: 4px 4px 0 0;
}

.seg {
  min-height: 2px;
}

.week-label {
  position: absolute;
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  white-space: nowrap;
}

.week-detail {
  margin-top: 4px;
  font-size: 0.9rem;
}

.data-table {
  width: 100%;
  margin-top: 8px;
  border-collapse: collapse;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
  padding: 4px 6px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

.data-table th:first-child,
.data-table td:first-child {
  text-align: left;
}

/* By person */
.person-row {
  display: grid;
  grid-template-columns: 1fr 80px 80px;
  gap: 8px;
  padding: 8px 0;
}

details.person {
  border-top: 1px solid var(--border);
}

details.person summary {
  cursor: pointer;
  list-style: none;
}

details.person .kv {
  padding-left: 12px;
}

summary {
  cursor: pointer;
}

/* Auto / Light / Dark switch */
.theme-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  margin: 0;
  padding: 0;
  border: none;
}

.theme-switch legend {
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

.theme-switch button {
  min-height: 44px;
  font-weight: 500;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0;
}

.theme-switch button:first-of-type {
  border-radius: 8px 0 0 8px;
}

.theme-switch button:last-of-type {
  border-radius: 0 8px 8px 0;
}

.theme-switch button + button {
  border-left: none;
}

.theme-switch button[aria-pressed="true"] {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

/* Admin screen */
#admin {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#admin > p {
  margin: 0;
}

.admin-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}

details.admin-panel > summary {
  font-size: 1.05rem;
  font-weight: 700;
  min-height: 32px;
}

details.admin-panel[open] > summary {
  margin-bottom: 4px;
}

.on-clock {
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}

.on-clock:last-child {
  border-bottom: none;
}

/* Phase switches */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.switch-row:last-child {
  border-bottom: none;
}

.switch-row button.link {
  min-height: 32px;
  padding: 4px 0;
}

.switch {
  position: relative;
  flex: none;
  width: 52px;
  height: 30px;
}

.switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}

.switch .slider {
  position: absolute;
  inset: 0;
  background: var(--track);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.15s;
}

.switch .slider::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}

.switch input:checked + .slider {
  background: var(--ok);
  border-color: var(--ok);
}

.switch input:checked + .slider::after {
  transform: translateX(22px);
}

.switch input:disabled + .slider {
  opacity: 0.4;
}

.switch input:focus-visible + .slider {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Fix punches */
.fix-pick {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

input[type="date"],
input[type="datetime-local"] {
  font-size: 1rem;
  padding: 10px;
  min-height: 44px;
}

.punch-card {
  gap: 10px;
  background: var(--bg);
}

.add-card > summary {
  font-weight: 600;
}

.add-card[open] {
  display: flex;
}

.refresh-buttons {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.refresh-buttons button {
  min-height: 44px;
  font-size: 0.9rem;
}

.punch-card[open] {
  display: flex;
}

.punch-summary {
  line-height: 1.4;
}

/* Delete / Clock out: a solid dark red in both modes (white text stays readable). */
button.danger {
  background: #b91c1c;
}

.punch-card:not([open]) {
  padding-top: 12px;
  padding-bottom: 12px;
}

/* Gear & CED tracker */
#gear > p {
  margin: 0 0 8px;
}

#gear-add {
  width: 100%;
}

.card.gear {
  gap: 8px;
}

.card.gear.delivered {
  opacity: 0.75;
}

.tag.gear-status.ordered,
.tag.gear-status.shipped {
  color: var(--text);
}

.tag.gear-status.delivered {
  color: var(--ok);
  border-color: var(--ok);
}

.gear-notes {
  white-space: pre-wrap;
  color: var(--muted);
}

.gear-files {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.gear-files a {
  color: var(--accent);
  overflow-wrap: anywhere;
}

.gear-files button.link {
  min-height: 36px;
  padding: 4px 0;
}

/* Mark received: the date on its own line, then Save / Cancel */
.gear .actions label.field {
  grid-column: 1 / -1;
}

.gear-form .hint,
.gear-settings .hint {
  font-weight: 400;
}

.gear-form input[type="text"],
.gear-form input[type="number"],
.gear-settings input[type="number"] {
  font-size: 1rem;
  padding: 10px;
  min-height: 44px;
}

button.danger-link {
  align-self: flex-start;
  color: var(--bad);
}

/* 30-day look-ahead */
.la-range {
  font-weight: 400;
}

.card.la-week {
  gap: 0;
  padding-top: 8px;
  padding-bottom: 8px;
}

.la-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.la-row:last-child {
  border-bottom: none;
}

.la-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.la-track {
  height: 6px;
  margin-top: 2px;
}

.la-track .burn-fill {
  background: var(--accent);
}

.la-gear {
  cursor: pointer;
}

.la-row button.link {
  align-self: flex-start;
  min-height: 36px;
  padding: 4px 0;
}

.la-progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.la-progress input[type="range"] {
  padding: 0;
  min-height: 36px;
  background: none;
  border: none;
}

/* Message feed */
#messages-composer {
  margin-bottom: 4px;
}

.composer {
  gap: 8px;
}

.composer p {
  margin: 0;
}

.reply-composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.tag-picker {
  display: flex;
  flex-direction: column;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.tag-picker[hidden] {
  display: none;
}

label.check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  font-weight: 500;
}

label.check input {
  width: 20px;
  height: 20px;
  padding: 0;
}

.card.thread {
  gap: 10px;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg.reply {
  margin-left: 4px;
  padding-left: 12px;
  border-left: 3px solid var(--border);
}

.msg-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.msg-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.msg-files a {
  color: var(--accent);
}

.msg-files img {
  display: block;
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 6px;
}

.thread button.link {
  align-self: flex-start;
  min-height: 36px;
  padding: 4px 0;
}

button.older {
  width: 100%;
  margin-top: 12px;
}
