:root {
  --ink: #162c28;
  --muted: #64736e;
  --cream: #fbf8f1;
  --paper: rgba(255, 253, 248, 0.92);
  --green: #17694e;
  --green-dark: #124c3a;
  --green-pale: #e4efe8;
  --gold: #c98531;
  --gold-pale: #fff1db;
  --red: #ad453c;
  --red-pale: #faece9;
  --border: #d9e0d9;
  --shadow: 0 16px 38px rgba(20, 57, 47, 0.08);
  --radius: 18px;
  font-family: "Segoe UI", "Aptos", Arial, sans-serif;
  color: var(--ink);
  background: var(--cream);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--cream);
  -webkit-tap-highlight-color: rgba(23, 105, 78, 0.14);
}

.backdrop {
  position: fixed;
  z-index: -1;
  inset: 0;
  background:
    radial-gradient(circle at 12% 8%, rgba(201, 133, 49, 0.13), transparent 32%),
    radial-gradient(circle at 86% 12%, rgba(23, 105, 78, 0.13), transparent 35%),
    linear-gradient(135deg, #fffdf8 0%, #f4f3e9 100%);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 2.7vw, 2.3rem);
  font-weight: 600;
  letter-spacing: -0.04em;
}

h2 {
  font-size: clamp(1.45rem, 2.2vw, 1.8rem);
  letter-spacing: -0.03em;
}

h3 {
  font-size: 1.05rem;
  font-weight: 650;
}

.hidden {
  display: none !important;
}

.eyebrow {
  margin-bottom: 0.35rem;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

.gate-card {
  width: min(460px, 100%);
  display: grid;
  gap: 1.2rem;
  padding: clamp(1.5rem, 4vw, 2.4rem);
  border: 1px solid rgba(217, 224, 217, 0.8);
  border-radius: 28px;
  box-shadow: var(--shadow);
  background: var(--paper);
}

.gate-copy {
  line-height: 1.55;
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 1rem;
}

label {
  display: grid;
  gap: 0.42rem;
  color: #41524d;
  font-size: 0.88rem;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  padding: 0.68rem 0.78rem;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: white;
  color: var(--ink);
  font: inherit;
  font-weight: 400;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

textarea {
  min-height: auto;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 105, 78, 0.13);
}

button,
.upload-button {
  min-height: 44px;
  padding: 0.66rem 1rem;
  border: 1px solid transparent;
  border-radius: 11px;
  color: var(--ink);
  background: transparent;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 650;
  cursor: pointer;
  transition: transform 100ms ease, background 120ms ease, border-color 120ms ease;
}

button:active,
.upload-button:active {
  transform: translateY(1px);
}

.primary {
  color: white;
  background: var(--green);
}

.primary:hover {
  background: var(--green-dark);
}

.quiet {
  border-color: var(--border);
  background: white;
}

.quiet:hover {
  border-color: #bfcac1;
  background: #f6f8f5;
}

.danger {
  color: var(--red);
  border-color: #e5b9b5;
  background: var(--red-pale);
}

.danger:hover {
  border-color: var(--red);
}

.hint {
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 400;
  line-height: 1.45;
}

.message {
  min-height: 1.15rem;
  color: var(--red);
  font-size: 0.88rem;
}

.message.success {
  color: var(--green);
}

.app {
  width: min(1220px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.5rem 0 2.5rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.4rem;
}

.tabs {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  margin-bottom: 1.25rem;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 253, 248, 0.72);
}

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

.tab.active {
  color: white;
  background: var(--green);
}

.app-message {
  margin: 0 0 0.55rem 0.4rem;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.section-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.3rem;
}

.pill {
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  color: var(--green);
  background: var(--green-pale);
  font-size: 0.84rem;
  font-weight: 650;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1rem;
}

.stat {
  display: grid;
  gap: 0.42rem;
  min-height: 112px;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--paper);
}

.stat span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
}

.stat strong {
  font-size: clamp(1.25rem, 2vw, 1.55rem);
  font-variant-numeric: tabular-nums;
}

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

.dashboard-grid,
.work-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.work-grid {
  grid-template-columns: minmax(280px, 355px) minmax(0, 1fr);
  align-items: start;
}

.card {
  padding: 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(20, 57, 47, 0.03);
  background: var(--paper);
}

.form-card {
  position: sticky;
  top: 1rem;
}

.form-card h3,
.card > h3 {
  margin-bottom: 0.9rem;
}

.card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}

.link-button {
  min-height: 36px;
  padding: 0.35rem 0.65rem;
  color: var(--green);
  font-size: 0.84rem;
}

