:root {
  color-scheme: light;
  --ink: #16201e;
  --muted: #66716e;
  --line: #dce3df;
  --paper: #fbfcfa;
  --panel: #ffffff;
  --pine: #12332f;
  --mint: #9be0c9;
  --gold: #f0b84d;
  --rose: #c74d5a;
  --blue: #3776ab;
  --shadow: 0 16px 40px rgba(18, 51, 47, 0.12);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(180deg, rgba(155, 224, 201, 0.42), rgba(251, 252, 250, 0) 340px),
    var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.hidden {
  display: none !important;
}

.locked {
  display: none;
}

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

.auth-card {
  width: min(430px, 100%);
  display: grid;
  gap: 16px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.auth-card h1 {
  font-size: clamp(1.8rem, 8vw, 3rem);
}

.auth-copy {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.auth-message {
  min-height: 22px;
  margin: 0;
  color: var(--rose);
  font-size: 0.88rem;
  font-weight: 800;
}

button,
input,
select {
  font: inherit;
}

button {
  touch-action: manipulation;
}

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

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

.topbar-actions {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 8px;
}

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

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(1.85rem, 8vw, 3.8rem);
  line-height: 0.96;
}

h2 {
  margin: 0;
  font-size: clamp(1.22rem, 4.5vw, 1.8rem);
  line-height: 1.05;
}

h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.icon-button,
.primary-button,
.secondary-button,
.danger-button,
.import-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
  white-space: nowrap;
}

.icon-button {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  background: var(--pine);
  color: #fff;
  box-shadow: var(--shadow);
}

.icon-button span {
  display: block;
  margin-top: -2px;
  font-size: 2rem;
  line-height: 1;
}

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

.summary-panel {
  min-height: 136px;
  padding: 18px;
  border: 1px solid rgba(18, 51, 47, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 10px 28px rgba(18, 51, 47, 0.08);
}

.summary-panel span {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.summary-panel strong {
  display: block;
  margin: 12px 0 6px;
  font-size: clamp(1.35rem, 5vw, 2.15rem);
  line-height: 1;
}

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

.total-panel {
  background: var(--pine);
  color: #fff;
}

.total-panel span,
.total-panel small {
  color: rgba(255, 255, 255, 0.76);
}

.chart-section,
.tab-panel {
  margin-top: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 34px rgba(18, 51, 47, 0.08);
}

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

.heading-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chart-wrap {
  width: 100%;
  aspect-ratio: 3 / 1;
  min-height: 180px;
  max-height: 320px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #f6faf8);
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.history-chip {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.history-chip small {
  display: block;
  color: var(--muted);
}

.backup-status {
  min-height: 22px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef5f1;
}

.tab {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.tab.active {
  background: #fff;
  color: var(--pine);
  box-shadow: 0 8px 18px rgba(18, 51, 47, 0.1);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.entry-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

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

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

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(55, 118, 171, 0.16);
}

.primary-button {
  background: var(--pine);
  color: #fff;
  font-weight: 900;
  padding: 0 18px;
}

.secondary-button,
.import-button {
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--pine);
  font-weight: 900;
  padding: 0 16px;
}

.compact-button {
  min-height: 46px;
  padding: 0 14px;
}

.danger-button {
  background: #fff2f3;
  color: var(--rose);
  border: 1px solid #f1c4c9;
  font-weight: 900;
  padding: 0 16px;
}

.item-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.list-tables {
  display: grid;
  gap: 16px;
}

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

.list-block h3 {
  margin: 0;
  color: var(--pine);
}

.table-scroll {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
}

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

th {
  position: sticky;
  top: 0;
  background: #eef5f1;
  color: var(--pine);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

td {
  color: var(--ink);
  font-size: 0.9rem;
}

tbody tr:nth-child(even) {
  background: #f8fbf9;
}

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

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

.item-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.item-meta {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.item-meta strong {
  font-size: 1.04rem;
}

.item-actions {
  display: flex;
  gap: 6px;
}

.mini-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7faf8;
  color: var(--pine);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 900;
  padding: 0 10px;
}

.alert-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-left: 6px;
  padding: 0 8px;
  border-radius: 999px;
  background: #fff3d8;
  color: #7b5205;
  font-size: 0.75rem;
  font-weight: 900;
}

.utility-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.import-button input {
  display: none;
}

.install-card {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid #b8ddd0;
  border-radius: 8px;
  background: #edf9f4;
}

.install-card p {
  margin: 6px 0 0;
  color: var(--muted);
}

.empty-state {
  padding: 18px;
  border: 1px dashed #b9c7c2;
  border-radius: 8px;
  color: var(--muted);
  background: #fbfdfc;
}

.edit-dialog {
  width: min(420px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 0;
}

.edit-dialog::backdrop {
  background: rgba(18, 32, 30, 0.46);
}

.edit-dialog form {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.dialog-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 840px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

  .summary-grid,
  .entry-form {
    grid-template-columns: 1fr;
  }

  .summary-panel {
    min-height: 112px;
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .heading-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .chart-wrap {
    aspect-ratio: 1.35 / 1;
  }

  .item-card {
    grid-template-columns: 1fr;
  }

  .item-meta {
    justify-items: start;
  }

  .utility-row > * {
    width: 100%;
  }

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

  .topbar-actions {
    flex-direction: column-reverse;
  }

  .dialog-actions {
    grid-template-columns: 1fr;
  }
}
