/* =========================================================
   1. Variables / Base
   ========================================================= */

:root {
  font-family: Arial, Tahoma, sans-serif;
  background: #f3f4f6;
  color: #111827;

  --dark: #111827;
  --line: #e5e7eb;
  --muted: #6b7280;

  --green: #059669;
  --yellow: #d97706;
  --red: #dc2626;
  --blue: #2563eb;
  --purple: #7c3aed;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding-bottom: 76px;
  background: #f3f4f6;
  color: #111827;
}

h1 {
  margin: 0;
  font-size: 24px;
}

h2 {
  margin: 0 0 10px;
}

h3 {
  margin: 0 0 10px;
}


/* =========================================================
   2. Layout / Header / Page
   ========================================================= */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--dark);
  color: white;
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 8px #0002;
}

.sub {
  font-size: 13px;
  color: #cbd5e1;
}

.pill {
  background: #334155;
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: bold;
  font-size: 13px;
}

main {
  max-width: 1160px;
  margin: auto;
  padding: 14px;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.panel,
.hero {
  background: white;
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 5px #0001;
}

.hint,
.hint-inline {
  color: var(--muted);
  font-size: 13px;
}


/* =========================================================
   3. Forms / Inputs / Buttons
   ========================================================= */

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

.setting-grid label {
  display: grid;
  grid-template-rows: 32px auto;
  gap: 6px;
}

.label-title {
  display: flex;
  gap: 5px;
  align-items: flex-start;
}

label {
  font-weight: bold;
  font-size: 14px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 12px;
  background: white;
  font-size: 15px;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  background: #111827;
  color: white;
  font-weight: bold;
  font-size: 15px;
  cursor: pointer;
}

.secondary {
  background: #e5e7eb;
  color: #111827;
}

.danger {
  background: #dc2626;
}

.outline {
  background: white;
  color: #dc2626;
  border: 1px solid #dc2626;
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.right {
  justify-content: flex-end;
}

.checkline {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.checkline input {
  width: auto;
}


/* =========================================================
   4. Cards / KPI
   ========================================================= */

.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.card {
  background: white;
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 1px 5px #0001;
}

.card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.card b {
  font-size: 26px;
}

.card.found b {
  color: var(--green);
}

.card.warn b,
.card.out b {
  color: var(--yellow);
}

.card.dup b {
  color: var(--purple);
}

.card.manual b {
  color: var(--blue);
}

.card.invalid b {
  color: var(--red);
}

.big-action {
  font-size: 18px;
  padding: 18px;
  min-width: 180px;
}

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


/* =========================================================
   5. Setting Page
   ========================================================= */

.mini-status {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.mini-status div {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.mini-status span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.warnings {
  margin-top: 8px;
  color: #b45309;
  white-space: pre-wrap;
}

.log {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  white-space: pre-wrap;
  background: #f8fafc;
}


/* =========================================================
   6. Scan Page
   ========================================================= */

.scan-form {
  display: grid;
  grid-template-columns: 220px 1fr 140px;
  gap: 12px;
  align-items: end;
}

.barcode-input {
  font-size: 32px;
  font-weight: bold;
  letter-spacing: 2px;
  border: 2px solid #111827;
}

.scan-btn {
  height: 64px;
  background: #059669;
  font-size: 20px;
}

.scan-kpi {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.scan-kpi span {
  background: white;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 13px;
}

.latest-head,
.result-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.latest {
  border-left: 12px solid #94a3b8;
  background: #f8fafc;
  border-radius: 12px;
  padding: 12px;
  box-shadow: inset 0 0 0 1px #e2e8f0;
}

/* Give the whole Latest Result card a light status tint,
   while keeping the left bar strong for quick recognition. */
.latest.found {
  border-color: var(--green);
  background: #ecfdf5;
  box-shadow: inset 0 0 0 1px #a7f3d0;
}

.latest.duplicate {
  border-color: var(--purple);
  background: #f5f3ff;
  box-shadow: inset 0 0 0 1px #ddd6fe;
}

.latest.out {
  border-color: var(--yellow);
  background: #fffbeb;
  box-shadow: inset 0 0 0 1px #fde68a;
}

.latest.invalid {
  border-color: var(--red);
  background: #fef2f2;
  box-shadow: inset 0 0 0 1px #fecaca;
}

.kv {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #e5e7eb;
  padding: 6px 0;
  gap: 12px;
}

.kv b {
  text-align: right;
}


/* =========================================================
   7. Base Tables
   ========================================================= */

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 14px;
  vertical-align: top;
}

th {
  background: #f8fafc;
  color: #334155;
}

.reason-cell {
  white-space: normal;
  line-height: 1.35;
}


/* =========================================================
   8. Status Indicators
   ========================================================= */

.badge {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  background: #f1f5f9;
  border-radius: 999px;
  padding: 5px 9px;
  font-weight: bold;
  font-size: 12px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  background: #94a3b8;
}

.dot.found {
  background: var(--green);
}

.dot.duplicate {
  background: var(--purple);
}

.dot.out {
  background: var(--yellow);
}

.dot.invalid {
  background: var(--red);
}

.pcode {
  font-weight: bold;
}

.pcode.match {
  color: var(--green);
}

.pcode.manual {
  color: var(--blue);
}

.pcode.warn {
  color: var(--yellow);
}

.pcode.err {
  color: var(--red);
}


/* =========================================================
   9. Recent Scans
   ========================================================= */

.edit-comment {
  background: #e5e7eb;
  color: #111827;
  padding: 9px 12px;
}

.edit-comment.has-comment {
  background: #2563eb;
  color: white;
}

.recent-compact {
  display: none;
}


/* =========================================================
   10. Tabs / Filters
   ========================================================= */

.tab-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.tab {
  background: #e5e7eb;
  color: #111827;
}

.tab.active {
  background: #111827;
  color: white;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 180px;
  gap: 10px;
  margin-bottom: 10px;
}


/* =========================================================
   11. Modal
   ========================================================= */

.modal {
  position: fixed;
  inset: 0;
  background: #0008;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal.hidden {
  display: none;
}

.modal-card {
  background: white;
  border-radius: 16px;
  padding: 18px;
  max-width: 520px;
  width: 100%;
  box-shadow: 0 20px 60px #0004;
}

.comment-meta {
  background: #f8fafc;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
}


/* =========================================================
   12. Bottom Navigation
   ========================================================= */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  background: white;
  border-radius: 16px 16px 0 0;
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  z-index: 30;
  box-shadow: 0 -2px 10px #0002;
}

.nav-btn {
  background: white;
  color: #475569;
}

.nav-btn.active {
  background: #111827;
  color: white;
}


/* =========================================================
   13. Result Scroll Tables
   ========================================================= */

.table-scroll {
  width: 100%;
  max-height: 440px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
}

.table-scroll table {
  min-width: 860px;
  border-collapse: separate;
  border-spacing: 0;
}

.sticky-table thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #f8fafc;
  box-shadow: 0 1px 0 var(--line);
}

.sticky-table th:first-child,
.sticky-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 4;
  background: white;
  box-shadow: 2px 0 4px rgba(15, 23, 42, 0.08);
}

.sticky-table thead th:first-child {
  z-index: 7;
  background: #f1f5f9;
}

.sticky-table tbody tr:nth-child(even) td:first-child {
  background: #fcfcfd;
}


/* =========================================================
   14. Result Table Column Widths - Desktop
   ========================================================= */

/* Summary by Place */
#summaryPane .table-scroll table {
  min-width: 760px;
}

#summaryPane th:first-child,
#summaryPane td:first-child {
  width: 150px;
  min-width: 150px;
  max-width: 170px;
}

