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

:root {
  --color-primary:        #0045DA;
  --color-secondary:      #0D0D0D;
  --color-accent-navy:    #050599;
  --color-accent-gray:    #C9C9C9;
  --color-accent-orange:  #FB4F14;
  --color-accent-teal:    #00BAA7;
}

body {
  font-family: 'Roboto', 'Segoe UI', Arial, sans-serif;
  background: #f4f5f7;
  color: var(--color-secondary);
  min-height: 100vh;
}

header {
  background: #fff;
  border-bottom: 3px solid var(--color-primary);
  padding: 14px 32px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 24px;
  text-decoration: none;
}

.header-logo {
  height: 44px;
  width: auto;
}

header h1 {
  color: var(--color-primary);
  font-family: 'Mohave', Arial, sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.container {
  max-width: 860px;
  margin: 36px auto;
  padding: 0 20px;
}

.container-wide {
  max-width: 1200px;
  margin: 36px auto;
  padding: 0 20px;
}

form {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  padding: 32px 36px;
}

.section-title {
  font-family: 'Mohave', Arial, sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-primary);
  border-bottom: 2px solid var(--color-primary);
  padding-bottom: 6px;
  margin: 28px 0 18px;
}

.section-title:first-child {
  margin-top: 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 24px;
}

.grid-3 {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 16px 24px;
}

.full-width {
  grid-column: 1 / -1;
}

label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #555;
  margin-bottom: 5px;
}

label .required {
  color: var(--color-accent-orange);
  font-weight: 700;
}

label .optional {
  font-size: 0.68rem;
  font-weight: 400;
  color: #999;
  text-transform: none;
  letter-spacing: 0;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--color-accent-gray);
  border-radius: 5px;
  font-size: 0.95rem;
  color: var(--color-secondary);
  background: #fafafa;
  transition: border-color 0.15s;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
  background: #fff;
}

.file-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.file-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #555;
}

.file-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
}

input[type="file"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px dashed var(--color-accent-gray);
  border-radius: 5px;
  font-size: 0.88rem;
  background: #fafafa;
  cursor: pointer;
}

input[type="file"]:focus {
  outline: none;
  border-color: var(--color-primary);
}

.result-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.result-option {
  position: relative;
  height: 100%;
}

.result-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.result-option label {
  display: flex;
  align-items: center;
  height: 100%;
  gap: 10px;
  padding: 12px 14px;
  border: 2px solid var(--color-accent-gray);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
  color: #444;
  background: #fafafa;
  transition: border-color 0.15s, background 0.15s;
}

.result-option input[type="radio"]:checked + label {
  background: #f0f4ff;
}

