/* Shared styles for viewer + admin + captures */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Sarabun", sans-serif;
  font-size: 14px;
  color: #222;
  background: #f4f4f4;
}

header {
  background: #1f2937;
  color: white;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
header h1 { margin: 0; font-size: 18px; font-weight: 500; }
header h1 a { color: inherit; text-decoration: none; }
.header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.nav-links { display: flex; gap: 4px; align-items: center; }
.nav-links a {
  color: #d1d5db;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 13px;
}
.nav-links a:hover, .nav-links a.active { background: #374151; color: white; }

.status {
  font-size: 12px;
  color: #aaffaa;
  margin-right: 8px;
  min-height: 14px;
}
.status.error { color: #ffaaaa; }

nav.tabs {
  display: flex;
  background: white;
  padding: 0 20px;
  border-bottom: 1px solid #ddd;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 10;
}
.tab {
  background: transparent;
  border: none;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  color: #666;
  font-size: 14px;
  font-family: inherit;
}
.tab:hover { color: #1f2937; }
.tab.active {
  color: #1f2937;
  border-bottom-color: #2563eb;
  font-weight: 500;
}

main { padding: 20px; margin: 0 auto; }

.panel { background: white; border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); padding: 20px; margin-bottom: 16px; }
.panel.hidden { display: none; }

.panel-header { margin-bottom: 16px; }
.panel-header h2 { margin: 0 0 4px 0; font-size: 18px; }
.panel-header .hint { margin: 4px 0 12px 0; color: #666; font-size: 13px; }

.panel-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search { padding: 6px 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 14px; flex: 1; max-width: 320px; }

.btn {
  padding: 6px 14px;
  border: 1px solid #ccc;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
}
.btn:hover { background: #f0f0f0; }
.btn-primary { background: #2563eb; color: white; border-color: #2563eb; }
.btn-primary:hover { background: #1d4ed8; }
.btn-danger { background: #dc2626; color: white; border-color: #dc2626; }
.btn-danger:hover { background: #b91c1c; }
.btn-icon { padding: 4px 8px; }

.table-wrap { overflow-x: auto; max-height: calc(100vh - 280px); overflow-y: auto; border: 1px solid #eee; border-radius: 4px; }

table { width: 100%; border-collapse: collapse; background: white; }
thead { position: sticky; top: 0; background: #f9fafb; z-index: 1; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid #eee; }
th { font-weight: 500; color: #555; font-size: 13px; white-space: nowrap; }
tbody tr:hover { background: #fafafa; }
td.numeric { text-align: right; font-variant-numeric: tabular-nums; }
th.center, td.center { text-align: center; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; }
td.actions button { padding: 2px 8px; margin-left: 4px; font-size: 12px; }
td.timestamp { font-size: 12px; color: #555; white-space: nowrap; }

.amount-pos { color: #15803d; font-weight: 500; font-variant-numeric: tabular-nums; }
.amount-neg { color: #dc2626; font-weight: 500; font-variant-numeric: tabular-nums; }

/* หน้า /captures + /admin/captures: ค่าทุกคอลัมน์อยู่กลาง (override .numeric) */
.captures-table th,
.captures-table td { text-align: center; font-variant-numeric: tabular-nums; }

.empty-state { padding: 40px; text-align: center; color: #999; }
.hidden { display: none !important; }

.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.checkbox-grid label { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid #eee; border-radius: 4px; cursor: pointer; }
.checkbox-grid label:hover { background: #f9fafb; }

.modifier-form { display: flex; flex-direction: column; gap: 12px; max-width: 400px; }
.modifier-form label { display: flex; align-items: center; gap: 12px; }
.modifier-form label > span:first-child { flex: 1; }
.modifier-form input { width: 100px; padding: 6px 10px; border: 1px solid #ccc; border-radius: 4px; }
.modifier-form .unit { color: #666; font-size: 13px; }

/* ─── Modal ─── */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.modal-content {
  position: relative;
  background: white;
  border-radius: 8px;
  padding: 24px;
  min-width: 400px;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-content h3 { margin: 0 0 16px 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.form-row label { font-size: 13px; color: #555; }
.form-row input,
.form-row select { padding: 8px 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 14px; font-family: inherit; }
.form-row input:focus,
.form-row select:focus { outline: 2px solid #2563eb; outline-offset: -1px; border-color: #2563eb; }
.form-row .error-msg { color: #dc2626; font-size: 12px; min-height: 14px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Viewer summary cards */
.summary-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.summary-card {
  background: white;
  border-radius: 6px;
  padding: 14px 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.summary-card .label { color: #6b7280; font-size: 12px; }
.summary-card .value { font-size: 22px; font-weight: 600; margin-top: 4px; }

/* Pagination */
.pager { display: flex; gap: 8px; align-items: center; padding: 12px 0; flex-wrap: wrap; }
.pager .info { color: #666; font-size: 13px; }
