/* ============================================================
   Cycle Count — Tool-specific styles
   Extends ../styles.css
   ============================================================ */

/* ── Local tokens ── */
:root {
  --surface:        #ffffff;
  --surface-2:      #f8f5f0;
  --border:         rgba(15, 15, 15, 0.10);
  --border-strong:  rgba(15, 15, 15, 0.20);
  --danger:         #a32d2d;
  --danger-bg:      #fcebeb;
  --success-bg:     #e8f5ec;
  --warning-bg:     #fff3e0;
  --complete-bg:    #eef6f0;
}

/* ── Single-column layout ── */
main {
  display: block;
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

/* ── Top bar (breadcrumb + user) ── */
.top-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--mid);
  flex-wrap: wrap;
}

.top-bar a {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
}

.top-bar a:hover { text-decoration: underline; }
.top-bar .sep { opacity: 0.4; }
.top-bar .user-pill {
  margin-left: auto;
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 0.68rem;
}

/* ── Page title row ── */
.page-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 1.5rem;
}

.page-title {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.project-number {
  color: var(--mid);
  font-weight: 600;
}

/* ── Cards / panels ── */
.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mid);
  margin-bottom: 0.75rem;
}

/* ── Form inputs ── */
.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 1rem;
}

.field-group label {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--mid);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.field-group input,
.field-group textarea,
.field-group select {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
  box-sizing: border-box;
}

.field-group textarea { resize: vertical; min-height: 72px; }
.field-group input:focus,
.field-group textarea:focus,
.field-group select:focus { border-color: var(--accent); }

/* Combobox (datalist) wrapper */
.combo-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
}

.combo-wrap input { flex: 1; }

/* ── Project list table ── */
.projects-table-wrap {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  overflow: auto;
  margin-bottom: 1.5rem;
}

.projects-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.projects-table thead th {
  background: var(--ink);
  color: var(--paper);
  padding: 10px 14px;
  text-align: left;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  white-space: nowrap;
}

.projects-table tbody tr {
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  transition: background 0.08s;
}

.projects-table tbody tr:last-child { border-bottom: none; }
.projects-table tbody tr:hover td { background: var(--accent-light); }

.projects-table td {
  padding: 10px 14px;
  vertical-align: middle;
}

.td-mono { font-family: var(--mono); font-size: 0.78rem; }
.td-mid  { color: var(--mid); font-size: 0.78rem; }

/* ── Status badge ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 2px;
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.badge-open     { background: var(--warning-bg);  color: #7a4f00; }
.badge-complete { background: var(--complete-bg);  color: var(--green); }
.badge-partial  { background: var(--accent-light); color: var(--accent); }

/* ── Location list ── */
.loc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface);
  margin-bottom: 1.25rem;
}

.loc-list li {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  transition: background 0.08s;
  gap: 12px;
}

.loc-list li:last-child { border-bottom: none; }
.loc-list li:hover { background: var(--accent-light); }
.loc-list li.complete { background: var(--complete-bg); }

.loc-code {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.82rem;
  min-width: 130px;
}

.loc-label {
  font-size: 0.8rem;
  color: var(--mid);
  flex: 1;
}

.loc-counted-by {
  font-size: 0.72rem;
  color: var(--mid);
  white-space: nowrap;
}

/* ── Location header bar (sticky during counting) ── */
.loc-header-bar {
  background: var(--ink);
  color: var(--paper);
  border-radius: 4px;
  padding: 12px 16px;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.loc-header-code {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
}

.loc-header-label {
  font-size: 0.82rem;
  opacity: 0.75;
  flex: 1;
}

.loc-header-status {
  margin-left: auto;
}

.loc-header-meta {
  font-size: 0.72rem;
  opacity: 0.65;
  width: 100%;
  margin-top: -8px;
}

/* ── Upload zone ── */
.upload-zone {
  border: 2px dashed var(--rule);
  border-radius: 4px;
  padding: 2.5rem 2rem;
  text-align: center;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 1rem;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}

.upload-icon {
  width: 40px;
  height: 40px;
  margin: 0 auto 1rem;
  background: var(--surface-2);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--rule);
}

.upload-icon svg {
  width: 20px;
  height: 20px;
  stroke: var(--accent);
  fill: none;
  stroke-width: 2;
}

.upload-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.upload-hint {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--mid);
}

.upload-or {
  text-align: center;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--mid);
  margin: 0.75rem 0;
}

#csvFileInput { display: none; }

/* ── Count table ── */
.count-table-wrap {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  overflow-x: auto;
  margin-bottom: 1.25rem;
}

