* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Microsoft JhengHei", "PingFang TC", -apple-system, sans-serif;
  background: #111827;
  color: #f3f4f6;
}

/* ---------- 首頁 ---------- */
.home {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.home a {
  padding: 20px 40px;
  font-size: 24px;
  background: #2563eb;
  color: white;
  text-decoration: none;
  border-radius: 12px;
}

.home a.secondary {
  background: #059669;
}

.home a.tertiary {
  background: #374151;
  font-size: 18px;
  padding: 14px 32px;
}

/* ---------- 下單頁面 ---------- */
.order-page {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px;
}

.order-page h1 {
  text-align: center;
}

.page-nav {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.page-nav a {
  color: #60a5fa;
  font-size: 15px;
  text-decoration: none;
}

.page-nav a:hover {
  text-decoration: underline;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 18px;
}

.field input, .field textarea {
  width: 100%;
  padding: 12px;
  font-size: 18px;
  border-radius: 8px;
  border: none;
}

.size-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
}

.size-inputs input {
  flex: 1;
  min-width: 0;
  padding: 12px;
  font-size: 18px;
  border-radius: 8px;
  border: none;
}

.size-sep,
.size-unit {
  color: #9ca3af;
  font-size: 18px;
  flex-shrink: 0;
}

.submit-btn {
  width: 100%;
  padding: 16px;
  margin-top: 20px;
  font-size: 20px;
  font-weight: bold;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}

.submit-btn:disabled {
  background: #4b5563;
  cursor: not-allowed;
}

.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 14px 24px;
  border-radius: 8px;
  font-size: 16px;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show { opacity: 1; }
.toast.success { background: #059669; }
.toast.error { background: #dc2626; }

/* ---------- 歷史工單查詢頁面 ---------- */
.history-page {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px;
}

.history-page h1 {
  text-align: center;
}

.history-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.history-toolbar input {
  flex: 1;
  min-width: 200px;
  padding: 10px 12px;
  font-size: 16px;
  border-radius: 8px;
  border: none;
}

.history-toolbar button {
  padding: 10px 18px;
  font-size: 15px;
  font-weight: bold;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.history-toolbar button#clearBtn {
  background: #4b5563;
}

.history-table {
  table-layout: auto;
}

.history-table td,
.history-table th {
  white-space: nowrap;
}

/* ---------- 顯示器頁面 ---------- */
.display-page {
  /* 用 vw/vh 而非固定 px,確保在電視 overscan(畫面邊緣被裁切)時
     標題、按鈕、表格都還在可視範圍內,不會被螢幕邊框擋住 */
  padding: 4vh 4vw;
  min-height: 100vh;
}

.display-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.display-header h1 {
  font-size: 32px;
  margin: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.page-nav-link {
  color: #60a5fa;
  font-size: 16px;
  text-decoration: none;
}

.page-nav-link:hover {
  text-decoration: underline;
}

.font-size-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  color: #9ca3af;
}

.font-size-control button {
  padding: 6px 12px;
  border: none;
  border-radius: 8px;
  background: #374151;
  color: white;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
}

.font-size-control button:active {
  background: #4b5563;
}

.conn-status {
  font-size: 16px;
  padding: 6px 14px;
  border-radius: 20px;
  background: #dc2626;
}

.conn-status.connected {
  background: #059669;
}

.board-columns {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

.board-columns .table-scroll {
  flex: 1;
  min-width: 0;
}

.order-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: var(--board-font-size, 16px);
}

.order-table thead th {
  text-align: left;
  padding: 8px 10px;
  background: #1f2937;
  color: #9ca3af;
  font-size: 0.875em;
  font-weight: normal;
  border-bottom: 2px solid #374151;
  white-space: nowrap;
}

.order-table thead th.col-seq {
  width: 30px;
  text-align: center;
}

.order-table thead th.col-date {
  width: 16ch;
}

.order-table thead th.col-customer {
  width: 10ch;
}

.order-table thead th.col-paper-type {
  width: 16ch;
}

.order-table thead th.col-size {
  width: 16ch;
  white-space: normal;
}

.order-table thead th.col-action {
  width: 70px;
}

.order-table td.col-date,
.order-table td.col-customer,
.order-table td.col-paper-type,
.order-table td.col-size {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.order-table tbody tr {
  border-bottom: 1px solid #1f2937;
  transition: background 0.15s;
}

.order-table tbody tr:hover {
  background: #1a2333;
}

.order-table td {
  padding: 8px 10px;
  vertical-align: middle;
}

.order-table td.col-seq {
  text-align: center;
  color: #9ca3af;
  font-size: 0.875em;
}

.order-table td.col-action {
  padding: 6px 4px;
}

.row-complete-btn {
  padding: 4px 10px;
  border: none;
  border-radius: 8px;
  background: #059669;
  color: white;
  font-size: 0.875em;
  cursor: pointer;
}

.row-complete-btn:active {
  background: #047857;
}

.empty-state {
  text-align: center;
  margin-top: 100px;
  font-size: 28px;
  color: #6b7280;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-box {
  background: #1f2937;
  border-radius: 16px;
  padding: 28px 32px;
  max-width: 480px;
  width: 90%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.modal-box h2 {
  margin: 0 0 12px;
  font-size: 24px;
}

.modal-box p {
  margin: 0 0 24px;
  color: #9ca3af;
  font-size: 18px;
}

.modal-error {
  margin: -12px 0 20px;
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(220, 38, 38, 0.15);
  color: #f87171;
  font-size: 15px;
}

.modal-actions {
  display: flex;
  gap: 12px;
}

.modal-actions button {
  flex: 1;
  padding: 14px;
  font-size: 18px;
  font-weight: bold;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}

.modal-confirm-btn {
  background: #059669;
  color: white;
}

.modal-cancel-btn {
  background: #4b5563;
  color: white;
}

/* ---------- 手機板(工單看板) ---------- */
@media (max-width: 900px) {
  .display-page {
    padding: 16px;
  }

  .display-header {
    flex-wrap: wrap;
    gap: 12px;
  }

  .display-header h1 {
    font-size: 24px;
  }

  .header-right {
    flex-wrap: wrap;
    gap: 10px;
  }

  .board-columns {
    flex-direction: column;
    gap: 16px;
  }

  .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .order-table {
    font-size: 15px;
    min-width: 640px;
  }

  .row-complete-btn {
    padding: 6px 14px;
  }
}
