:root {
  --bg: #f3efe6;
  --paper: #fffdf8;
  --ink: #1d2a24;
  --muted: #5e6d66;
  --line: #ddd4c4;
  --primary: #1f4d3a;
  --primary-soft: #e4efe8;
  --accent: #c45c26;
  --present: #2d7a4f;
  --present-bg: #e4f3ea;
  --absent: #b42318;
  --absent-bg: #fdecea;
  --sunday: #fbeaea;
  --shadow: 0 10px 28px rgba(31, 44, 36, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Noto Sans", sans-serif;
}

body {
  padding: 16px 16px 32px;
}

a {
  color: inherit;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app {
  max-width: 520px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.3;
}

.back,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 14px;
  background: var(--paper);
  color: var(--primary);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.card {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.hero {
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: 1.8rem;
}

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

.stack {
  display: grid;
  gap: 12px;
}

.home-grid {
  display: grid;
  gap: 12px;
}

.home-tile {
  display: block;
  padding: 22px 18px;
  border-radius: 22px;
  background: var(--paper);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.home-tile strong {
  display: block;
  font-size: 1.2rem;
  margin-bottom: 6px;
}

.home-tile.students {
  border-left: 6px solid var(--present);
}

.home-tile.teachers {
  border-left: 6px solid var(--accent);
}

.home-tile.roster {
  border-left: 6px solid var(--primary);
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
}

.btn {
  width: 100%;
  min-height: 50px;
  border: 0;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.btn:disabled {
  opacity: 0.6;
}

.btn.secondary {
  background: var(--primary-soft);
  color: var(--primary);
}

.btn.danger {
  background: var(--absent-bg);
  color: var(--absent);
}

.btn.ghost {
  background: transparent;
  color: var(--primary);
  box-shadow: none;
}

.error {
  color: var(--absent);
  margin: 0;
}

.date-nav {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.date-nav .date-label {
  position: relative;
  display: block;
  color: var(--ink);
  font-size: 1rem;
  text-align: center;
  padding: 10px 8px;
  border-radius: 14px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.date-nav .date-label.sunday {
  background: var(--sunday);
}

.date-nav .date-label strong {
  display: block;
  font-size: 1.05rem;
}

.date-nav .date-label span {
  color: var(--muted);
  font-size: 0.85rem;
}

.date-nav.compact {
  grid-template-columns: 38px 1fr 38px;
  gap: 6px;
  margin-bottom: 8px;
}

.date-nav.compact .icon-btn {
  min-width: 38px;
  min-height: 36px;
  padding: 0;
  border-radius: 10px;
  font-size: 1.4rem;
  line-height: 1;
}

.date-nav.compact .date-label {
  padding: 7px 8px;
  border-radius: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.date-nav.compact .date-label strong,
.date-nav.compact .date-label span {
  display: inline;
  font-size: 0.9rem;
}

.date-nav.compact .date-label span::before {
  content: " · ";
}

.date-picker {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  opacity: 0;
}

.class-row,
.month-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 12px;
}

.person {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 16px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.person header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.person h2 {
  margin: 0;
  font-size: 1.05rem;
}

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.choices.three {
  grid-template-columns: repeat(3, 1fr);
}

.choices.four {
  grid-template-columns: repeat(4, 1fr);
}

.compact-list {
  background: var(--paper);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.compact-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 10px;
  border-left: 4px solid transparent;
}

.compact-row + .compact-row {
  border-top: 1px solid var(--line);
}

.compact-row.marked {
  border-left-color: var(--present);
}

.compact-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.compact-name small {
  display: inline-block;
  min-width: 1.6em;
  color: var(--muted);
  font-weight: 400;
}

.compact-choices {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.compact-choices .choice {
  min-width: 42px;
  min-height: 38px;
  padding: 0 6px;
  border-radius: 10px;
  font-size: 0.85rem;
}

.compact-row.stacked {
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding-top: 8px;
  padding-bottom: 8px;
}

.compact-choices.split {
  gap: 10px;
}

.compact-choices.split .group {
  display: flex;
  flex: 1;
  gap: 4px;
}

.compact-choices.split .group.work {
  flex: 0 0 auto;
  padding-right: 10px;
  border-right: 1px solid var(--line);
}

.compact-choices.split .group .choice {
  flex: 1;
}

.compact-row.absent {
  border-left-color: var(--absent);
}

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

.summary-row .summary {
  flex: 1;
  min-width: 0;
  margin: 0;
  gap: 4px 12px;
}

.lock-btn {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 32px;
  padding: 0;
  border: 1px solid #e0a54b;
  border-radius: 10px;
  background: #fff4e5;
  color: #b26a00;
}

.lock-btn.unlocked {
  border-color: var(--absent);
  background: #fdecea;
  color: var(--absent);
}

.is-locked #list .choice,
.is-locked #list .absent-reason,
.is-locked #actions .btn {
  opacity: 0.45;
}

.compact-info {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.compact-info .compact-name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  white-space: normal;
  line-height: 1.25;
  font-size: 0.92rem;
  padding-left: 18px;
  text-indent: -18px;
}

.compact-info .compact-name small {
  min-width: 18px;
  text-indent: 0;
}

.compact-info .absent-reason {
  padding-left: 18px;
}

.compact-choices.tight .choice.more {
  min-width: 30px;
  padding: 0 2px;
}

.compact-choices.tight {
  gap: 3px;
}

.compact-choices.tight .choice {
  min-width: 37px;
  min-height: 34px;
  padding: 0 3px;
  font-size: 0.92rem;
  font-weight: 400;
}

.compact-choices .choice.absent {
  margin-left: 3px;
  color: var(--absent);
}

.compact-choices .choice.absent.active {
  color: #fff;
}

.absent-reason {
  align-self: flex-start;
  max-width: 100%;
  margin: 0;
  padding: 0 0 0 1.6em;
  border: 0;
  background: none;
  color: var(--absent);
  font-size: 0.78rem;
  line-height: 1.3;
  text-align: left;
  text-decoration: underline dotted;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.absent-text,
.summary .absent-text,
.totals .absent-text {
  color: var(--absent);
}

.absence-list {
  margin: 10px 0 0;
  padding-left: 18px;
  font-size: 0.85rem;
  color: var(--absent);
}

.absence-list strong {
  font-weight: 600;
}

.choice-label {
  margin: 2px 0 -4px;
  font-size: 0.8rem;
  color: var(--muted);
}

.choice.active.work {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.choice.active.hours {
  background: var(--present);
  border-color: var(--present);
  color: #fff;
}

.bulk-title {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.sticky-actions.card {
  padding: 12px;
}

.choice {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
}

.choice.active.present {
  background: var(--present);
  border-color: var(--present);
  color: #fff;
}

.choice.active.absent,
.choice.active.zero {
  background: var(--absent);
  border-color: var(--absent);
  color: #fff;
}

.choice.active.half,
.choice.active.one,
.choice.active.two {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.list-item {
  display: grid;
  gap: 8px;
  padding: 14px;
  border-radius: 16px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.list-item.inactive {
  opacity: 0.62;
}

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

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.tab {
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  background: var(--paper);
  color: var(--muted);
}

.tab.active {
  background: var(--primary);
  color: #fff;
}

.hidden {
  display: none !important;
}

.section-title {
  margin: 20px 0 8px;
  font-size: 1rem;
  color: var(--muted);
}

.topbar + .section-title {
  margin-top: 0;
}

.month-card {
  cursor: pointer;
}

.month-card .totals {
  display: flex;
  gap: 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.day-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-top: 10px;
}

.day-cell {
  min-height: 42px;
  border-radius: 10px;
  background: #f7f3ea;
  text-align: center;
  padding: 6px 2px;
  font-size: 0.75rem;
}

.day-head {
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
}

.day-cell.sun {
  background: var(--sunday);
}

.day-cell .mark {
  display: block;
  margin-top: 2px;
  font-weight: 700;
}

.day-cell .sub {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
}

.sheet td.day .sub {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--accent);
}

.day-cell.present .mark {
  color: var(--present);
}

.day-cell.absent .mark {
  color: var(--absent);
}

.day-cell.present.filled {
  background: var(--present);
  color: #fff;
}

.day-cell.absent.filled {
  background: var(--absent);
  color: #fff;
}

.day-cell.filled .mark {
  color: #fff;
}

.empty {
  padding: 24px 8px;
  text-align: center;
  color: var(--muted);
}

.footer-link {
  display: block;
  text-align: center;
  margin-top: 16px;
  color: var(--primary);
  font-weight: 700;
}

.hint {
  font-size: 0.88rem;
  color: var(--muted);
}

.item-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.item-head strong {
  flex: 1;
  font-size: 1.05rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 10;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.summary strong {
  color: var(--ink);
}

.sticky-actions {
  position: sticky;
  bottom: calc(12px + env(safe-area-inset-bottom));
  margin-top: 14px;
}

.person .total {
  font-weight: 700;
  color: var(--primary);
}

.day-cell.unmarked .mark {
  color: var(--line);
}

.app.wide {
  max-width: 1400px;
}

.app.wide > .topbar,
.app.wide > .tabs,
.app.wide > .class-row,
.app.wide > .date-nav,
.app.wide > .hint {
  max-width: 520px;
}

.tabs.two {
  grid-template-columns: repeat(2, 1fr);
}

.sheet-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 14px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.sheet-wrap > .summary {
  margin: 0;
  padding: 10px 12px;
}

.sheet {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
  min-width: 100%;
}

.sheet th,
.sheet td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 6px 4px;
  text-align: center;
  white-space: nowrap;
  background: var(--paper);
}

.sheet thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
}

.sheet th.day small {
  display: block;
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--muted);
}

.sheet .day {
  min-width: 30px;
}

.sheet th.day.sun,
.sheet td.day.sun {
  background: var(--sunday);
}

.sheet td.day.on {
  background: var(--present-bg);
  color: var(--present);
  font-weight: 700;
}

.sheet td.day.off {
  background: var(--absent-bg);
  color: var(--absent);
  font-weight: 700;
}

.sheet .stt,
.sheet .name {
  position: sticky;
  z-index: 1;
}

.sheet .stt {
  left: 0;
  width: 34px;
  min-width: 34px;
  color: var(--muted);
}

.sheet .name {
  left: 34px;
  max-width: 130px;
  min-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  font-weight: 600;
  box-shadow: 2px 0 0 var(--line);
}

.sheet thead .stt,
.sheet thead .name {
  z-index: 3;
}

.sheet .total {
  min-width: 48px;
  font-weight: 700;
  color: var(--primary);
}

.sheet tr.inactive th,
.sheet tr.inactive td {
  color: var(--muted);
}

.print-btn {
  font-size: 0.9rem;
  font-weight: 700;
}

.print-title {
  display: none;
}

@media print {
  @page {
    size: A4 landscape;
    margin: 8mm;
  }

  html,
  body {
    background: #fff !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .app.wide {
    max-width: none;
  }

  .topbar,
  .tabs,
  .class-row,
  .date-nav,
  #legend,
  .toast {
    display: none !important;
  }

  .print-title {
    display: block;
    margin: 0 0 6px;
    font-size: 13pt;
    text-align: center;
    text-transform: uppercase;
    color: #000;
  }

  .sheet-wrap {
    overflow: visible;
    border-radius: 0;
    box-shadow: none;
  }

  .sheet {
    width: 100%;
    font-size: 7pt;
    border-top: 1px solid #999;
    border-left: 1px solid #999;
  }

  .sheet th,
  .sheet td {
    padding: 2px 1px;
    border-color: #999;
  }

  .sheet thead th,
  .sheet .stt,
  .sheet .name {
    position: static;
  }

  .sheet .day {
    min-width: 0;
  }

  .sheet .name {
    max-width: none;
    min-width: 0;
    white-space: normal;
    box-shadow: none;
  }

  .sheet .total {
    min-width: 0;
    white-space: normal;
  }

  .sheet tr {
    break-inside: avoid;
  }

  .sheet thead {
    display: table-header-group;
  }

  .sheet-wrap > .summary {
    padding: 6px 0 0;
    font-size: 9pt;
  }
}

.badge.combo {
  background: #fdf0e6;
  color: var(--accent);
}

.rate-line {
  margin: 0;
}

.finance-totals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.finance-total {
  display: grid;
  gap: 2px;
  padding: 10px;
  border-radius: 14px;
  background: var(--paper);
  box-shadow: var(--shadow);
  font-size: 0.8rem;
  color: var(--muted);
}

.finance-total strong {
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.finance-total.income strong {
  color: var(--present);
}

.finance-total.expense strong {
  color: var(--absent);
}

.finance-total.balance strong {
  color: var(--primary);
}

.finance-total.balance.negative strong {
  color: var(--absent);
}

.pay-detail {
  padding-left: 18px;
  font-size: 0.8rem;
  color: var(--muted);
}

.compact-info .compact-name .inline-sub {
  min-width: 0;
  margin-left: 6px;
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--muted);
}

.pay-row .compact-name,
.pay-row .pay-detail {
  padding-left: 4px;
  text-indent: 0;
}

.pay-btn {
  flex-shrink: 0;
  min-width: 72px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--primary);
  border-radius: 10px;
  background: #fff;
  color: var(--primary);
  font-weight: 600;
}

.pay-btn.paid {
  border-color: var(--present);
  background: var(--present);
  color: #fff;
}

.entry-amount {
  flex-shrink: 0;
  font-size: 0.92rem;
  white-space: nowrap;
}

.entry-row.income .entry-amount {
  color: var(--present);
}

.entry-row.expense .entry-amount {
  color: var(--absent);
}

.entry-row.income {
  border-left-color: var(--present);
}

.entry-row.expense {
  border-left-color: var(--absent);
}

.entry-delete {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
}

.choice.active.income {
  background: var(--present);
  border-color: var(--present);
  color: #fff;
}

.choice.active.expense {
  background: var(--absent);
  border-color: var(--absent);
  color: #fff;
}

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

.form-row input {
  min-width: 0;
  width: 100%;
}

.rate-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.rate-row .btn {
  width: auto;
  min-height: 36px;
  padding: 0 14px;
}

.warn {
  color: var(--accent);
  font-size: 0.85rem;
}

.money {
  font-weight: 700;
  color: var(--ink);
}

.home-tile.sheet-tile {
  border-left: 6px solid var(--muted);
}

.install-card {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  border-left: 6px solid var(--primary);
}

.install-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.install-card .hint {
  margin: 0;
}

.install-steps {
  margin: 0;
  padding-left: 20px;
  font-size: 0.92rem;
  line-height: 1.5;
}

.install-close {
  width: 32px;
  height: 32px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.3rem;
}

.home-tile.finance-tile {
  border-left: 6px solid #b26a00;
}

.home-tile.gold-tile {
  border-left: 6px solid #c9a227;
}

.gold-updated {
  margin: -4px 0 12px;
  font-size: 0.9rem;
}

.gold-prices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.gold-card {
  display: grid;
  gap: 6px;
  padding: 16px 14px;
  border-radius: 16px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.gold-card span {
  color: var(--muted);
  font-size: 0.9rem;
}

.gold-card strong {
  font-size: 1.6rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.gold-card.buy strong {
  color: var(--present);
}

.gold-card.sell strong {
  color: var(--accent);
}

.gold-prices + .error {
  margin-bottom: 12px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.75rem;
}
