:root {
  color-scheme: light;
  --ink: #17211b;
  --muted: #66736b;
  --line: #dbe3dd;
  --panel: #ffffff;
  --page: #f4f7f1;
  --accent: #246b58;
  --accent-strong: #174c3e;
  --warn: #aa5b18;
  --danger: #a33d3d;
  --blue: #2f5d8c;
  --shadow: 0 18px 44px rgba(35, 53, 44, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

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

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

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 3.7rem);
  line-height: 0.95;
}

.top-actions,
.item-actions,
.tabs,
.filters,
.field-row,
.section-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 1.25rem;
  font-weight: 700;
}

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

.summary-grid article {
  min-height: 92px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(44, 62, 51, 0.06);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.summary-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 2rem;
  line-height: 1;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(290px, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

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

.control-panel,
.inventory-panel,
.history-panel {
  padding: 16px;
}

.tabs {
  padding: 4px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3ef;
}

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

.tab.is-active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 4px 14px rgba(35, 53, 44, 0.1);
}

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

.is-hidden {
  display: none;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

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

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 107, 88, 0.14);
}

.primary-action,
.danger-action {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-weight: 900;
}

.primary-action {
  background: var(--accent);
}

.primary-action:hover {
  background: var(--accent-strong);
}

.danger-action {
  background: var(--danger);
}

.filters {
  align-items: stretch;
  margin-bottom: 14px;
}

.search-wrap {
  display: flex;
  align-items: center;
  flex: 1.2;
  min-width: 190px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  padding-left: 11px;
}

.search-wrap input {
  border: 0;
  background: transparent;
  box-shadow: none;
}

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

.inventory-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfa;
}

.item-main {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
}

.item-main h3 {
  margin-bottom: 4px;
  font-size: 1.08rem;
}

.item-meta,
.item-details {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.item-qty {
  flex: 0 0 auto;
  min-width: 76px;
  text-align: right;
  color: var(--blue);
  font-size: 1.15rem;
}

.item-details {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 8px;
  border-radius: 7px;
  background: #edf2f5;
  color: #33475b;
  font-weight: 700;
  font-size: 0.78rem;
}

.badge.warn {
  background: #fff0df;
  color: var(--warn);
}

.badge.danger {
  background: #fbe8e8;
  color: var(--danger);
}

.item-actions {
  flex-wrap: wrap;
  margin-top: 12px;
}

.chip-button,
.text-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  min-height: 36px;
  padding: 7px 10px;
  font-weight: 800;
}

.quick-use {
  border-color: rgba(36, 107, 88, 0.28);
  color: var(--accent-strong);
}

.remove-item {
  color: var(--danger);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 220px;
  border: 1px dashed #b9c6bd;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
}

.history-panel {
  margin-top: 16px;
}

.section-heading {
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-heading h2 {
  margin-bottom: 0;
  font-size: 1.05rem;
}

#historyList {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

#historyList li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.92rem;
}

#historyList strong {
  color: var(--ink);
}

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

dialog::backdrop {
  background: rgba(18, 27, 23, 0.42);
}

.dialog-card {
  display: grid;
  gap: 12px;
  padding: 16px;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100vw - 20px, 720px);
    padding-top: 14px;
  }

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

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

  .filters {
    flex-wrap: wrap;
  }

  .filters > select,
  .search-wrap {
    flex: 1 1 100%;
  }
}

@media (max-width: 520px) {
  .field-row,
  .topbar {
    align-items: stretch;
  }

  .field-row {
    flex-direction: column;
  }

  .topbar {
    flex-direction: column;
  }

  .top-actions {
    align-self: flex-end;
  }

  .summary-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .summary-grid article {
    min-height: 78px;
    padding: 12px;
  }

  .summary-grid strong {
    font-size: 1.55rem;
  }
}