.result-option.green input[type="radio"]:checked + label { border-color: #00aa00; color: #007700; }
.result-option.yellow input[type="radio"]:checked + label { border-color: #d4a000; color: #8a6500; }
.result-option.red input[type="radio"]:checked + label { border-color: var(--color-accent-orange); color: var(--color-accent-orange); }

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot.green { background: #00aa00; }
.dot.yellow { background: #d4a000; }
.dot.red { background: var(--color-accent-orange); }

.submit-row {
  margin-top: 28px;
  text-align: right;
}

button[type="submit"] {
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 12px 32px;
  font-size: 1rem;
  font-weight: 700;
  font-family: 'Mohave', Arial, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s;
}

button[type="submit"]:hover {
  background: var(--color-accent-navy);
}

button[type="submit"]:active {
  background: var(--color-secondary);
}

.hidden { display: none !important; }

/* ── Home page ── */
.home-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.report-count {
  font-size: 0.85rem;
  color: #666;
}

.btn-primary {
  display: inline-block;
  background: var(--color-primary);
  color: #fff;
  padding: 10px 22px;
  border-radius: 6px;
  font-family: 'Mohave', Arial, sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  transition: background 0.15s;
}

.btn-primary:hover { background: var(--color-accent-navy); }

.report-table-wrap {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  overflow: hidden;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.report-table thead {
  background: var(--color-primary);
  color: #fff;
}

.report-table th {
  font-family: 'Mohave', Arial, sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 13px 16px;
  text-align: left;
}

.report-table td {
  padding: 12px 16px;
  border-bottom: 1px solid #f0f0f0;
  color: var(--color-secondary);
}

.report-table tbody tr:last-child td { border-bottom: none; }

.report-table tbody tr:hover { background: #f7f9ff; }

.mono { font-family: 'Roboto Mono', monospace; font-size: 0.85rem; }

.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
}

.result-badge .badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.result-green { background: #e6f9e6; color: #007700; }
.result-green .badge-dot { background: #00aa00; }

.result-yellow { background: #fff8e0; color: #8a6500; }
.result-yellow .badge-dot { background: #d4a000; }

.result-red { background: #fff0eb; color: var(--color-accent-orange); }
.result-red .badge-dot { background: var(--color-accent-orange); }

.dash-result-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  color: #555;
}

.result-green-dot  { background: #00aa00; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.result-yellow-dot { background: #d4a000; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.result-red-dot    { background: var(--color-accent-orange); width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.dash-result-row.active .dash-result-label { color: #fff; }
.dash-result-row.active .result-green-dot,
.dash-result-row.active .result-yellow-dot,
.dash-result-row.active .result-red-dot    { background: #fff; }

.pagination-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 12px 0 4px;
}

.page-size-wrap {
  justify-self: end;
  min-width: 0;
  font-size: 0.88rem;
  color: #555;
}

.page-size-wrap select {
  margin: 0;
  padding: 3px 6px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.88rem;
}

.page-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-self: center;
}

.page-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.88rem;
  color: #555;
  padding: 2px 4px;
}

.page-btn:hover:not([disabled]) {
  color: var(--color-secondary);
}

.page-btn.active {
  font-weight: 700;
  color: var(--color-secondary);
}

.page-btn[disabled] {
  opacity: 0.3;
  cursor: default;
}

.page-ellipsis {
  font-size: 0.88rem;
  color: #aaa;
}

.btn-view {
  display: inline-block;
  padding: 5px 14px;
  border: 1.5px solid var(--color-primary);
  border-radius: 5px;
  color: var(--color-primary);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.btn-view:hover {
  background: var(--color-primary);
  color: #fff;
}

.action-cell {
  display: flex;
  gap: 8px;
  align-items: center;
}

.empty-state {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  padding: 60px 32px;
  text-align: center;
  color: #888;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* ── Dashboard ── */
.dashboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.dash-card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  padding: 20px 24px;
}

.dash-card-title {
  font-family: 'Mohave', Arial, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-primary);
  margin-bottom: 14px;
}

.dash-total {
  font-size: 2.6rem;
  font-weight: 700;
  color: var(--color-secondary);
  line-height: 1;
  margin-bottom: 12px;
}

.dash-by-location {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dash-loc-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  color: #555;
  cursor: pointer;
  padding: 2px 6px;
  margin: 0 -6px;
  border-radius: 4px;
  transition: background 0.15s;
}

.dash-loc-row:hover {
  background: #f0f4ff;
  color: #333;
}

.dash-loc-row.active {
  background: var(--color-secondary);
  color: #fff;
}

.dash-loc-row.active .dash-loc-count {
  color: #fff;
}

.dash-loc-count {
  font-weight: 700;
  color: var(--color-secondary);
}

.dash-results {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dash-result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  padding: 3px 6px;
  margin: 0 -6px;
  border-radius: 4px;
  transition: background 0.15s;
}

.dash-result-row:hover {
  background: #f0f4ff;
}

.dash-result-row.active {
  background: var(--color-secondary);
}

.dash-result-row.active .dash-result-count {
  color: #fff;
}

.dash-result-count {
  font-weight: 700;
  font-size: 1rem;
  color: var(--color-secondary);
}

.dash-recent {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dash-recent-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.85rem;
}

.dash-recent-left {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  min-width: 0;
}

.dash-recent-num {
  color: var(--color-primary);
  font-size: 0.8rem;
  flex-shrink: 0;
  text-decoration: none;
}

.dash-recent-num:hover {
  text-decoration: underline;
}

.dash-recent-customer {
  color: #444;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dash-recent-serial {
  font-size: 0.78rem;
  color: #888;
  flex-shrink: 0;
}

.dash-sep {
  color: #ccc;
  flex-shrink: 0;
}

.dash-result-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.result-dot-green  { background: #00aa00; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.result-dot-yellow { background: #d4a000; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.result-dot-red    { background: var(--color-accent-orange); width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.dash-empty {
  font-size: 0.85rem;
  color: #999;
}

/* ── Filter bar ── */
.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.filter-bar input[type="text"] {
  flex: 1;
  min-width: 0;
}

.filter-bar select {
  width: auto;
  flex-shrink: 0;
}

.filter-date-range {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.filter-date-range input[type="date"] {
  width: auto;
  padding: 9px 10px;
}

.date-range-sep {
  color: #999;
  font-size: 0.9rem;
}

/* ── Create form header back link ── */
.header-back {
  margin-left: auto;
  color: var(--color-primary);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  padding: 7px 14px;
  border: 1.5px solid var(--color-primary);
  border-radius: 5px;
  transition: background 0.15s, color 0.15s;
}

.header-back:hover {
  background: var(--color-primary);
  color: #fff;
}

.image-input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.source-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--color-accent-gray);
  border-radius: 5px;
  overflow: hidden;
  width: fit-content;
}

.source-btn {
  background: #fafafa;
  border: none;
  padding: 7px 14px;
  font-size: 0.8rem;
  font-family: 'Roboto', sans-serif;
  font-weight: 500;
  color: #666;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.source-btn:not(:last-child) {
  border-right: 1px solid var(--color-accent-gray);
}

.source-btn.active {
  background: var(--color-primary);
  color: #fff;
}

.cam-video,
.cam-preview {
  width: 100%;
  border-radius: 5px;
  border: 1px solid var(--color-accent-gray);
  background: #000;
}

.cam-controls {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.cam-btn {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 5px;
  font-size: 0.88rem;
  font-family: 'Roboto', sans-serif;
  font-weight: 600;
  cursor: pointer;
  background: var(--color-primary);
  color: #fff;
  transition: background 0.15s;
}

.cam-btn:hover { background: var(--color-accent-navy); }

/* ── Preview chart ── */
.chart-container {
  padding: 16px 20px 8px;
  border-bottom: 1px solid #f0f0f0;
}

/* ── Excel preview ── */
.excel-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.excel-input-row input[type="file"] {
  flex: 1;
  min-width: 0;
}

.stab-status {
  font-size: 0.78rem;
  color: #999;
  margin-top: 4px;
  display: block;
}

.stab-status.stab-set {
  color: #007700;
  font-weight: 600;
}

.btn-preview {
  flex-shrink: 0;
  padding: 8px 18px;
  background: transparent;
  border: 1.5px solid var(--color-primary);
  border-radius: 5px;
  color: var(--color-primary);
  font-size: 0.85rem;
  font-family: 'Roboto', sans-serif;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn-preview:hover {
  background: var(--color-primary);
  color: #fff;
}

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

.modal {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  width: 100%;
  max-width: 560px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 2px solid var(--color-primary);
}

.modal-header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.modal-subtitle {
  font-size: 0.78rem;
  color: #999;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  font-family: 'Roboto', sans-serif;
}

.modal-title {
  font-family: 'Mohave', Arial, sans-serif;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: #888;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

.modal-close:hover { color: var(--color-secondary); }

.modal-body {
  overflow-y: auto;
  padding: 0;
}

.modal-note {
  padding: 10px 20px;
  font-size: 0.8rem;
  color: #666;
  border-top: 1px solid #f0f0f0;
  font-style: italic;
}

.modal-loading {
  padding: 32px;
  text-align: center;
  color: #888;
  font-size: 0.9rem;
}

.modal-error {
  padding: 16px 20px;
  color: var(--color-accent-orange);
  font-size: 0.9rem;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.preview-table thead {
  background: var(--color-primary);
  color: #fff;
  position: sticky;
  top: 0;
}

.preview-table th {
  font-family: 'Mohave', Arial, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 10px 16px;
  text-align: left;
}

.preview-table td {
  padding: 9px 16px;
  border-bottom: 1px solid #f0f0f0;
}

.preview-table tbody tr:last-child td { border-bottom: none; }
.preview-table tbody tr:hover { background: #eef2ff; }
.preview-table tbody tr.selected-row { background: #d0dbff; }
.preview-table tbody tr.selected-row td { font-weight: 600; }

.preview-snapshot-row { cursor: pointer; }
.preview-detail-row { cursor: pointer; background: #fafafa; }
.preview-detail-row td:nth-child(2) { padding-left: 32px; }

.expand-col { width: 40px; }

.preview-snapshot-row td:first-child {
  cursor: pointer;
  text-align: center;
  padding: 0;
}

.expand-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 36px;
  font-size: 1rem;
  color: var(--color-primary);
  user-select: none;
}

/* ── Error banner ── */
.error-banner {
  background: #fff2ee;
  border: 1px solid var(--color-accent-orange);
  color: var(--color-accent-orange);
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 20px;
  font-size: 0.9rem;
}

.warning-banner {
  background: #fffbe6;
  border: 1px solid #d4a000;
  color: #7a5800;
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.mobile-divider { display: none; }

/* ── Responsive ── */
@media (max-width: 768px) {
  header { padding: 12px 16px; }

  .container-wide { padding: 0 12px; margin: 16px auto; }

  /* Dashboard: stack cards */
  .dashboard { grid-template-columns: 1fr; }

  /* Filter bar: wrap and stretch each control */
  .filter-bar { flex-wrap: wrap; }
  .filter-bar input[type="text"],
  .filter-bar select { width: 100%; flex-shrink: 1; }
  .filter-date-range { width: 100%; }
  .filter-date-range input[type="date"] { flex: 1; }

  /* Filter divider */
  .mobile-divider {
    display: block;
    border: none;
    border-top: 1px solid #e0e0e0;
    margin: 12px 0;
  }

  /* Table → cards */
  .report-table-wrap { background: transparent; box-shadow: none; border-radius: 0; overflow: visible; }

  .report-table thead { display: none; }

  .report-table tbody tr {
    display: block;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    margin-bottom: 12px;
    overflow: hidden;
  }

  .report-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid #f0f0f0;
  }

  .report-table tbody tr td:last-child { border-bottom: none; }
  .report-table tbody tr:last-child td { border-bottom: 1px solid #f0f0f0; }
  .report-table tbody tr:last-child td:last-child { border-bottom: none; }
  .report-table tbody tr:hover { background: #fff; }

  .report-table td::before {
    content: attr(data-label);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #999;
    flex-shrink: 0;
    margin-right: 12px;
  }

  .report-table td.action-cell {
    justify-content: flex-end;
    gap: 8px;
  }
  .report-table td.action-cell::before { display: none; }

  /* Pagination: hide empty spacer, left-align controls */
  .pagination-bar { grid-template-columns: 1fr auto; }
  .pagination-bar > div:first-child { display: none; }

  /* Create page */
  .container { padding: 0 12px; margin: 16px auto; }

  form { padding: 20px 16px; }

  .grid-2 { grid-template-columns: 1fr; }

  .result-options { grid-template-columns: 1fr; }

  .excel-input-row { flex-wrap: wrap; }
  .excel-input-row input[type="file"] { width: 100%; }
  .excel-input-row .btn-preview { width: 100%; }

  .submit-row { text-align: center; }
  button[type="submit"] { width: 100%; }

  /* Modal: slide up from bottom on mobile */
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { border-radius: 12px 12px 0 0; max-height: 90vh; width: 100%; max-width: 100%; }
}
