:root {
  --purple: #4a148c;
  --purple-deep: #2d0a57;
  --purple-mid: #6a1b9a;
  --gold: #f6d36b;
  --ink: #1f1233;
  --muted: #5c4d6e;
  --line: #eadff8;
  --danger: #9b1c3c;
  --ok: #0f6b4c;
  --shadow: 0 8px 24px rgba(74, 20, 140, 0.08);
  --nav-h: 4.25rem;
  --font: "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-family: var(--font);
  color: var(--ink);
  line-height: 1.45;
}

* { box-sizing: border-box; }
html { overflow-x: hidden; }
body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(165deg, #f4e9ff 0%, #fdeefe 46%, #fff6ee 100%);
  color: var(--ink);
  overflow-x: hidden;
}
a { color: var(--purple-mid); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }

.app-header {
  background: linear-gradient(100deg, #4a148c 0%, #6a1b9a 62%, #8e24aa 100%);
  color: white;
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top, 0px);
}
.brand-row {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 0.65rem 0.9rem 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: white;
  text-decoration: none;
  min-width: 0;
  flex: 1;
}
.brand img {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: white;
  flex: none;
}
.brand-text { min-width: 0; }
.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand .gold, .brand .tag {
  margin: 0.12rem 0 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand .gold { color: var(--gold); font-size: 0.78rem; }
.brand .tag {
  display: none;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.9;
}
.header-logout { display: none; flex: none; }
.logout {
  background: none;
  border: 0;
  color: white;
  padding: 0.2rem 0;
  font-weight: 650;
  font-size: 0.9rem;
  text-decoration: underline;
  text-underline-offset: 0.15em;
  cursor: pointer;
}

.tabnav {
  display: none;
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 0 0.75rem 0.75rem;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.tabnav a {
  color: var(--purple);
  background: rgba(255, 255, 255, 0.94);
  text-decoration: none;
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  font-size: 0.84rem;
  font-weight: 650;
  min-height: 2.25rem;
  display: inline-flex;
  align-items: center;
}
.tabnav a.active { background: var(--purple-deep); color: white; }

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  background: white;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -6px 20px rgba(74, 20, 140, 0.06);
}
.bottom-nav a, .bottom-nav button {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--muted);
  text-decoration: none;
  min-height: var(--nav-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.35rem 0.1rem;
}
.bottom-nav svg { width: 1.35rem; height: 1.35rem; }
.bottom-nav .active { color: var(--purple); }

.app-main {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 0.9rem max(0.9rem, env(safe-area-inset-right, 0px)) calc(var(--nav-h) + 1.4rem + env(safe-area-inset-bottom, 0px)) max(0.9rem, env(safe-area-inset-left, 0px));
  min-width: 0;
}
.card, .tile, .split > * { min-width: 0; max-width: 100%; }
.card {
  background: white;
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 1rem;
  margin: 0 0 0.9rem;
}
h2 { margin: 0 0 0.7rem; font-size: 1.2rem; line-height: 1.25; }
h3 { margin: 0 0 0.45rem; font-size: 1.02rem; }
p { overflow-wrap: anywhere; }
.muted { color: var(--muted); font-size: 0.9rem; }
.notice, .error {
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.8rem;
  font-size: 0.92rem;
}
.notice { background: #e9f8f1; color: var(--ok); }
.error { background: #fde8ee; color: var(--danger); }

.tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
  margin-bottom: 0.9rem;
}
.tile {
  background: white;
  border-radius: 16px;
  padding: 0.85rem 0.9rem;
  box-shadow: var(--shadow);
}
.tile strong {
  display: block;
  font-size: 1.65rem;
  line-height: 1.1;
  color: var(--purple);
}
.tile span { color: var(--muted); font-size: 0.82rem; }

.filters, .stack, .roster { display: grid; gap: 0.75rem; min-width: 0; }
.filters.cols { grid-template-columns: minmax(0, 1fr); }
.field { display: grid; gap: 0.3rem; font-size: 0.92rem; font-weight: 650; min-width: 0; }
.field input, .field select, .field textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  background: white;
  font-weight: 500;
  min-height: 2.85rem;
}
.field input[type="date"],
.field input[type="time"],
.field input[type="datetime-local"] {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.field textarea { min-height: 6rem; resize: vertical; }
.btn, .btn.secondary, .btn.danger, .btn.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.85rem;
  border-radius: 12px;
  border: 0;
  padding: 0.55rem 0.9rem;
  text-decoration: none;
  font-weight: 700;
  cursor: pointer;
  max-width: 100%;
}
.btn { background: var(--purple); color: white; }
.btn.secondary { background: #efe4ff; color: var(--purple); }
.btn.danger { background: #fde8ee; color: var(--danger); }
.btn.ghost { background: transparent; color: var(--purple-mid); }
.btn.wide { width: 100%; }
.actions, .row-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; min-width: 0; }
.actions .btn { flex: 1 1 8.5rem; }
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.7rem;
  min-width: 0;
}
.page-head h2 { margin: 0; min-width: 0; }
.btn.compact, .page-head .btn {
  flex: 0 0 auto;
  width: auto;
  min-height: 2.4rem;
  padding: 0.4rem 0.8rem;
  white-space: nowrap;
}
.row-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: 100%;
  margin-top: 0.35rem;
}
.row-actions form { display: grid; min-width: 0; }
.row-actions .btn { width: 100%; padding-left: 0.35rem; padding-right: 0.35rem; }
.danger-zone {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}
.danger-zone h3 { color: var(--danger); }

.person {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 0.75rem;
  align-items: start;
  padding: 0.8rem 0;
  border-top: 1px solid var(--line);
}
.person:first-of-type { border-top: 0; }
.avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #efe4ff;
  color: var(--purple);
  display: grid;
  place-items: center;
  font-weight: 750;
  position: relative;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.avatar:has(img) .initials { visibility: hidden; }