.count-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.count-table thead th {
  background: var(--ink);
  color: var(--paper);
  padding: 10px 12px;
  text-align: left;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.count-table thead th:hover { color: var(--accent-light); }
.count-table thead th .sort-indicator { font-size: 0.58rem; margin-left: 4px; opacity: 0.4; }
.count-table thead th.sorted .sort-indicator { opacity: 1; color: var(--accent-light); }

/* Actions column: not sortable */
.count-table thead th.col-actions { cursor: default; }
.count-table thead th.col-actions:hover { color: var(--paper); }

.count-table tbody tr {
  border-bottom: 1px solid var(--rule);
  transition: background 0.08s;
}

.count-table tbody tr:last-child { border-bottom: none; }
.count-table tbody tr:hover td { background: #faf7f3; }

.count-table td {
  padding: 8px 12px;
  vertical-align: middle;
}

.count-table .td-sku   { font-family: var(--mono); font-weight: 600; font-size: 0.8rem; }
.count-table .td-desc  { color: var(--mid); font-size: 0.78rem; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count-table .td-lot   { font-family: var(--mono); font-size: 0.75rem; }
.count-table .td-qty   { font-family: var(--mono); font-size: 0.8rem; text-align: right; }
.count-table .td-count { font-family: var(--mono); font-size: 0.8rem; }
.count-table .td-counted-lot { font-family: var(--mono); font-size: 0.75rem; }

/* Physical count input */
.count-input {
  width: 70px;
  padding: 5px 8px;
  font-family: var(--mono);
  font-size: 0.8rem;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--surface);
  color: var(--ink);
  text-align: right;
  outline: none;
  transition: border-color 0.15s;
}

.count-input:focus { border-color: var(--accent); }
.count-input[readonly] { background: var(--surface-2); color: var(--mid); cursor: default; }

/* Variance column */
.td-variance {
  font-family: var(--mono);
  font-size: 0.8rem;
  text-align: right;
}

.variance-zero    { color: var(--green); }
.variance-nonzero { color: var(--danger); font-weight: 700; }
.variance-blank   { color: var(--mid); }

/* Row action buttons */
.row-actions { display: flex; gap: 6px; align-items: center; }

.btn-row {
  padding: 4px 9px;
  font-family: var(--sans);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 2px;
  cursor: pointer;
  border: 1px solid;
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
}

.btn-edit   { background: transparent; border-color: var(--rule);   color: var(--mid); }
.btn-edit:hover  { border-color: var(--accent); color: var(--accent); }
.btn-print  { background: transparent; border-color: var(--rule);   color: var(--mid); }
.btn-print:hover { border-color: var(--ink);    color: var(--ink); }
.btn-delete { background: transparent; border-color: transparent;   color: var(--mid); }
.btn-delete:hover { color: var(--danger); }

/* ── Complete location bar ── */
.complete-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: 4px;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.complete-bar .note {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--mid);
  flex: 1;
}

/* ── Modal overlay ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 15, 0.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

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

.modal-title {
  font-size: 1rem;
  font-weight: 800;
  margin-bottom: 1rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 1.25rem;
}

/* ── Corrections table ── */
.corrections-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.corrections-table thead th {
  background: var(--ink);
  color: var(--paper);
  padding: 9px 12px;
  text-align: left;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.corrections-table tbody tr {
  border-bottom: 1px solid var(--rule);
  transition: background 0.08s;
}

.corrections-table tbody tr.corrected { opacity: 0.45; text-decoration: line-through; }
.corrections-table td { padding: 8px 12px; vertical-align: middle; }
.corrections-table .td-mono { font-family: var(--mono); font-size: 0.75rem; }

.correction-type {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 2px;
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.ct-lot   { background: var(--warning-bg); color: #7a4f00; }
.ct-qty   { background: var(--danger-bg);  color: var(--danger); }
.ct-extra { background: var(--complete-bg); color: var(--green); }
.ct-zero  { background: #f0f0f0; color: var(--mid); }

/* ── Printer status (reused from inventory-labels) ── */
.printer-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--mid);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mid);
  flex-shrink: 0;
}

.status-dot.connected { background: var(--green); }
.status-dot.error     { background: var(--danger); }

#printerSelect {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 3px 6px;
  outline: none;
  cursor: pointer;
}

#printerSelect:focus { border-color: var(--accent); }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 10px 16px;
  border-radius: 2px;
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  z-index: 1000;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  max-width: 320px;
}

#toast.show    { opacity: 1; transform: translateY(0); }
#toast.success { background: var(--success-bg); color: var(--green);  border: 1px solid #b6dfc0; }
#toast.error   { background: var(--danger-bg);  color: var(--danger); border: 1px solid #f0c0c0; }
#toast.info    { background: var(--warning-bg); color: #6d4400;       border: 1px solid #ffcc80; }

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--rule);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-state {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--mid);
  font-family: var(--mono);
  font-size: 0.78rem;
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--mid);
}

.empty-state h3 { font-size: 1rem; margin-bottom: 0.5rem; color: var(--ink); }
.empty-state p  { font-family: var(--mono); font-size: 0.72rem; }

/* ── Responsive ── */
@media (max-width: 1024px) {
  .count-table .col-desc,      .count-table .td-desc      { display: none; }
  .count-table .col-lot,       .count-table .td-lot       { display: none; }
  .btn-sm { padding: 8px 12px; min-height: 36px; }
  .count-input { height: 40px; font-size: 1rem; }
}

@media (max-width: 760px) {
  main { padding: 1rem; }
  .count-table .col-counted-lot, .count-table .td-counted-lot { display: none; }
  .count-table .col-packem-qty,  .count-table .td-packem-qty  { display: none; }
  .page-title { font-size: 1.2rem; }
  .loc-header-bar { flex-direction: column; align-items: flex-start; gap: 6px; }
}
