:root {
  --ink: #0a0a0a;
  --paper: #fafafa;
  --white: #ffffff;
  --line: #e6e2e0;
  --muted: #767066;
  --pink: #f4dede;
  --pink-deep: #eec4c4;
  --pink-text: #a14b4b;
  --green: #e3efdf;
  --green-text: #3f6b3f;
  --amber: #f7ecd0;
  --amber-text: #8a6a1f;
  --gray: #ececec;
  --gray-text: #5c5c5c;
  --radius: 10px;
  --font: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header / branding ---------- */

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

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

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: block;
}

.brand-logo {
  height: 20px;
  width: auto;
  display: block;
}

.brand-sub {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
  border-left: 1px solid var(--line);
  padding-left: 12px;
  margin-left: 2px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

/* ---------- Buttons ---------- */

.btn {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--ink);
  color: var(--white);
}
.btn-primary:hover { background: #262626; }

.btn-ghost {
  background: var(--white);
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-ghost:hover { background: var(--gray); }

.btn-icon {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--muted);
}
.btn-icon:hover { background: var(--gray); color: var(--ink); }

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 32px;
  background: var(--white);
  border-bottom: 1px solid var(--line);
}

.tab {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.active {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

/* ---------- Content ---------- */

.content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 32px 60px;
}

.view.hidden { display: none !important; }

.toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

#search {
  width: 100%;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-family: var(--font);
  font-size: 13px;
  background: var(--white);
  box-sizing: border-box;
}
#search:focus { outline: 2px solid var(--pink-deep); }

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-search {
  flex: 1;
  min-width: 240px;
}

.filter-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}

.filter-group select {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-family: var(--font);
  font-size: 13px;
  background: var(--white);
  min-width: 150px;
}
.filter-group select:focus { outline: 2px solid var(--pink-deep); }

.btn-sort-dir {
  padding: 10px 14px;
  font-size: 13px;
  box-sizing: border-box;
}

.stats-row {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}

/* ---------- Bulk action bar ---------- */

.bulk-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--ink);
  color: var(--white);
  padding: 10px 18px;
  border-radius: 999px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.bulk-bar #bulkCount {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.bulk-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.bulk-actions select {
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid #444;
  background: #1f1f1f;
  color: var(--white);
  font-family: var(--font);
  font-size: 12.5px;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 12.5px;
}

.btn-danger {
  background: #c94b4b;
  color: var(--white);
}
.btn-danger:hover { background: #b23e3e; }

.col-check {
  width: 32px;
}
td.col-check {
  text-align: center;
}

/* ---------- Table ---------- */

.table-wrap {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: #fcfbfa;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
thead th:hover { color: var(--ink); }
thead th.col-actions { cursor: default; }

tbody tr {
  border-bottom: 1px solid var(--line);
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #fdf9f9; }
tbody tr.row-clickable { cursor: pointer; }

tbody td {
  padding: 12px 16px;
  vertical-align: middle;
}

/* The checkbox and action buttons sit inside clickable rows but shouldn't
   themselves look like part of the "click row to edit" surface. */
td.col-check, td.col-actions {
  cursor: default;
}

/* Actions column (Edit/Delete buttons) is only shown when browsing the full,
   unfiltered inventory — keeps the filtered/search view uncluttered since
   rows are click-to-edit and bulk-select still covers delete. */
#table.filters-active th.col-actions,
#table.filters-active td.col-actions {
  display: none;
}

.cell-serial {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: var(--muted);
}

.cell-model { color: var(--ink); }
.cell-email { color: var(--muted); font-size: 13px; }

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-active { background: var(--green); color: var(--green-text); }
.badge-retired { background: var(--gray); color: var(--gray-text); }
.badge-repair { background: var(--amber); color: var(--amber-text); }
.badge-storage { background: var(--pink); color: var(--pink-text); }
.badge-red { background: #f8dede; color: #a03a3a; }
.badge-blue { background: #dbe6f5; color: #3a5a8a; }
.badge-purple { background: #e6ddf2; color: #6b4a9a; }
.badge-teal { background: #d9f0ec; color: #2e7d6f; }
.badge-gray { background: var(--gray); color: var(--gray-text); }
.badge-green { background: var(--green); color: var(--green-text); }
.badge-amber { background: var(--amber); color: var(--amber-text); }
.badge-pink { background: var(--pink); color: var(--pink-text); }

.badge-replace { background: #f8dede; color: #a03a3a; font-weight: 700; }
.badge-not-needed { background: var(--gray); color: var(--gray-text); }
.badge-ok { background: var(--green); color: var(--green-text); }
.badge-unknown { background: var(--gray); color: var(--muted); }

.row-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
}
.empty-state.hidden, .hidden { display: none !important; }

/* ---------- Dashboard ---------- */

.cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--ink);
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 4px;
}

.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.dash-panel {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 16px;
}

.dash-panel h3 {
  margin: 0 0 14px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.bar-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 360px;
  overflow-y: auto;
}

.bar-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}

.bar-row .bar-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--ink);
}

.bar-row .bar-count {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.bar-track {
  grid-column: 1 / -1;
  height: 8px;
  background: var(--paper);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--ink);
  border-radius: 999px;
}
.bar-fill.pink { background: var(--pink-deep); }

.dash-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.dash-table th {
  text-align: left;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--line);
}
.dash-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
}
.dash-table tr:last-child td { border-bottom: none; }

