:root {
  --bg: #f7f8f5;
  --panel: #ffffff;
  --panel-raised: #fffefa;
  --ink: #202823;
  --muted: #69736d;
  --line: #dce2dd;
  --strong-line: #bdc9c1;
  --accent: #2d7d63;
  --accent-soft: #e8f3ee;
  --gold: #f0b429;
  --danger: #b33a32;
  --danger-soft: #fff0ef;
  --tabbar-bg: rgba(247, 248, 245, 0.94);
  --secondary: #eef1ed;
  --shadow: 0 12px 32px rgba(32, 40, 35, 0.08);
}

:root[data-theme="dark"] {
  --bg: #111714;
  --panel: #18211d;
  --panel-raised: #202b26;
  --ink: #edf3ef;
  --muted: #aebbb4;
  --line: #34443c;
  --strong-line: #53665c;
  --accent: #62c69c;
  --accent-soft: #213a31;
  --gold: #f2c45c;
  --danger: #ff8a7f;
  --danger-soft: #3b2423;
  --tabbar-bg: rgba(17, 23, 20, 0.94);
  --secondary: #26342e;
  --shadow: 0 16px 42px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  width: 100%;
  overflow-x: hidden;
}

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

button,
input,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

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

.topbar,
.header-actions,
.section-heading,
.form-actions,
.tool-grid,
.switch-row {
  display: flex;
  align-items: center;
}

.topbar,
.section-heading {
  justify-content: space-between;
  gap: 12px;
}

.topbar {
  margin-bottom: 14px;
}

.header-actions,
.form-actions,
.tool-grid {
  gap: 8px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

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

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

h2 {
  font-size: 18px;
}

h3 {
  font-size: 15px;
}

.dashboard,
.panel,
.dialog-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.dashboard,
.panel {
  margin-bottom: 12px;
  padding: 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.metric {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-raised);
  padding: 10px;
}

.hero-metric {
  background: var(--accent-soft);
  border-color: #c7dfd4;
}

.metric span,
.metric small,
label,
.muted,
.record-meta,
.summary-line {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.hero-metric strong {
  font-size: 28px;
}

.tabbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 6px;
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tabbar-bg);
  backdrop-filter: blur(14px);
}

.tab,
.icon-button,
.text-icon-button,
.primary-button,
.secondary-button,
.text-button,
.lot-action,
.remove-button {
  border: 0;
  cursor: pointer;
}

.tab {
  min-width: 0;
  min-height: 42px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 850;
}

.tab.active {
  background: var(--accent);
  color: #ffffff;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-raised);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

label.icon-button,
label.text-icon-button {
  font-weight: 400;
}

.text-icon-button {
  display: grid;
  min-width: 58px;
  min-height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-raised);
  color: var(--ink);
  font-size: 14px;
  font-weight: 850;
  padding: 0 10px;
  text-align: center;
}

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

.tab-panel {
  display: none;
}

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

form {
  margin-top: 12px;
}

.type-choice {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.type-choice input {
  position: absolute;
  opacity: 0;
}

.type-choice span {
  display: grid;
  min-height: 46px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-raised);
  color: var(--ink);
  font-size: 14px;
  font-weight: 850;
  text-align: center;
}

.type-choice input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.dividend-choice {
  grid-column: 1 / -1;
}

.field-grid,
.filter-grid,
.initial-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-raised);
  color: var(--ink);
  font-size: 16px;
  outline: 0;
  padding: 12px;
}

input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45, 125, 99, 0.14);
}

.primary-button,
.secondary-button {
  min-height: 48px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 850;
}

.primary-button {
  flex: 1;
  background: var(--accent);
  color: #ffffff;
}

.secondary-button {
  background: var(--secondary);
  color: var(--ink);
}

.text-button {
  background: transparent;
  color: var(--accent);
  font-weight: 850;
  padding: 8px 0;
}

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

.cover-box,
.compact-summary {
  margin-top: 14px;
  border: 1.5px solid var(--strong-line);
  border-radius: 8px;
  background: var(--panel-raised);
  padding: 12px;
}

.compact-summary {
  margin-bottom: 18px;
  box-shadow: inset 0 0 0 1px rgba(45, 125, 99, 0.08);
}

.compact-summary + .record-list {
  padding-top: 14px;
  border-top: 2px solid var(--line);
}

.tight {
  margin-bottom: 8px;
}

.lot-list,
.record-list,
.initial-list {
  display: grid;
  gap: 8px;
}

.lot-card,
.record-card,
.initial-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-raised);
  padding: 10px;
}

.record-card.open {
  border-color: #b7d8ca;
  background: var(--panel-raised);
}

.record-card.closed {
  opacity: 0.72;
}

.record-title-row,
.record-money-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.record-title {
  font-weight: 900;
  line-height: 1.3;
}

.record-money {
  flex: 0 0 auto;
  font-weight: 900;
  text-align: right;
}

.record-meta {
  margin-top: 4px;
  line-height: 1.45;
}

.profit {
  color: var(--accent);
}

.loss {
  color: var(--danger);
}

.lot-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 8px;
  align-items: end;
}

.lot-card input {
  padding: 10px;
}

.lot-action {
  grid-column: 1 / -1;
  min-height: 42px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 850;
}

.switch-row {
  justify-content: flex-start;
  gap: 10px;
  margin: 8px 0 12px;
}

.switch-row input {
  width: 22px;
  height: 22px;
}

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

.full-width {
  width: 100%;
  margin-top: 12px;
}

.remove-button {
  min-height: 40px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 850;
}

dialog {
  width: min(calc(100% - 28px), 560px);
  border: 0;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(32, 40, 35, 0.36);
}

.dialog-panel {
  padding: 12px;
}

.summary-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
}

.summary-line:first-child {
  border-top: 0;
}

.summary-line strong {
  color: var(--ink);
  text-align: right;
}

.empty-state {
  color: var(--muted);
  padding: 12px 0 2px;
  line-height: 1.45;
}

@media (min-width: 560px) {
  .field-grid,
  .filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .amount-field {
    grid-column: span 2;
  }
}

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

  h1 {
    font-size: 28px;
  }

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

  .lot-card {
    grid-template-columns: minmax(0, 1fr);
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }
}