#summaryPane th:not(:first-child),
#summaryPane td:not(:first-child) {
  min-width: 90px;
  text-align: center;
}

/* Find result */
#findPane .table-scroll table {
  min-width: 680px;
}

#findPane th:first-child,
#findPane td:first-child {
  width: 120px;
  min-width: 120px;
  max-width: 130px;
}

#findPane th:nth-child(2),
#findPane td:nth-child(2) {
  width: 54px;
  min-width: 54px;
  max-width: 54px;
  text-align: center;
  padding-left: 6px;
  padding-right: 6px;
}

#findPane th:nth-child(3),
#findPane td:nth-child(3) {
  min-width: 80px;
}

#findPane th:nth-child(4),
#findPane td:nth-child(4) {
  min-width: 110px;
}

#findPane th:nth-child(5),
#findPane td:nth-child(5) {
  min-width: 90px;
}

#findPane th:nth-child(6),
#findPane td:nth-child(6) {
  min-width: 180px;
  white-space: normal;
}

/* All scan result */
#allPane .table-scroll table {
  min-width: 960px;
}

#allPane th:first-child,
#allPane td:first-child {
  width: 120px;
  min-width: 120px;
  max-width: 130px;
}

#allPane th:nth-child(2),
#allPane td:nth-child(2) {
  min-width: 90px;
}

