:root {
  color-scheme: light;
  --bg: #f5f7f2;
  --panel: #ffffff;
  --panel-soft: #eef5ef;
  --ink: #1d2520;
  --muted: #6a746d;
  --line: #dce4dc;
  --green: #2f7a5a;
  --green-dark: #20573f;
  --coral: #c85044;
  --amber: #ac7218;
  --blue: #386fa4;
  --shadow: 0 18px 48px rgba(35, 52, 42, 0.12);
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(47, 122, 90, 0.08), transparent 270px),
    var(--bg);
  color: var(--ink);
}

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

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

.app-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(26px + env(safe-area-inset-bottom));
}

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

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.brand-mark {
  position: relative;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--green);
  box-shadow: inset 0 -10px 0 rgba(0, 0, 0, 0.09);
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  background: #fff;
}

.brand-mark::before {
  left: 11px;
  right: 11px;
  top: 10px;
  height: 22px;
  border-radius: 3px;
}

.brand-mark::after {
  left: 16px;
  top: 17px;
  width: 10px;
  height: 15px;
  border-radius: 2px 2px 0 0;
  background: var(--green-dark);
}

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

h1 {
  font-size: 1.42rem;
  line-height: 1.12;
  letter-spacing: 0;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.92rem;
}

.mobile-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 12px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.74);
}

.switch-button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.switch-button.active {
  background: var(--green);
  color: #fff;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.overview-panel,
.editor-panel {
  padding: 14px;
}

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

.panel-heading h2 {
  font-size: 1.05rem;
  line-height: 1.25;
}

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

.summary-cell {
  min-height: 76px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfb;
}

.summary-cell span {
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1;
}

.summary-cell small {
  color: var(--muted);
  font-size: 0.78rem;
}

.summary-cell.urgent span {
  color: var(--coral);
}

.summary-cell.soon span {
  color: var(--amber);
}

.summary-cell.total span {
  color: var(--green);
}

.toolbar {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.search-field input,
label > input,
label > select,
label > textarea,
.suffix-field,
.list-header select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  outline: none;
}

input,
select,
textarea {
  padding: 10px 12px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
.suffix-field:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 122, 90, 0.15);
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.filter-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  font-weight: 700;
}

.filter-button.active {
  border-color: rgba(47, 122, 90, 0.4);
  background: var(--panel-soft);
  color: var(--green-dark);
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.list-header select {
  width: auto;
  min-width: 132px;
  min-height: 38px;
  padding-block: 7px;
}

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

.item-card {
  display: grid;
  gap: 12px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.item-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}

.item-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.item-title-row h3 {
  min-width: 0;
  font-size: 1.03rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.status-pill,
.category-pill,
.platform-pill,
.amount-text {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill {
  background: var(--panel-soft);
  color: var(--green-dark);
}

.item-card.overdue .status-pill {
  background: rgba(200, 80, 68, 0.1);
  color: var(--coral);
}

.item-card.soon .status-pill {
  background: rgba(172, 114, 24, 0.12);
  color: var(--amber);
}

.category-pill {
  background: rgba(56, 111, 164, 0.1);
  color: var(--blue);
}

.platform-pill,
.amount-text {
  background: #f0f2ee;
  color: var(--muted);
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.date-block {
  min-width: 78px;
  text-align: right;
}

.date-block strong {
  display: block;
  font-size: 0.98rem;
}

.date-block small {
  color: var(--muted);
  font-size: 0.78rem;
}

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

.detail-grid div {
  min-width: 0;
  padding: 8px;
  border-radius: var(--radius);
  background: #f7f9f7;
}

.detail-grid dt {
  color: var(--muted);
  font-size: 0.72rem;
}

.detail-grid dd {
  margin: 2px 0 0;
  font-size: 0.84rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.notes-text {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.notes-text:empty {
  display: none;
}

.card-actions,
.form-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.primary-button,
.secondary-button,
.danger-button,
.text-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 9px 12px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

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

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--green-dark);
}

.secondary-button {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.danger-button {
  border-color: rgba(200, 80, 68, 0.25);
  background: rgba(200, 80, 68, 0.08);
  color: var(--coral);
}

.text-button {
  min-height: 34px;
  border: 0;
  background: transparent;
  color: var(--green-dark);
  padding-inline: 6px;
}

.compact {
  min-height: 38px;
  padding-inline: 14px;
}

.product-link.disabled {
  pointer-events: none;
  background: #d7ddd7;
  color: #6e776f;
}

.item-form {
  display: grid;
  gap: 12px;
}

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

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

.suffix-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  padding: 0;
  overflow: hidden;
}

.suffix-field input {
  min-width: 0;
  border: 0;
  box-shadow: none;
}

.suffix-field span {
  padding-right: 12px;
  color: var(--muted);
}

.empty-state {
  display: grid;
  gap: 12px;
  justify-items: start;
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.68);
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 10;
  max-width: min(420px, calc(100vw - 32px));
  transform: translate(-50%, 140%);
  padding: 11px 14px;
  border-radius: var(--radius);
  background: #17231c;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

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

[data-active-view="settings"] .overview-panel,
[data-active-view="list"] .editor-panel {
  display: none;
}

@media (max-width: 420px) {
  .app-shell {
    padding-inline: 12px;
  }

  .summary-grid,
  .detail-grid {
    gap: 6px;
  }

  .summary-cell,
  .detail-grid div {
    padding-inline: 8px;
  }

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

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

  .date-block {
    text-align: left;
  }
}

@media (min-width: 760px) {
  .app-shell {
    padding: 28px 20px 34px;
  }

  .mobile-switch {
    display: none;
  }

  h1 {
    font-size: 1.9rem;
  }

  .layout {
    grid-template-columns: minmax(0, 1.25fr) minmax(330px, 0.75fr);
    align-items: start;
  }

  [data-active-view="settings"] .overview-panel,
  [data-active-view="list"] .editor-panel {
    display: block;
  }

  .toolbar {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .filter-row {
    width: 300px;
  }

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

  .editor-panel {
    position: sticky;
    top: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
