:root {
  --bg: #f7faf8;
  --surface: #ffffff;
  --surface-soft: #eef7f3;
  --text: #24312e;
  --muted: #6c7b77;
  --line: #dce7e2;
  --green: #8ec5b6;
  --green-dark: #477f72;
  --rose: #f2b8b5;
  --amber: #f4cf88;
  --blue: #9db8df;
  --danger: #c85f65;
  --shadow: 0 16px 40px rgba(47, 74, 68, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #f7faf8 0%, #edf6f1 100%);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.auth-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: max(22px, env(safe-area-inset-top)) 16px max(22px, env(safe-area-inset-bottom));
}

.auth-screen.is-hidden,
.app-shell.is-locked,
.admin-only.is-hidden {
  display: none;
}

.auth-panel {
  display: grid;
  gap: 16px;
  width: 100%;
  max-width: 430px;
  padding: 22px;
  border: 1px solid rgba(220, 231, 226, 0.82);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.auth-copy,
.panel-copy {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

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

.auth-tab {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 850;
}

.auth-tab.is-active {
  background: var(--surface-soft);
  color: var(--green-dark);
}

.auth-form {
  display: none;
  gap: 13px;
}

.auth-form.is-active {
  display: grid;
}

.status-message {
  min-height: 20px;
  margin: 0;
  color: var(--green-dark);
  font-size: 0.9rem;
  font-weight: 800;
}

.app-shell {
  width: 100%;
  max-width: 720px;
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(92px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 2px 18px;
}

.top-actions {
  display: grid;
  grid-template-columns: auto auto;
  align-items: end;
  gap: 8px;
}

.top-actions .year-filter {
  grid-column: 1 / -1;
}

.user-chip {
  align-self: center;
  max-width: 155px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.55rem, 8vw, 2.25rem);
  line-height: 1.05;
}

h2 {
  font-size: 1.12rem;
}

.year-filter {
  display: grid;
  gap: 6px;
  min-width: 104px;
}

.year-filter label,
label span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

select,
input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

input[type="checkbox"] {
  width: auto;
  min-height: auto;
  accent-color: var(--green-dark);
}

select:focus,
input:focus {
  border-color: var(--green-dark);
  box-shadow: 0 0 0 3px rgba(142, 197, 182, 0.28);
}

.view {
  display: none;
  animation: rise 180ms ease;
}

.view.is-active {
  display: grid;
  gap: 16px;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hero-panel,
.chart-panel,
.form-panel,
.table-panel {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(220, 231, 226, 0.82);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.hero-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px;
  background: linear-gradient(135deg, #ffffff 0%, #eef7f3 48%, #fff7e4 100%);
}

.hero-panel h2 {
  font-size: 1.9rem;
  line-height: 1;
}

.hero-panel p:last-child {
  margin: 9px 0 0;
  color: var(--muted);
  line-height: 1.35;
}

.progress-ring {
  display: grid;
  place-items: center;
  flex: 0 0 92px;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, #fff 0 58%, transparent 59%),
    conic-gradient(var(--green-dark) var(--progress, 0%), #dbe9e4 0);
  color: var(--green-dark);
  font-weight: 900;
}

.goal-control {
  display: grid;
  gap: 7px;
  max-width: 270px;
  margin-top: 14px;
}

.goal-control label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.goal-control > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.goal-control input {
  min-height: 42px;
}

.goal-control .ghost-button {
  min-height: 42px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.metric-card {
  min-height: 112px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric-card small {
  display: block;
  min-height: 34px;
  color: var(--muted);
  font-weight: 750;
  line-height: 1.25;
}

.metric-card strong {
  display: block;
  margin-top: 10px;
  font-size: 1.45rem;
  line-height: 1;
}

.metric-card span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.chart-panel,
.table-panel,
.form-panel {
  padding: 16px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.panel-heading span {
  color: var(--muted);
  font-size: 0.82rem;
  text-align: right;
}

.form-panel {
  display: grid;
  gap: 14px;
}

.panel-heading.compact {
  margin-bottom: 2px;
}

.calculator-block {
  display: grid;
  gap: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

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

label {
  display: grid;
  gap: 7px;
}

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

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  min-height: 50px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 850;
}

.primary-button {
  background: var(--green-dark);
  color: #fff;
}

.secondary-button {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  text-align: center;
}

.compact-button {
  min-height: 42px;
  padding: 0 12px;
}

.ghost-button {
  min-height: 40px;
  background: var(--surface-soft);
  color: var(--green-dark);
}

.danger-button {
  min-height: 40px;
  background: #fff0f0;
  color: var(--danger);
}

.file-button input {
  display: none;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.report-options {
  box-shadow: none;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.checkbox-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 800;
}

.print-report {
  display: none;
}

table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  background: var(--surface);
}

th,
td {
  padding: 13px 11px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-weight: 900;
}

.icon-button.delete {
  color: var(--danger);
}

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

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
}

.bottom-nav.has-admin {
  grid-template-columns: repeat(5, 1fr);
}

.nav-button {
  display: grid;
  place-items: center;
  gap: 3px;
  min-height: 58px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.nav-button.is-active {
  background: var(--surface-soft);
  color: var(--green-dark);
}

.nav-icon {
  font-size: 1.25rem;
  line-height: 1;
}

@media (min-width: 680px) {
  .summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding-right: 12px;
    padding-left: 12px;
  }

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

  .top-actions {
    width: 100%;
  }

  .year-filter {
    width: 100%;
  }

  .summary-grid,
  .action-row,
  .checkbox-grid {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    margin: 12mm;
  }

  body {
    background: #fff;
    color: #111;
  }

  .auth-screen,
  .app-shell {
    display: none !important;
  }

  .print-report {
    display: block;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  }

  .print-page {
    display: grid;
    gap: 18px;
  }

  .print-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    padding-bottom: 14px;
    border-bottom: 2px solid #111;
  }

  .print-header p,
  .print-header span,
  .print-header small {
    display: block;
    margin: 0;
  }

  .print-header p,
  .print-header strong {
    font-size: 10pt;
    text-transform: uppercase;
  }

  .print-header h1 {
    margin-top: 4px;
    font-size: 22pt;
  }

  .print-metrics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }

  .print-metrics article {
    min-height: 62px;
    padding: 10px;
    border: 1px solid #bbb;
  }

  .print-metrics span {
    display: block;
    color: #555;
    font-size: 9pt;
  }

  .print-metrics strong {
    display: block;
    margin-top: 6px;
    font-size: 15pt;
  }

  .print-table-section h2 {
    margin: 0 0 8px;
    font-size: 14pt;
  }

  .print-report table {
    min-width: 0;
    font-size: 9pt;
  }

  .print-report th,
  .print-report td {
    padding: 7px 6px;
    white-space: normal;
  }

  .print-empty {
    color: #555;
  }
}
