:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef4ec;
  --text: #20241f;
  --muted: #687168;
  --line: #dfe5dc;
  --accent: #28724f;
  --accent-strong: #16583b;
  --danger: #b33b32;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: rgba(246, 247, 244, 0.95);
  border-bottom: 1px solid var(--line);
}

.eyebrow { margin: 0 0 2px; color: var(--accent); font-size: 12px; font-weight: 700; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 24px; }
main { width: min(760px, 100%); margin: 0 auto; padding: 14px 14px 28px; }

.summary-band { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.summary-band div { padding: 12px 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; }
.summary-band span, .summary-band small { display: block; color: var(--muted); font-size: 12px; }
.summary-band strong { display: inline-block; margin-top: 4px; font-size: 26px; line-height: 1; }

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

.sync-panel strong {
  display: block;
  font-size: 14px;
}

.sync-panel span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.sync-panel form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.sync-panel input {
  min-height: 42px;
}

.main-tabs {
  position: sticky;
  top: 77px;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-bottom: 12px;
  padding: 4px;
  background: #e7ece4;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.main-tab.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(31, 48, 37, 0.08);
}

.entry-panel, .list-section {
  margin-bottom: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(31, 48, 37, 0.1);
}

.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-title h2 { font-size: 18px; }
.section-title span { color: var(--muted); font-size: 13px; }
form { display: grid; gap: 12px; }
label { display: grid; gap: 6px; }
label span { color: var(--muted); font-size: 13px; font-weight: 700; }

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

input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(40, 114, 79, 0.14); }
.grid-2 { display: grid; gap: 10px; }
.primary-button, .ghost-button, .icon-button, .delete-button { border: 0; border-radius: 8px; }
.primary-button { min-height: 50px; color: #fff; background: var(--accent); font-weight: 800; }
.ghost-button { padding: 8px 10px; color: var(--accent); background: #eaf2ed; font-size: 13px; font-weight: 700; }
.icon-button { width: 44px; height: 44px; color: #fff; background: var(--accent); font-size: 22px; font-weight: 900; }

.controls-band { display: grid; gap: 10px; margin-bottom: 14px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); padding: 3px; background: #e7ece4; border: 1px solid var(--line); border-radius: 8px; }
.segment { min-height: 40px; color: var(--muted); background: transparent; border: 0; border-radius: 6px; font-weight: 800; }
.segment.active { color: var(--text); background: var(--surface); box-shadow: 0 2px 8px rgba(31, 48, 37, 0.08); }
.record-list, .ranking-list { display: grid; gap: 8px; }

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

.record-card time { color: var(--muted); font-size: 12px; font-weight: 700; }
.record-card h3 { margin-top: 2px; font-size: 17px; }
.record-card p { margin-top: 3px; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.record-actions { display: grid; justify-items: end; gap: 8px; }
.record-actions strong { font-size: 20px; white-space: nowrap; }
.delete-button { width: 34px; height: 34px; color: var(--danger); background: #f8e9e7; font-size: 20px; }
.empty-state { display: grid; gap: 4px; padding: 18px 10px; color: var(--muted); text-align: center; }
.empty-state strong { color: var(--text); }
.ranking-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.ranking-row:last-child { border-bottom: 0; }
.ranking-row span { overflow: hidden; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.ranking-row strong { color: var(--accent-strong); }

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

.inventory-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: #fbfcfa;
  font-size: 14px;
}

.inventory-table th,
.inventory-table td {
  min-width: 78px;
  padding: 10px 12px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

.inventory-table th {
  color: var(--muted);
  background: #eef4ec;
  font-weight: 800;
  text-align: center;
}

.inventory-table tbody th {
  color: var(--text);
  text-align: left;
}

.inventory-table tr:last-child th,
.inventory-table tr:last-child td {
  border-bottom: 0;
}

.inventory-table th:last-child,
.inventory-table td:last-child {
  border-right: 0;
}

.inventory-table .sticky-col {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 132px;
  max-width: 170px;
  background: #eef4ec;
  box-shadow: 1px 0 0 var(--line);
  overflow: hidden;
  text-overflow: ellipsis;
}

.inventory-table td.shortage {
  color: var(--danger);
  background: #fff7f6;
  font-weight: 800;
}

.inventory-table td.zero {
  color: var(--muted);
}

.inventory-table td.empty-cell {
  background: #ffffff;
}

@media (min-width: 680px) {
  .controls-band { grid-template-columns: 1fr 1fr; align-items: end; }
  .main-tabs { top: 81px; }
}
