:root {
  color-scheme: light;
  --ink: #16211b;
  --muted: #65746c;
  --line: #d9e2dd;
  --paper: #ffffff;
  --soft: #f3f7f1;
  --wash: #eaf2e8;
  --green: #1f4d3a;
  --green-strong: #163829;
  --amber: #d99a2b;
  --clay: #a4573c;
  --blue: #32606d;
  --shadow: 0 18px 40px rgba(22, 33, 27, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #f7f9f4;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(31, 77, 58, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(217, 154, 43, 0.16), transparent 38%),
    #f7f9f4;
  font-family: "Segoe UI", Arial, sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 0 max(26px, env(safe-area-inset-bottom));
}

.app-header {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 128px;
  gap: 22px;
  align-items: center;
  min-height: 190px;
  overflow: hidden;
  padding: 28px;
  border-radius: 8px;
  color: #fff;
  background:
    linear-gradient(120deg, rgba(22, 56, 41, 0.95), rgba(31, 77, 58, 0.72)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.06) 0 1px, transparent 1px 28px);
  box-shadow: var(--shadow);
}

.app-header h1,
.panel h2 {
  margin: 0;
}

.app-header h1 {
  font-size: clamp(2.3rem, 8vw, 4.5rem);
  line-height: 1;
}

.header-copy {
  max-width: 620px;
  margin: 12px 0 0;
  color: rgba(255, 255, 255, 0.86);
  font-size: 1.05rem;
  line-height: 1.5;
}

.farm-mark {
  display: grid;
  place-items: center;
  width: 128px;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.13);
}

.farm-mark img {
  width: 92px;
  height: 92px;
}

.eyebrow {
  margin: 0 0 8px;
  color: inherit;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.metric-card {
  min-height: 118px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 12px 28px rgba(22, 33, 27, 0.07);
}

.metric-card.accent {
  color: #fff;
  border-color: transparent;
  background: var(--green);
}

.metric-card span,
.entry-preview span {
  display: block;
  color: inherit;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(1.45rem, 4vw, 2rem);
  line-height: 1.08;
}

.metric-card small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.35;
}

.metric-card.accent small {
  color: rgba(255, 255, 255, 0.76);
}

.tab-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 24px rgba(22, 33, 27, 0.08);
  backdrop-filter: blur(12px);
}

.tab-button,
.ghost-button,
.file-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--green);
  background: #fff;
  font-weight: 800;
}

.tab-button.is-active,
.primary-button {
  color: #fff;
  border-color: var(--green);
  background: var(--green);
}

.tab-button:focus-visible,
.primary-button:focus-visible,
.ghost-button:focus-visible,
.file-button:focus-visible,
input:focus,
textarea:focus {
  outline: 3px solid rgba(217, 154, 43, 0.26);
  border-color: var(--amber);
}

.view {
  display: none;
  margin-top: 14px;
}

.view.is-active {
  display: block;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 12px 28px rgba(22, 33, 27, 0.07);
}

.entry-form,
#financials-view .panel,
.panel-stack .panel {
  display: grid;
  gap: 18px;
  padding: 22px;
}

.logger-form,
#price-form {
  display: grid;
  gap: 18px;
}

.panel-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(160px, 220px);
  gap: 16px;
  align-items: end;
}

.panel h2 {
  font-size: 1.55rem;
}

label,
fieldset {
  min-width: 0;
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-weight: 750;
}

label span,
legend {
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 800;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 10px;
}

.field-hint {
  margin: -3px 0 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

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

textarea {
  resize: vertical;
}

.size-grid,
.expense-grid,
.price-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.size-card,
.price-card {
  display: grid;
  gap: 7px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.size-card span,
.price-card span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}

.size-code {
  color: var(--blue);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

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

.entry-preview div,
.report-card,
.feed-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--wash);
}

.entry-preview strong {
  display: block;
  margin-top: 6px;
  font-size: 1.2rem;
}

