/* SPDX-License-Identifier: GPL-3.0-or-later */

:root {
  --bg: #f4f6f7;
  --card: #ffffff;
  --text: #14201f;
  --muted: #5f6f6d;
  --border: #dbe3e2;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --ok: #16a34a;
  --soon: #d97706;
  --overdue: #dc2626;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;
  --banner-bg: #e0f2f1;
  --navbar-h: 56px;
  --pressed: rgba(0, 0, 0, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101615;
    --card: #1a2322;
    --text: #e4ecea;
    --muted: #93a5a2;
    --border: #2b3736;
    --accent: #14b8a6;
    --accent-text: #04211d;
    --warn-bg: #3b2f14;
    --warn-text: #fcd34d;
    --banner-bg: #14302d;
    --pressed: rgba(255, 255, 255, 0.12);
  }
}

* {
  box-sizing: border-box;
}

/* Author display values (flex etc.) would otherwise beat the UA's [hidden]
   rule — the JS toggles visibility exclusively via the hidden attribute. */
[hidden] {
  display: none !important;
}

html {
  font-family: system-ui, -apple-system, sans-serif;
}

body {
  margin: 0 auto;
  max-width: 680px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  /* viewport-fit=cover is set, so notched devices need the inset padding too. */
  padding: 0 max(12px, env(safe-area-inset-left)) env(safe-area-inset-bottom)
    max(12px, env(safe-area-inset-right));
  /* the :active pressed state below is the tap feedback */
  -webkit-tap-highlight-color: transparent;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: max(10px, env(safe-area-inset-top));
}

.app-header h1 {
  margin: 6px 0;
  font-size: 1.5rem;
}

.brand {
  color: var(--accent);
  text-decoration: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

h2 {
  font-size: 1.1rem;
  margin: 22px 0 8px;
}

a {
  color: var(--accent);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- navigation: fixed bottom bar (thumb zone) --- */

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  justify-content: center;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.tabs a {
  flex: 1 1 0;
  max-width: 170px;
  padding: 10px 12px;
  min-height: var(--navbar-h);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--muted);
  border-top: 3px solid transparent;
  white-space: nowrap;
  font-size: 0.9rem;
  touch-action: manipulation;
}

.tabs a.active {
  color: var(--accent);
  border-top-color: var(--accent);
  font-weight: 600;
}

/* Clearance for the fixed bar — sibling combinators keep c.html (no .tabs)
   unaffected. The main padding also keeps #weeks-more (IntersectionObserver
   sentinel) from sitting permanently occluded-but-intersecting under the bar. */
.tabs ~ main {
  padding-bottom: calc(var(--navbar-h) + 16px + env(safe-area-inset-bottom));
}

.tabs ~ .toast {
  bottom: calc(var(--navbar-h) + 12px + env(safe-area-inset-bottom));
}

/* --- buttons & forms --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

/* Smaller type/padding than .btn, but never a smaller touch target. */
.btn-small {
  min-height: 44px;
  padding: 6px 12px;
  font-size: 0.9rem;
}

.btn-danger {
  color: var(--overdue);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.badge {
  background: var(--accent-text);
  color: var(--accent);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.8rem;
  font-weight: 700;
}

input[type="text"],
input[type="number"],
select,
textarea {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
}

input[type="number"] {
  width: 5.5em;
}

.form-row,
.filter-row,
.share-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
}

.form-row input[type="text"] {
  flex: 1;
  min-width: 140px;
}

.file-label {
  position: relative;
}

/* --- dashboard cards --- */

.cards {
  display: grid;
  gap: 10px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 6px solid var(--muted);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.card.status-ok {
  border-left-color: var(--ok);
}

.card.status-soon {
  border-left-color: var(--soon);
}

.card.status-overdue {
  border-left-color: var(--overdue);
}

.card .area-name {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0 0 2px;
}

.card .due-line {
  margin: 0;
  font-weight: 600;
}

.status-ok .due-line {
  color: var(--ok);
}

.status-soon .due-line {
  color: var(--soon);
}

.status-overdue .due-line {
  color: var(--overdue);
}

.card .last-line {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* --- history --- */

.history {
  list-style: none;
  margin: 0;
  padding: 0;
}

.history li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}

.history .who {
  font-weight: 600;
}

.history .when {
  color: var(--muted);
  white-space: nowrap;
}

.history .multi {
  color: var(--muted);
  font-size: 0.85rem;
}

.history .deleted-area {
  color: var(--muted);
}

/* --- manage lists --- */

.manage-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.manage-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.manage-list .grow {
  flex: 1;
}

.manage-list .muted {
  font-size: 0.9rem;
}

/* --- check-in page --- */

.checkin-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  margin-top: 12px;
}

.checkin-card h2 {
  margin: 0 0 4px;
  font-size: 1.5rem;
}

.person-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.person-grid .btn.selected {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  font-weight: 700;
}

.big-confirm {
  width: 100%;
  font-size: 1.15rem;
  min-height: 54px;
  margin-top: 10px;
}

.result-check {
  font-size: 2.2rem;
  color: var(--ok);
  margin: 0;
}

.undo-bar {
  position: relative;
  overflow: hidden;
}

/* --- weeks (KW duty plan) --- */

.weeks-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.week-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}