#allPane th:nth-child(3),
#allPane td:nth-child(3) {
  min-width: 80px;
}

#allPane th:nth-child(4),
#allPane td:nth-child(4) {
  min-width: 110px;
}

#allPane th:nth-child(5),
#allPane td:nth-child(5) {
  min-width: 90px;
}

#allPane th:nth-child(6),
#allPane td:nth-child(6),
#allPane th:nth-child(7),
#allPane td:nth-child(7) {
  min-width: 180px;
  white-space: normal;
}

#allPane th:nth-child(8),
#allPane td:nth-child(8) {
  min-width: 90px;
}

#allPane th:nth-child(9),
#allPane td:nth-child(9) {
  min-width: 150px;
}


/* =========================================================
   15. Mobile Overrides
   ========================================================= */

@media (max-width: 760px) {
  body {
    padding-bottom: 78px;
  }

  .topbar {
    padding: 12px 14px;
  }

  h1 {
    font-size: 22px;
  }

  .sub {
    display: none;
  }

  main {
    padding: 10px;
  }

  .panel,
  .hero {
    padding: 14px;
    border-radius: 12px;
  }

  .bottom-nav {
    left: 0;
    right: 0;
    transform: none;
    border-radius: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .nav-btn {
    padding: 12px 6px;
    font-size: 13px;
  }

  .cards {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .card {
    padding: 10px;
  }

  .card b {
    font-size: 23px;
  }

  .form-grid,
  .mini-status,
  .filter-row {
    grid-template-columns: 1fr;
  }

  .home-actions {
    display: grid;
  }

  .big-action {
    width: 100%;
  }

  /* Scan page mobile */
  .scan-form {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .scan-sticky {
    position: sticky;
    top: 64px;
    z-index: 9;
    background: #f3f4f6;
    padding-bottom: 8px;
  }

  .barcode-input {
    height: 64px;
    font-size: 28px;
  }

  .scan-btn {
    width: 100%;
    height: 58px;
  }

  .scan-kpi {
    gap: 5px;
  }

  .scan-kpi span {
    font-size: 12px;
    padding: 6px 8px;
  }

  .latest-head {
    align-items: center;
  }

  .comment-btn {
    padding: 12px 14px;
  }

  /* Recent scans mobile */
  .recent-table-wrap {
    display: none;
  }

  .recent-compact {
    display: block;
  }

  .recent-row {
    display: grid;
    grid-template-columns: 12px 1fr auto;
    gap: 8px;
    align-items: start;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px;
    margin-bottom: 8px;
    background: #f8fafc;
  }

  .recent-main {
    font-weight: bold;
  }

  .recent-sub,
  .recent-reason {
    color: #475569;
    font-size: 13px;
    margin-top: 3px;
  }

  .recent-reason {
    white-space: normal;
  }

  .col-time {
    display: none;
  }

  th,
  td {
    font-size: 13px;
    padding: 9px;
  }

  /* Result tabs mobile */
  .tab-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    overflow-x: visible;
  }

  .tab {
    width: 100%;
    min-width: 0;
    padding: 11px 8px;
    font-size: 13px;
    white-space: normal;
    line-height: 1.15;
    text-align: center;
  }

  /* Result table mobile scroll */
  .table-scroll {
    max-height: 56vh;
  }

  .table-scroll table {
    min-width: 720px;
  }

  .sticky-table th,
  .sticky-table td {
    padding: 8px 10px;
    font-size: 12px;
  }

  .sticky-table th:first-child,
  .sticky-table td:first-child {
    min-width: 96px;
    max-width: 110px;
    width: 100px;
    white-space: nowrap;
  }

  .sticky-table th:not(:first-child),
  .sticky-table td:not(:first-child) {
    min-width: 80px;
  }

  .sticky-table .reason-cell {
    min-width: 160px;
    max-width: 220px;
    white-space: normal;
    line-height: 1.25;
  }

  /* Summary by Place mobile */
  #summaryPane .table-scroll table {
    min-width: 680px;
  }

  #summaryPane th:first-child,
  #summaryPane td:first-child {
    min-width: 110px;
    max-width: 120px;
    width: 110px;
  }

  #summaryPane th:not(:first-child),
  #summaryPane td:not(:first-child) {
    min-width: 72px;
    text-align: center;
  }

  /* Find result mobile */
  #findPane .table-scroll table {
    min-width: 600px;
  }

  #findPane th:first-child,
  #findPane td:first-child {
    min-width: 96px;
    max-width: 110px;
    width: 100px;
  }

  #findPane th:nth-child(2),
  #findPane td:nth-child(2) {
    width: 42px;
    min-width: 42px;
    max-width: 42px;
    padding-left: 6px;
    padding-right: 6px;
    text-align: center;
  }

  #findPane th:nth-child(3),
  #findPane td:nth-child(3) {
    min-width: 70px;
  }

  #findPane th:nth-child(4),
  #findPane td:nth-child(4) {
    min-width: 90px;
  }

  #findPane th:nth-child(5),
  #findPane td:nth-child(5) {
    min-width: 80px;
  }

  #findPane th:nth-child(6),
  #findPane td:nth-child(6) {
    min-width: 160px;
  }

  /* All scan result mobile */
  #allPane .table-scroll table {
    min-width: 860px;
  }

  #allPane th:first-child,
  #allPane td:first-child {
    min-width: 96px;
    max-width: 110px;
    width: 100px;
  }

  #allPane th:nth-child(6),
  #allPane td:nth-child(6),
  #allPane th:nth-child(7),
  #allPane td:nth-child(7) {
    min-width: 160px;
  }
}

