:root {
  --bg: #f5f4f1;
  --surface: #ffffff;
  --ink: #1f1b16;
  --ink-soft: #6b625a;
  --line: #e4dfd8;
  --accent: #8a6d3b;
  --accent-ink: #ffffff;
  --good: #2f7d4f;
  --warn: #b98a1f;
  --bad: #b3432f;
  --muted: #8a837b;
  --radius: 10px;
  font-size: 15px;
}

* { box-sizing: border-box; }

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

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px;
}
.brand h1 { font-size: 17px; margin: 0; }
.brand p { font-size: 12px; margin: 0; color: var(--ink-soft); }

.tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 8px; }
.tab {
  border: none; background: transparent; padding: 8px 16px;
  border-radius: 6px; font-size: 13px; font-weight: 600; color: var(--ink-soft);
  cursor: pointer;
}
.tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

main { padding: 24px 28px 60px; max-width: 1200px; margin: 0 auto; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat-card .num { font-size: 26px; font-weight: 700; }
.stat-card .label { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
.stat-card.available .num { color: var(--good); }
.stat-card.checked_out .num { color: var(--accent); }
.stat-card.needs_repair .num { color: var(--warn); }
.stat-card.missing .num { color: var(--bad); }

.section-title { font-size: 15px; font-weight: 700; margin: 28px 0 12px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); }
th { color: var(--ink-soft); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #faf9f7; }

.toolbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .filters { display: flex; gap: 8px; flex-wrap: wrap; }

input, select, textarea {
  font-family: inherit; font-size: 13.5px;
  border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 10px; background: var(--surface); color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; }

button.btn {
  border: none; border-radius: 6px; padding: 9px 16px;
  font-size: 13.5px; font-weight: 600; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
}
button.btn.secondary { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }
button.btn.danger { background: var(--bad); color: #fff; }
button.btn.small { padding: 5px 10px; font-size: 12px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; }
.badge.available { background: #e5f3ea; color: var(--good); }
.badge.checked_out { background: #f1e9dc; color: var(--accent); }
.badge.needs_repair { background: #fbf0da; color: var(--warn); }
.badge.missing { background: #f9e4de; color: var(--bad); }
.badge.retired { background: #ececec; color: var(--muted); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--ink-soft); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,17,13,.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 20px; overflow-y: auto; z-index: 100;
}
.modal {
  background: var(--surface); border-radius: 12px; padding: 28px;
  width: 100%; max-width: 560px; position: relative;
}
.modal-close {
  position: absolute; top: 14px; right: 16px; border: none; background: none;
  font-size: 22px; cursor: pointer; color: var(--ink-soft);
}
.modal h2 { margin-top: 0; font-size: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 4px; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.breadcrumb { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 10px; cursor: pointer; }
.breadcrumb:hover { color: var(--ink); }

.item-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.item-header h2 { margin: 0 0 4px; }
.item-meta { color: var(--ink-soft); font-size: 13px; }

.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 20px; }
.chip { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; font-size: 12.5px; }
.chip b { display: block; font-size: 16px; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.cat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; cursor: pointer; }
.cat-card:hover { border-color: var(--accent); }
.cat-card h3 { margin: 0 0 6px; font-size: 15px; }
.cat-card p { margin: 0; font-size: 12.5px; color: var(--ink-soft); }

.low-stock-row { color: var(--warn); font-weight: 600; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  main { padding: 16px; }
  .topbar { padding: 12px 16px; }
}