.week-row.week-current {
  border-left: 6px solid var(--accent);
}

.week-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.week-kw {
  font-weight: 700;
}

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

.week-summary {
  flex-basis: 100%;
  font-size: 0.9rem;
}

.week-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

/* Documented touch-target exception: 7 columns in a 320px viewport leave
   ~40px of WIDTH per cell (7 x 44 = 308 > 296 content px) — a 44px-wide
   calendar cell is geometrically impossible here, so the height compensates. */
.day-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: 56px;
  padding: 4px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
  touch-action: manipulation;
}

/* View mode disables cells but must keep full contrast — it is information,
   not a greyed-out control. */
.day-cell:disabled {
  cursor: default;
  opacity: 1;
}

.day-cell .day-dow {
  color: var(--muted);
  font-size: 0.7rem;
}

.day-cell .day-num {
  font-weight: 600;
}

.day-cell .day-mark {
  font-size: 0.75rem;
  min-height: 1em;
}

.state-planned {
  border-color: var(--accent);
  outline: 1px solid var(--accent);
}

.state-partial {
  border-color: var(--soon);
  outline: 1px solid var(--soon);
}

.state-partial .day-mark {
  color: var(--soon);
  font-weight: 700;
}

.state-done {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.state-done .day-dow {
  color: var(--accent-text);
  opacity: 0.8;
}

.state-extra .day-mark {
  color: var(--muted);
}

.day-editor {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.day-editor-title {
  margin: 0 0 6px;
  font-weight: 600;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.chip {
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}

.chip.selected {
  border-color: var(--accent);
  outline: 1px solid var(--accent);
  font-weight: 600;
}

/* one row per slot in the day editor: area label + person chips */
.slot-row {
  display: grid;
  gap: 4px;
  margin-top: 10px;
}

.slot-row-label {
  font-weight: 600;
  font-size: 0.9rem;
}

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

.day-editor:focus {
  outline: none;
}

.day-editor-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.weeks-more {
  width: 100%;
  margin-top: 10px;
}

.week-card {
  display: block;
  cursor: pointer;
}

.week-card-head {
  margin: 0 0 4px;
}

.week-card-tasks {
  list-style: none;
  margin: 4px 0;
  padding: 0;
}

.week-card-tasks li {
  padding: 1px 0;
}

.week-card .week-strip {
  margin-top: 8px;
  pointer-events: none;
}

/* --- misc --- */

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  background: var(--banner-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  margin: 10px 0;
}

.warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-radius: 10px;
  padding: 8px 12px;
}

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

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 30px 10px;
}

.honesty-note {
  margin: 26px 0 14px;
  padding: 12px 14px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.share-fallback {
  width: 100%;
  font-family: ui-monospace, "SF Mono", Monaco, monospace;
  font-size: 0.8rem;
}

.qr-wrap {
  text-align: center;
  margin: 14px 0;
}

.qr-wrap canvas {
  max-width: min(360px, 100%);
  height: auto;
  background: #fff;
  border-radius: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 9999;
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(20, 20, 20, 0.92);
  color: #fff;
  font-size: 0.95rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  display: flex;
  gap: 12px;
  align-items: center;
  max-width: 90vw;
}

.toast .btn {
  min-height: 44px;
  padding: 4px 14px;
}

/* --- QR sheet (screen preview; print layout lives in print.css) --- */

.qr-sheet {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.qr-tile {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
  background: var(--card);
}

.qr-tile canvas {
  width: 40mm;
  height: 40mm;
  image-rendering: pixelated;
  background: #fff;
}

.qr-tile .tile-area {
  font-weight: 700;
  margin: 6px 0 0;
}

.qr-tile .tile-plan {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0;
}

/* --- pressed states: the tap feedback (tap-highlight is disabled on body).
   An inset overlay instead of transform — no layout shift, works on top of
   .btn-primary's accent fill. --- */

.btn:active:not(:disabled),
.chip:active,
.day-cell:active:not(:disabled),
.tabs a:active,
.week-card:active {
  box-shadow: inset 0 0 0 999px var(--pressed);
}

@media (max-width: 640px) {
  .form-row .btn,
  .share-actions .btn {
    flex: 1 1 auto;
  }
}