.history-table td { vertical-align: top; }

.mini-history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 220px;
  overflow-y: auto;
  padding: 10px 12px;
  background: var(--paper);
  border-radius: 8px;
}

.mini-history-row {
  font-size: 12.5px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}
.mini-history-row:last-child { border-bottom: none; padding-bottom: 0; }

.mini-history-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
  color: var(--muted);
}

.mini-history-detail {
  color: var(--ink);
  line-height: 1.4;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 24px 0 40px;
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  background: var(--white);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.modal.modal-sm { max-width: 360px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.modal-header h2 {
  font-size: 18px;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}
.modal-close:hover { color: var(--ink); }

.modal-body { padding: 4px 24px; }

#recordForm { padding: 4px 24px 24px; }

.form-row {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.form-row input[type="checkbox"] {
  margin-right: 6px;
}

.form-row input:not([type="checkbox"]),
.form-row select,
.form-row textarea {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-family: var(--font);
  font-size: 14px;
  background: var(--paper);
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  outline: 2px solid var(--pink-deep);
  background: var(--white);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 24px 24px;
}

.modal-help {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}
.modal-help code {
  background: var(--gray);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

.field-hint {
  font-size: 12px;
  color: var(--muted);
  min-height: 14px;
}

.status-select-row {
  display: flex;
  gap: 8px;
}
.status-select-row select { flex: 1; }

.color-swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.swatch.selected {
  border-color: var(--ink);
}
.swatch-gray { background: #d9d9d9; }
.swatch-green { background: #bfe0b3; }
.swatch-amber { background: #f0d894; }
.swatch-pink { background: var(--pink-deep); }
.swatch-red { background: #e79c9c; }
.swatch-blue { background: #a9c3e8; }
.swatch-purple { background: #cdb6e8; }
.swatch-teal { background: #a3ddd0; }

.import-preview {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--paper);
  border-radius: 8px;
  font-size: 13px;
  max-height: 160px;
  overflow-y: auto;
}

#csvFile { margin: 6px 0 14px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--white);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}

@media (max-width: 720px) {
  .content { padding: 20px 16px 40px; }
  .topbar { padding: 14px 16px; }
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  tbody tr {
    padding: 12px 16px;
    border-bottom: 6px solid var(--paper);
  }
  tbody td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    border: none;
  }
  tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    font-size: 12px;
  }
  .row-actions { justify-content: flex-start; }
}