/* =========================================================
   Row Selection Highlight
   Click/tap row highlight for Result tables
   ========================================================= */

.sticky-table tbody tr.selected-row td {
  background: #bfdbfe;
}

.sticky-table tbody tr.selected-row td:first-child {
  background: #bfdbfe;
  box-shadow: 2px 0 6px rgba(15, 23, 42, 0.18);
}

/* Hover highlight for PC */
.sticky-table tbody tr:hover td {
  background: #dbeafe;
}

.sticky-table tbody tr:hover td:first-child {
  background: #dbeafe;
}

/* =========================================================
   V8 Intranet Server Status
   ========================================================= */
.server-status {
  min-height: 52px;
  border-left: 6px solid #94a3b8;
}
.server-status.ok {
  background: #ecfdf5;
  border-color: #059669;
  color: #065f46;
}
.server-status.error {
  background: #fef2f2;
  border-color: #dc2626;
  color: #991b1b;
}


/* =========================================================
   V8 Cloud Sync — Cloud Master
   ========================================================= */
.cloud-status-grid b {
  overflow-wrap: anywhere;
}

.upload-key-row {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  max-width: 520px;
}

.upload-key-row input {
  width: 100%;
}

.danger-zone {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

.server-status.ok {
  border-left: 4px solid var(--green);
}

.server-status.error {
  border-left: 4px solid var(--red);
}


/* =========================================================
   V8.1 Cloud Sync — Central Scan
   ========================================================= */
.central-scan-filters {
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  margin-top: 10px;
}

@media (max-width: 760px) {
  .central-scan-filters {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 460px) {
  .central-scan-filters {
    grid-template-columns: 1fr;
  }
}
