:root {
  --bg: #f7f2ec;
  --panel: #fffdf9;
  --ink: #2a211c;
  --muted: #7a6d65;
  --line: #eadfd5;
  --accent: #d66b4d;
  --accent-dark: #b95237;
  --soft: #f3e7dc;
  --danger: #ad352f;
  --shadow: 0 14px 40px rgba(80, 50, 30, 0.08);
  --radius: 22px;
}

* { box-sizing: border-box; }

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

button, input, select { font: inherit; }
button { cursor: pointer; }

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 34px max(24px, calc((100vw - 1440px) / 2));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

h1, h2, p { margin: 0; }
h1 { font-size: clamp(28px, 4vw, 46px); letter-spacing: -0.04em; }
h2 { font-size: 24px; letter-spacing: -0.025em; }
.subtitle { margin-top: 8px; color: var(--muted); }
.eyebrow { margin-bottom: 7px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: 0.15em; }

.header-actions, .inventory-actions, .form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.container { width: min(1440px, calc(100% - 32px)); margin: 28px auto 64px; }

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

.summary-card {
  min-height: 145px;
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.summary-card span, .summary-card small { color: var(--muted); }
.summary-card strong { font-size: clamp(26px, 3vw, 38px); letter-spacing: -0.04em; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.entry-panel { padding: 24px; margin-bottom: 20px; }
.inventory-panel { margin-top: 20px; }

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
}
.inventory-heading { padding: 24px 24px 0; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
.field { display: flex; flex-direction: column; gap: 8px; }
.field-wide { grid-column: span 2; }
.field span { color: var(--muted); font-size: 13px; font-weight: 700; }

input, select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 0 13px;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(214, 107, 77, .12); }
.money-input { position: relative; }
.money-input input { padding-right: 38px; }
.money-input b { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }

.live-calculation {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 20px;
  padding: 16px;
  background: var(--soft);
  border-radius: 16px;
}
.live-calculation div { display: flex; flex-direction: column; gap: 4px; }
.live-calculation span { color: var(--muted); font-size: 12px; font-weight: 700; }
.live-calculation strong { font-size: 21px; }
.form-actions { justify-content: flex-end; margin-top: 18px; }

.btn {
  border: 0;
  border-radius: 12px;
  min-height: 44px;
  padding: 0 16px;
  font-weight: 800;
}
.btn-primary { color: #fff; background: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-light { color: var(--ink); background: var(--soft); }
.btn-light:hover { background: #ead9ca; }
.btn-large { min-width: 220px; min-height: 50px; }
.text-btn { border: 0; padding: 5px; color: var(--muted); background: transparent; font-weight: 700; }
.text-btn:hover { color: var(--ink); }
.text-btn.danger { color: var(--danger); }
.file-label { display: inline-flex; align-items: center; }

.search-input { width: 220px; }
.inventory-actions select { width: 210px; }
.table-wrap { overflow-x: auto; position: relative; }
table { width: 100%; min-width: 1180px; border-collapse: collapse; }
th, td { padding: 14px 16px; border-top: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; background: #fcf8f4; }
td { font-size: 14px; }
.number { text-align: right; font-variant-numeric: tabular-nums; }
.actions-col { width: 132px; }
.item-name { font-weight: 800; }
.item-meta { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.type-pill { display: inline-flex; border-radius: 999px; padding: 6px 9px; background: var(--soft); font-size: 12px; font-weight: 700; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn { border: 1px solid var(--line); border-radius: 9px; padding: 7px 9px; color: var(--ink); background: #fff; font-weight: 700; }
.icon-btn:hover { border-color: var(--accent); }
.icon-btn.delete:hover { color: var(--danger); border-color: var(--danger); }
.qty-control { display: inline-flex; align-items: center; gap: 8px; }
.qty-control button { width: 26px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.qty-control strong { min-width: 22px; text-align: center; }

.empty-state { display: none; padding: 52px 20px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; color: var(--ink); margin-bottom: 6px; }
.empty-state.visible { display: block; }

.danger-zone { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-top: 16px; padding: 0 6px; color: var(--muted); font-size: 13px; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(380px, calc(100vw - 44px));
  padding: 14px 18px;
  border-radius: 13px;
  color: #fff;
  background: var(--ink);
  box-shadow: 0 16px 42px rgba(0,0,0,.22);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: .22s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

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

@media (max-width: 720px) {
  .topbar { flex-direction: column; padding: 26px 20px; }
  .header-actions { width: 100%; }
  .header-actions .btn, .header-actions .file-label { flex: 1; justify-content: center; }
  .container { width: min(100% - 20px, 1440px); margin-top: 14px; }
  .summary-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .summary-card { min-height: 125px; padding: 16px; }
  .summary-card strong { font-size: 25px; }
  .entry-panel { padding: 18px; }
  .panel-heading, .inventory-heading { align-items: flex-start; flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: span 1; }
  .live-calculation { grid-template-columns: 1fr; }
  .form-actions .btn { width: 100%; }
  .inventory-actions { width: 100%; }
  .search-input, .inventory-actions select { width: 100%; }
  .danger-zone { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 440px) {
  .summary-grid { grid-template-columns: 1fr; }
}
