:root {
  --bg: #f6f0e8;
  --bg-elevated: #fffaf4;
  --surface: #ffffff;
  --ink: #2a2118;
  --ink-soft: #5c4f42;
  --muted: #8a7b6b;
  --line: #e8ddd0;
  --line-strong: #d4c4b0;
  --terracotta: #c45c26;
  --terracotta-deep: #a3481a;
  --terracotta-soft: #f3e0d4;
  --sage: #5f7a5a;
  --sage-soft: #e4eee2;
  --ochre: #c4922a;
  --ochre-soft: #f7edd4;
  --danger: #b33a2e;
  --danger-soft: #f8e4e1;
  --shadow: 0 8px 28px rgba(42, 33, 24, 0.08);
  --shadow-sm: 0 2px 10px rgba(42, 33, 24, 0.06);
  --radius: 16px;
  --radius-sm: 12px;
  --nav-h: 64px;
  --top-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg) url("joisk-asset:bg-texture") repeat;
  background-size: 280px 280px;
  min-height: 100dvh;
  line-height: 1.45;
}
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.35em; font-weight: 700; letter-spacing: -0.02em; }
p { margin: 0 0 0.75em; }
.muted { color: var(--muted); }
.hint { font-size: 0.85rem; color: var(--muted); margin: 0.25rem 0 1rem; }

.app-shell {
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom, 0px));
  max-width: 720px;
  margin: 0 auto;
  position: relative;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--top-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: rgba(246, 240, 232, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(232, 221, 208, 0.8);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 750;
  letter-spacing: -0.03em;
}
.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  object-fit: cover;
}
.brand-name { font-size: 1.15rem; }
.topbar-right { position: relative; }
.who-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 5px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  max-width: 180px;
}
.who-btn img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}
.who-btn span {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.who-btn .chev { opacity: 0.55; flex-shrink: 0; }
.who-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 50;
}
.who-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  text-align: left;
}
.who-option:hover, .who-option:focus-visible { background: var(--terracotta-soft); outline: none; }
.who-option.active { background: var(--terracotta-soft); }
.who-option img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}
.who-option .meta { display: flex; flex-direction: column; min-width: 0; }
.who-option .meta strong { font-size: 0.92rem; }
.who-option .meta span { font-size: 0.78rem; color: var(--muted); }

/* Hero */
.hero {
  position: relative;
  margin: 12px 14px 0;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 140px;
  box-shadow: var(--shadow-sm);
}
.hero-img {
  width: 100%;
  height: 160px;
  object-fit: cover;
}
.hero-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 16px 18px;
  background: linear-gradient(to top, rgba(42,33,24,0.72) 0%, rgba(42,33,24,0.15) 55%, transparent 100%);
  color: #fffaf4;
}
.hero-overlay h1 { font-size: 1.55rem; margin: 0; }
.hero-overlay p { margin: 4px 0 0; opacity: 0.92; font-size: 0.92rem; }

.main { padding: 14px 14px 0; }
.main-pad { padding-top: 18px; }
.page-head { margin-bottom: 16px; }
.page-head h1 { font-size: 1.65rem; }
.page-head p { margin: 0; }

/* Toolbar & filters */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 14px 0 12px;
  flex-wrap: wrap;
}
.week-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
  box-shadow: var(--shadow-sm);
}
.week-label {
  min-width: 118px;
  text-align: center;
  font-weight: 650;
  font-size: 0.92rem;
  padding: 0 4px;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  color: var(--ink-soft);
  transition: background 0.15s var(--ease);
}
.icon-btn:hover, .icon-btn:focus-visible { background: var(--terracotta-soft); outline: none; }

.filter-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 14px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink-soft);
  transition: all 0.15s var(--ease);
}
.chip.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fffaf4;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  border-radius: 999px;
  font-weight: 650;
  font-size: 0.92rem;
  border: 1px solid transparent;
  transition: transform 0.12s var(--ease), background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--terracotta);
  color: #fffaf4;
  box-shadow: 0 4px 14px rgba(196, 92, 38, 0.28);
}
.btn-primary:hover { background: var(--terracotta-deep); }
.btn-ghost {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink);
}
.btn-ghost:hover { background: var(--bg); }
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { filter: brightness(0.95); }
.btn-sage {
  background: var(--sage);
  color: #fff;
}
.btn-sm { padding: 8px 12px; font-size: 0.84rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

/* Week board */
.week-board { display: flex; flex-direction: column; gap: 14px; }
.day-block {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.day-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 12px 14px;
  background: linear-gradient(180deg, #fff 0%, var(--bg-elevated) 100%);
  border-bottom: 1px solid var(--line);
}
.day-head .day-name { font-weight: 750; font-size: 0.98rem; }
.day-head .day-date { color: var(--muted); font-size: 0.84rem; }
.day-head.today .day-name { color: var(--terracotta); }
.day-shifts { padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.day-empty {
  padding: 14px;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
}

/* Shift cards */
.shift-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  text-align: left;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s var(--ease);
}
button.shift-card:hover, button.shift-card:focus-visible {
  border-color: var(--terracotta);
  box-shadow: var(--shadow-sm);
  outline: none;
}
button.shift-card:active { transform: scale(0.99); }
.shift-card .status-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--bg);
}
.shift-card .info { min-width: 0; }
.shift-card .time {
  font-weight: 750;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}
