*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --red: #D4271B;
  --red-dark: #a81f15;
  --red-light: #fdf1f0;
  --surface: #ffffff;
  --surface-2: #f7f7f5;
  --surface-3: #f0efed;
  --border: #e3e2de;
  --border-strong: #c8c7c2;
  --text: #1a1a18;
  --text-2: #5a5a56;
  --text-3: #9a9a94;
  --green-bg: #edf7ef;
  --green-text: #1a6b2a;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  min-height: 100vh;
}

/* ── Top bar ── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 12px;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.top-bar-left img {
  height: 36px;
  width: auto;
}

.top-bar-title h1 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.top-bar-title p {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 1px;
}

.top-bar-right {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  white-space: nowrap;
  transition: background 0.15s;
}

.btn:hover { background: var(--surface-2); }

.btn-primary {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.btn-primary:hover { background: var(--red-dark); }

/* ── Summary cards ── */
.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  padding: 16px 20px 12px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

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

.stat-card .value {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

.stat-card.accent .value { color: var(--red); }
.stat-card.success .value { color: var(--green-text); }

/* ── Progress ── */
.progress-wrap {
  padding: 0 20px 4px;
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--red);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.progress-label {
  font-size: 11px;
  color: var(--text-3);
  text-align: right;
  margin-top: 3px;
  padding-right: 2px;
}

/* ── Filter bar ── */
.filter-bar {
  display: flex;
  gap: 10px;
  padding: 10px 20px 12px;
  flex-wrap: wrap;
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 160px;
}

.search-wrap svg {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 34px;
  padding: 0 10px 0 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text);
}

.search-input:focus { outline: none; border-color: var(--red); }

.dept-pills {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.dept-pill {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.dept-pill:hover { border-color: var(--border-strong); }
.dept-pill.active { background: var(--red); color: #fff; border-color: var(--red); }

/* ── Table — desktop ── */
.table-header {
  display: grid;
  grid-template-columns: 1fr 60px 60px 56px 72px;
  gap: 6px;
  padding: 6px 20px;
  background: var(--surface-3);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 62px;
  z-index: 50;
}

.table-header span {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table-header span.c { text-align: center; }
.table-header span.r { text-align: right; }

.dept-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 20px;
  background: var(--surface-3);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.dept-header .dept-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.dept-header .dept-count { font-size: 11px; color: var(--text-3); }

/* Desktop row */
.item-row {
  display: grid;
  grid-template-columns: 1fr 60px 60px 56px 72px;
  gap: 6px;
  padding: 7px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  align-items: center;
  transition: background 0.1s;
}

.item-row:hover { background: var(--surface-2); }
.item-row.counted { background: var(--green-bg); }

.item-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-meta { font-size: 10px; color: var(--text-3); margin-top: 2px; }

.num-input {
  width: 100%;
  height: 34px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.num-input:focus { outline: none; border-color: var(--red); }

.total-cell { font-size: 12px; font-weight: 600; text-align: center; color: var(--text); }
.value-cell { font-size: 12px; font-weight: 600; text-align: right; color: var(--red); }

/* ── Mobile stepper row ── */
.mobile-row { display: none; }

.empty-state {
  padding: 32px 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}

/* ── Mobile overrides ── */
@media (max-width: 600px) {
  .top-bar { padding: 10px 12px; gap: 8px; }
  .top-bar-left img { height: 28px; }
  .top-bar-title h1 { font-size: 13px; }
  .top-bar-title p { display: none; }
  .top-bar-right .btn-label { display: none; }
  .top-bar-right .btn { padding: 7px 10px; }
  /* Keep the Export/Share label visible — it's the main action */
  .top-bar-right .export-label { display: inline; }

  .summary { padding: 10px 12px 8px; gap: 6px; grid-template-columns: 1fr 1fr; }
  .stat-card { padding: 9px 10px; }
  .stat-card .value { font-size: 16px; }
  .stat-card .label { font-size: 10px; }

  .progress-wrap { padding: 0 12px 4px; }

  .filter-bar { padding: 8px 12px 10px; gap: 8px; }
  .dept-pills { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
  .dept-pills::-webkit-scrollbar { display: none; }

  .table-header { display: none; }

  /* Hide desktop rows, show mobile cards */
  .item-row { display: none; }
  .mobile-row {
    display: block;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
    overflow: hidden;
    transition: background 0.1s;
  }
  .mobile-row.counted { background: var(--green-bg); }

  .mobile-row-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
  }

  .mobile-item-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    flex: 1;
    padding-right: 8px;
  }

  .mobile-item-meta { font-size: 11px; color: var(--text-3); margin-top: 2px; }

  .mobile-value {
    font-size: 14px;
    font-weight: 700;
    color: var(--red);
    white-space: nowrap;
  }

  .mobile-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    min-width: 0;
  }

  .stepper-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
  }

  .stepper-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: center;
  }

  .stepper {
    display: flex;
    align-items: center;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: var(--surface);
    height: 50px;
    min-width: 0;
  }

  .stepper.focused { border-color: var(--red); }

  .step-btn {
    width: 40px;
    min-width: 40px;
    height: 100%;
    font-size: 22px;
    font-weight: 300;
    color: var(--text-2);
    background: var(--surface-2);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }

  .step-btn:active { background: var(--border); }

  .step-input {
    flex: 1;
    height: 100%;
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    border: none;
    background: transparent;
    min-width: 0;
    width: 0;
    padding: 0;
  }

  .step-input:focus { outline: none; }

  /* Modal full screen on mobile */
  .modal-overlay { align-items: flex-end; }
  .modal { border-radius: 16px 16px 0 0; max-width: 100%; margin: 0; }
}

/* ── Email modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 400px;
  margin: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

.modal h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

.modal p {
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 16px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 5px;
}

.form-group input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
}

.form-group input:focus { outline: none; border-color: var(--red); }

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.modal-actions .btn { flex: 1; justify-content: center; }

.status-msg {
  margin-top: 10px;
  font-size: 12px;
  text-align: center;
  min-height: 18px;
}

.status-msg.error { color: var(--red); }
.status-msg.success { color: var(--green-text); }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 300;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translateY(0); }