.link-button:hover {
  background: var(--green-pale);
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.list-column {
  min-width: 0;
}

.empty-state {
  padding: 1rem 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.schedule {
  padding: 0;
  overflow: hidden;
}

.schedule-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.1rem 0.8rem;
}

.schedule-header p {
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.schedule-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0 1.1rem 0.8rem;
}

.tag {
  padding: 0.28rem 0.56rem;
  border-radius: 999px;
  color: var(--green);
  background: var(--green-pale);
  font-size: 0.78rem;
  font-weight: 650;
}

.tag.pending {
  color: #845519;
  background: var(--gold-pale);
}

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

.schedule summary {
  padding: 0.75rem 1.1rem;
  color: var(--green);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
}

.table-wrap {
  overflow-x: auto;
  padding: 0 1.1rem 0.75rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th {
  padding: 0.55rem 0.35rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-align: left;
  text-transform: uppercase;
}

td {
  padding: 0.62rem 0.35rem;
  border-top: 1px solid #e7ece7;
  font-variant-numeric: tabular-nums;
}

td:last-child {
  text-align: right;
}

.status {
  font-size: 0.8rem;
  font-weight: 600;
}

.status.paid {
  color: var(--green);
}

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

.schedule-actions {
  display: flex;
  gap: 0.28rem;
}

.icon-action {
  min-height: 34px;
  padding: 0.3rem 0.55rem;
  border-color: var(--border);
  background: white;
  color: var(--muted);
  font-size: 0.78rem;
}

.icon-action:hover {
  color: var(--ink);
  border-color: #bfcac1;
}

.payment-check {
  width: 18px;
  min-height: 18px;
  accent-color: var(--green);
}

.month-picker {
  width: min(200px, 100%);
}

.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 0;
}

.compact .stat {
  min-height: 92px;
}

.summary-list {
  display: grid;
  gap: 0.7rem;
}

.category-row {
  display: grid;
  grid-template-columns: 100px minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.55rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.bar {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eee8;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.day-group + .day-group {
  margin-top: 1rem;
}

.day-heading {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.45rem;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 650;
}

.expense-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0;
  border-top: 1px solid #e7ece7;
}

.expense-entry strong {
  display: block;
  font-size: 0.9rem;
}

.expense-entry small {
  color: var(--muted);
}

.expense-entry .amount {
  font-size: 0.9rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.entry-actions {
  display: flex;
  gap: 0.22rem;
}

.bill-item {
  display: grid;
  gap: 0.9rem;
}

.bill-heading,
.bill-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.bill-heading p {
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.84rem;
}

.bill-heading strong {
  font-size: 1.12rem;
  font-variant-numeric: tabular-nums;
}

.bill-footer {
  padding-top: 0.8rem;
  border-top: 1px solid #e7ece7;
}

.status.pending {
  color: #845519;
}

.bill-generated {
  justify-self: end;
}

.settings-grid {
  align-items: start;
}

.settings-grid p {
  color: var(--muted);
  font-size: 0.91rem;
  line-height: 1.5;
}

.upload-button {
  display: inline-flex;
  align-items: center;
  border-color: var(--border);
  background: white;
}

.upload-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.danger-zone {
  border-color: #ecc9c5;
}

.install-steps {
  display: grid;
  gap: 0.55rem;
  margin: 0;
  padding-left: 1.25rem;
  color: var(--muted);
  font-size: 0.91rem;
  line-height: 1.45;
}

.offline-status {
  padding: 0.7rem 0.8rem;
  border-radius: 11px;
  color: #845519 !important;
  background: var(--gold-pale);
  font-size: 0.83rem !important;
  font-weight: 600;
}

.offline-status.ready {
  color: var(--green) !important;
  background: var(--green-pale);
}

@media (max-width: 860px) {
  .stats,
  .dashboard-grid,
  .work-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .form-card {
    position: static;
  }
}

@media (max-width: 540px) {
  .app {
    width: min(100% - 1rem, 1220px);
    padding-top: max(0.8rem, env(safe-area-inset-top));
    padding-bottom: calc(5.4rem + env(safe-area-inset-bottom));
  }

  .gate {
    padding-top: max(1.25rem, env(safe-area-inset-top));
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  }

  .topbar {
    margin-bottom: 1rem;
  }

  .topbar h1 {
    font-size: 1.65rem;
  }

  .tabs {
    position: fixed;
    z-index: 20;
    right: 0;
    bottom: 0;
    left: 0;
    justify-content: space-around;
    gap: 0.15rem;
    margin: 0;
    padding: 0.4rem 0.4rem calc(0.4rem + env(safe-area-inset-bottom));
    border-radius: 16px 16px 0 0;
    background: rgba(255, 253, 248, 0.98);
    box-shadow: 0 -5px 22px rgba(20, 57, 47, 0.09);
  }

  .tab {
    flex: 1;
    min-height: 48px;
    padding-right: 0.4rem;
    padding-left: 0.4rem;
    font-size: 0.72rem;
  }

  .field-row,
  .compact {
    grid-template-columns: 1fr;
  }

  .section-title {
    align-items: start;
    flex-direction: column;
  }

  .schedule-header {
    flex-direction: column;
  }

  .expenses-grid .form-card {
    order: -1;
  }

  .expense-entry {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .entry-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }

  .bill-heading,
  .bill-footer {
    align-items: start;
    flex-direction: column;
  }
}