.shift-card .sub {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.shift-card .people {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}
.shift-card .people img {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid var(--surface);
}
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-open { background: var(--ochre-soft); color: #8a6410; }
.badge-claimed { background: var(--sage-soft); color: var(--sage); }
.badge-mine { background: var(--terracotta-soft); color: var(--terracotta-deep); }
.badge-scheduled { background: #eee8e0; color: var(--ink-soft); }
.badge-past { background: #eee; color: #777; }

/* Lists */
.shift-list, .team-list, .admin-team-list, .admin-shift-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.list-card {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  width: 100%;
  text-align: left;
  transition: border-color 0.15s, transform 0.12s var(--ease);
}
button.list-card:hover, button.list-card:focus-visible {
  border-color: var(--terracotta);
  outline: none;
}
.list-card .avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.list-card .body { flex: 1; min-width: 0; }
.list-card .title { font-weight: 700; margin: 0 0 2px; }
.list-card .meta { font-size: 0.84rem; color: var(--muted); margin: 0; }
.list-card .aside { flex-shrink: 0; text-align: right; }
.list-card .aside .num { font-weight: 750; font-size: 1.1rem; color: var(--terracotta); }
.list-card .aside .lbl { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* Stats */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.stat-num { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.03em; color: var(--terracotta); }
.stat-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 650; }

.section-tabs {
  display: flex;
  gap: 4px;
  background: rgba(255,255,255,0.55);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 14px;
  overflow-x: auto;
}
.sec-tab {
  flex: 1 0 auto;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 650;
  color: var(--ink-soft);
}
.sec-tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* Search */
.search-wrap {
  position: relative;
  margin-bottom: 14px;
}
.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.search-wrap input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.search-wrap input:focus {
  outline: 2px solid var(--terracotta-soft);
  border-color: var(--terracotta);
}

/* Empty */
.empty-state {
  text-align: center;
  padding: 28px 18px 40px;
  color: var(--ink-soft);
}
.empty-state img {
  margin: 0 auto 14px;
  border-radius: var(--radius-sm);
  opacity: 0.95;
}
.empty-state h2 { font-size: 1.15rem; }
.empty-state p { color: var(--muted); max-width: 280px; margin: 0 auto 16px; }

/* Cards & forms */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  font-weight: 600;
}
.field span em { font-style: normal; font-weight: 500; color: var(--muted); }
.field input, .field select, .field textarea,
.settings-form input, .settings-form select,
#admin-pin {
  width: 100%;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--bg-elevated);
  font-weight: 500;
}
.field input:focus, .field select:focus, .field textarea:focus,
.settings-form input:focus, .settings-form select:focus, #admin-pin:focus {
  outline: 2px solid var(--terracotta-soft);
  border-color: var(--terracotta);
}
.field textarea { resize: vertical; min-height: 64px; }
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.check-field {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 8px 0 14px;
  font-size: 0.9rem;
  font-weight: 500;
}
.check-field input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--terracotta); }
.form-error {
  color: var(--danger);
  background: var(--danger-soft);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 600;
  margin: 0 0 10px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(42, 33, 24, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  animation: fadeIn 0.18s var(--ease);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(480px, 100%);
  max-height: min(90dvh, 720px);
  overflow: auto;
  background: var(--surface);
  border-radius: 20px 20px 16px 16px;
  box-shadow: var(--shadow);
  animation: slideUp 0.22s var(--ease);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.modal-close { font-size: 1.5rem; line-height: 1; }
.modal-body { padding: 8px 16px 4px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px 16px;
  flex-wrap: wrap;
}
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}
.detail-row:last-child { border-bottom: none; }
.detail-row .lbl { color: var(--muted); font-weight: 600; }
.detail-row .val { font-weight: 650; text-align: right; }
.person-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
}
.person-chip img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
  from { transform: translateY(18px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 100;
  background: var(--ink);
  color: #fffaf4;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  max-width: min(92vw, 400px);
  text-align: center;
  animation: fadeIn 0.18s var(--ease);
}
.toast[hidden] { display: none; }
.toast.error { background: var(--danger); }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(720px, 100%);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(255, 250, 244, 0.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  z-index: 60;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 0.68rem;
  font-weight: 650;
  color: var(--muted);
  padding-top: 6px;
}
.nav-item svg { opacity: 0.85; }
.nav-item.active { color: var(--terracotta); }
.nav-item.active svg { opacity: 1; }

/* Admin */
.gate-card { max-width: 420px; }
.gate-card h2 { margin-bottom: 6px; }
.admin-section { margin: 22px 0; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.section-head h2 { margin: 0; font-size: 1.15rem; }
.ops-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 10px;
}
.ops-item {
  background: var(--bg);
  border-radius: 12px;
  padding: 12px;
}
.ops-item .n { font-size: 1.4rem; font-weight: 800; color: var(--terracotta); }
.ops-item .l { font-size: 0.78rem; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: 0.03em; }
.admin-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.admin-row img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}
.admin-row .grow { flex: 1; min-width: 0; }
.admin-row .grow strong { display: block; font-size: 0.95rem; }
.admin-row .grow span { font-size: 0.8rem; color: var(--muted); }
.admin-row .row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--terracotta-soft);
  color: var(--terracotta-deep);
  margin-left: 6px;
  vertical-align: middle;
}
.pill.off { background: #eee; color: #888; }
.danger-zone h2 { color: var(--danger); }
.danger-card p { color: var(--ink-soft); font-size: 0.92rem; }
.settings-form .btn { margin-top: 4px; }
.admin-shift-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}
.admin-shift-item .top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.admin-shift-item .actions { display: flex; gap: 6px; justify-content: flex-end; }

/* Member detail */
.member-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 8px 0 16px;
}
.member-hero img {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--terracotta-soft);
}
.member-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 8px 0 4px;
}
.member-stats .ms {
  background: var(--bg);
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
}
.member-stats .ms .n { font-weight: 800; font-size: 1.15rem; color: var(--terracotta); }
.member-stats .ms .l { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; font-weight: 650; }

@media (min-width: 560px) {
  .hero-img { height: 200px; }
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 20px; }
  .ops-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}