.person .meta, .person > div { min-width: 0; display: flex; flex-direction: column; gap: 0.2rem; }
.person strong, .person em { display: block; }
.person em { font-style: normal; color: var(--muted); font-size: 0.82rem; overflow-wrap: anywhere; }

.table-wrap { width: 100%; max-width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.55rem 0.35rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.04em; text-transform: uppercase; }
.roster article {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem;
  display: grid;
  gap: 0.55rem;
  min-width: 0;
}
.check { display: flex; align-items: center; gap: 0.55rem; font-weight: 650; min-height: 2.5rem; }
.savebar { display: flex; }
.savebar .btn { width: 100%; }
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: max(1.25rem, env(safe-area-inset-top, 0px)) 1rem max(5.5rem, env(safe-area-inset-bottom, 0px));
}
.login-card { width: min(420px, 100%); }
.center { text-align: center; }
.center img {
  display: block;
  margin-left: auto;
  margin-right: auto;
}
.gold { color: #c9a227; }
.pager { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.split { display: grid; gap: 0.9rem; min-width: 0; }
.form-block {
  display: grid;
  gap: 0.7rem;
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
  min-width: 0;
}

#pwa-install[hidden] { display: none !important; }
.install-banner, #pwa-install {
  position: fixed;
  left: max(0.75rem, env(safe-area-inset-left, 0px));
  right: max(0.75rem, env(safe-area-inset-right, 0px));
  width: auto;
  box-sizing: border-box;
  transform: none;
  bottom: max(0.75rem, calc(env(safe-area-inset-bottom, 0px) + 0.75rem));
  background: var(--purple);
  color: white;
  border-radius: 16px;
  padding: 12px 12px 12px 16px;
  display: flex;
  gap: 0.6rem;
  align-items: center;
  z-index: 28;
  box-shadow: var(--shadow);
}
body:has(.bottom-nav) .install-banner,
body:has(.bottom-nav) #pwa-install {
  bottom: calc(var(--nav-h) + 0.45rem + env(safe-area-inset-bottom, 0px));
}
body.has-install-banner .app-main {
  padding-bottom: calc(6.5rem + env(safe-area-inset-bottom, 0px));
}
body.has-install-banner:has(.bottom-nav) .app-main {
  padding-bottom: calc(var(--nav-h) + 5.75rem + env(safe-area-inset-bottom, 0px));
}
.install-banner p, #pwa-install p { margin: 0; flex: 1 1 auto; min-width: 0; font-size: 0.88rem; line-height: 1.35; }
#pwa-install-icon { flex: none; width: 1.2rem; height: 1.2rem; display: none; color: #fff; }
#pwa-install.is-ios #pwa-install-icon,
#pwa-install-icon:not([hidden]) { display: block; }
.install-banner button, #pwa-install button {
  background: white;
  color: var(--purple);
  border: 0;
  border-radius: 10px;
  min-height: 40px;
  padding: 0 0.75rem;
  font-weight: 700;
  flex: none;
}
#pwa-install-dismiss {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 10px;
  background: #fff;
  color: var(--purple);
  font-size: 1.5rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
body.has-install-banner .login-wrap {
  padding-bottom: calc(7rem + env(safe-area-inset-bottom, 0px));
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(31, 18, 51, 0.45);
  z-index: 40;
  border: 0;
  padding: 0;
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  background: white;
  border-radius: 20px 20px 0 0;
  padding: 0.4rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
  max-height: min(80vh, 34rem);
  overflow: auto;
  box-shadow: var(--shadow);
}
.sheet-grab {
  width: 2.5rem;
  height: 0.28rem;
  border-radius: 99px;
  background: var(--line);
  margin: 0.35rem auto 0.7rem;
}
.sheet h2 { margin-bottom: 0.15rem; }
.sheet a, .sheet button.btn {
  display: flex;
  width: 100%;
  text-align: left;
  text-decoration: none;
  min-height: 3rem;
  align-items: center;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  font-weight: 650;
  background: transparent;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  border-radius: 0;
  padding: 0.35rem 0;
}
.sheet a.active { color: var(--purple); }
.sheet form { margin: 0; }
.sheet form button {
  display: flex;
  width: 100%;
  text-align: left;
  min-height: 3rem;
  align-items: center;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 0.35rem 0;
  background: transparent;
  color: var(--ink);
  font-weight: 650;
  cursor: pointer;
}

@media (max-width: 719px) {
  table.as-cards thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  table.as-cards, table.as-cards tbody, table.as-cards tr, table.as-cards td { display: block; width: 100%; }
  table.as-cards tr {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 0.55rem 0.75rem;
    margin: 0 0 0.65rem;
  }
  table.as-cards td {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    border: 0;
    padding: 0.28rem 0;
  }
  table.as-cards td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
    font-size: 0.78rem;
    flex: none;
  }
}

@media (min-width: 720px) {
  .brand .tag { display: block; }
  .brand h1 { font-size: 1.2rem; }
  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .filters.cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters .btn { align-self: end; }
  .split { grid-template-columns: 1fr 1fr; align-items: start; }
  .app-main { padding-bottom: 5rem; }
  .bottom-nav { display: none; }
  .tabnav { display: flex; }
  .header-logout { display: block; }
  body:has(.bottom-nav) .install-banner,
  body:has(.bottom-nav) #pwa-install { bottom: max(0.75rem, env(safe-area-inset-bottom, 0px)); }
  body.has-install-banner .app-main,
  body.has-install-banner:has(.bottom-nav) .app-main { padding-bottom: 6.5rem; }
}
@media (min-width: 1024px) {
  .filters.cols { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