.button-row,
.utility-row,
.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

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

.section-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(160px, 220px);
  gap: 16px;
  align-items: end;
  margin-bottom: 12px;
}

.section-header h3,
#feed-inventory-title {
  margin: 0;
  font-size: 1.05rem;
}

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

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

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

.report-card,
.feed-card {
  min-height: 118px;
  background: #fff;
}

.report-card.accent {
  color: #fff;
  border-color: var(--green);
  background: var(--green);
}

.report-card span,
.feed-card span {
  display: block;
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.report-card strong,
.feed-card strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(1.3rem, 4vw, 1.8rem);
  line-height: 1.1;
}

.report-card small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.35;
}

.report-card.accent small {
  color: rgba(255, 255, 255, 0.76);
}

.statement-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.85fr);
  gap: 16px;
}

.statement-grid h3,
#period-days-title {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

.statement-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.statement-list div,
.breakdown-row,
.period-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.statement-list dt,
.statement-list dd {
  margin: 0;
}

.statement-list dt,
.breakdown-row span,
.period-row span {
  color: var(--muted);
}

.statement-list dd,
.breakdown-row strong,
.period-row strong {
  font-weight: 850;
}

.statement-total {
  color: #fff;
  border-color: var(--green);
  background: var(--green) !important;
}

.statement-total dt {
  color: rgba(255, 255, 255, 0.78);
}

.breakdown-list,
.period-table {
  display: grid;
  gap: 8px;
}

.period-row {
  grid-template-columns: minmax(110px, 0.75fr) minmax(110px, 0.8fr) repeat(4, minmax(0, 1fr));
}

.primary-button,
.ghost-button,
.file-button {
  min-height: 48px;
  padding: 0 16px;
}

.primary-button:hover,
.tab-button.is-active:hover {
  background: var(--green-strong);
}

.ghost-button:hover,
.file-button:hover {
  color: #fff;
  background: var(--green);
}

.file-button {
  display: inline-grid;
  place-items: center;
}

.status-line {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.history-card h3 {
  margin: 0;
  font-size: 1.04rem;
}

.history-card p {
  margin: 7px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.history-actions {
  display: grid;
  gap: 8px;
  align-content: start;
}

.mini-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--green);
  background: #fff;
  font-weight: 800;
}

.mini-button.danger {
  color: var(--clay);
}

.empty-state {
  display: none;
  margin: 0;
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: #fbfcfa;
}

.empty-state.is-visible {
  display: block;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@media (max-width: 860px) {
  .summary-grid,
  .report-summary,
  .feed-grid,
  .size-grid,
  .expense-grid,
  .price-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .statement-grid,
  .period-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 18px, 1120px);
    padding-top: 9px;
  }

  .app-header {
    grid-template-columns: 1fr;
    min-height: 0;
    padding: 20px;
  }

  .farm-mark {
    width: 82px;
  }

  .farm-mark img {
    width: 58px;
    height: 58px;
  }

  .summary-grid,
  .panel-header,
  .section-header,
  .range-controls,
  .entry-preview,
  .history-card {
    grid-template-columns: 1fr;
  }

  .summary-grid {
    gap: 10px;
  }

  .metric-card {
    min-height: 0;
    padding: 15px;
  }

  .tab-bar {
    gap: 6px;
    padding: 6px;
  }

  .tab-button {
    min-height: 42px;
    padding: 0 8px;
    font-size: 0.92rem;
  }

  .entry-form,
  #financials-view .panel,
  .panel-stack .panel {
    gap: 16px;
    padding: 16px;
  }

  .logger-form,
  #price-form {
    gap: 16px;
  }
}

@media (max-width: 430px) {
  .size-grid,
  .expense-grid,
  .price-grid,
  .report-summary,
  .feed-grid {
    grid-template-columns: 1fr;
  }

  .button-row > *,
  .utility-row > * {
    flex: 1 1 100%;
  }
}
