:root {
  color-scheme: light;
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #ece6dc;
  --ink: #1f2933;
  --muted: #667085;
  --line: #d8d2c8;
  --green: #315c48;
  --green-2: #dfe9e3;
  --clay: #c26b3a;
  --blue: #4f7aa3;
  --gold: #b99b4f;
  --danger: #b42318;
  --danger-bg: #fee4e2;
  --ok-bg: #dcfce7;
  --shadow: 0 14px 30px rgba(31, 41, 51, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  max-width: 980px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 14px calc(86px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 0 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(16px);
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.1;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
}

.top-actions,
.actions-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar > div:first-child {
  min-width: 0;
}

.top-actions {
  flex: 0 0 auto;
}

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(31, 41, 51, 0.06);
}

.icon-button span {
  font-size: 20px;
  line-height: 1;
}

.file-button input {
  display: none;
}

main {
  display: block;
}

.screen {
  display: none;
}

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

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

.kpi {
  min-height: 96px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(31, 41, 51, 0.08);
}

.kpi span {
  display: block;
  min-height: 36px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
}

.kpi strong {
  display: block;
  margin-top: 10px;
  color: var(--green);
  font-size: 24px;
  line-height: 1;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 22px 0 10px;
}

.section-head span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--green);
  font-weight: 800;
}

.bars {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(112px, 160px) 1fr 54px;
  align-items: center;
  gap: 10px;
  min-height: 30px;
  color: var(--muted);
  font-size: 13px;
}

.bar-track {
  overflow: hidden;
  height: 9px;
  border-radius: 999px;
  background: var(--surface-2);
}

.bar-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--blue));
}

.activity-list,
.record-list {
  display: grid;
  gap: 10px;
}

.empty-state {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
  color: var(--muted);
  text-align: center;
}

.entry-form {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.form-grid {
  display: grid;
  gap: 10px;
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-2);
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 44px;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 800;
}

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

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--green);
}

.danger-button {
  border: 1px solid #fda29b;
  background: var(--danger-bg);
  color: var(--danger);
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin: 12px 0;
}

.record {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.record-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.record-title {
  display: grid;
  gap: 3px;
}

.record-title strong {
  line-height: 1.2;
}

.record-title span {
  color: var(--muted);
  font-size: 13px;
}

.record-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill,
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.pill.ok {
  background: var(--ok-bg);
  color: #166534;
}

.pill.warn {
  background: #fef3c7;
  color: #92400e;
}

.delete-button {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 1px solid #fda29b;
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 18px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 12px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.segmented button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segmented button.is-active {
  background: var(--surface);
  color: var(--green);
  box-shadow: 0 2px 8px rgba(31, 41, 51, 0.08);
}

.stock-panel {
  display: none;
}

.stock-panel.is-active {
  display: block;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  max-width: 980px;
  margin: 0 auto;
  padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(18px);
}

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

.bottom-nav span {
  font-size: 18px;
  line-height: 1;
}

.bottom-nav button.is-active {
  background: var(--green-2);
  color: var(--green);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: calc(88px + env(safe-area-inset-bottom));
  left: 16px;
  z-index: 30;
  display: none;
  max-width: 520px;
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
}

.toast.is-visible {
  display: block;
}

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

  .form-grid.two {
    grid-template-columns: 1fr;
  }

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

  .bar-row {
    grid-template-columns: minmax(92px, 120px) 1fr 44px;
  }

  h1 {
    font-size: 22px;
  }
}

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

  .screen[data-screen="dashboard"] {
    max-width: 940px;
  }

  .entry-form {
    padding: 16px;
  }
}
