:root {
  --primary: #0052cc;
  --primary-hover: #0747a6;
  --success: #2e7d32;
  --success-hover: #1b5e20;
  --danger: #d32f2f;
  --danger-hover: #b71c1c;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e0e4eb;
  --text: #172b4d;
  --text-muted: #6b778c;
  --radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.4;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  background-color: #0c2340;
  color: #fff;
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.badge-portal {
  background: #0052cc;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 12px;
  text-transform: uppercase;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.live-clock {
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  color: #b3c5e6;
}
.btn-settings {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: background 0.2s;
}
.btn-settings:hover { background: rgba(255,255,255,0.22); }

.container {
  max-width: 1400px;
  width: 100%;
  margin: 18px auto;
  padding: 0 16px;
  display: grid;
  grid-template-columns: 440px 1fr;
  gap: 20px;
  flex: 1;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  display: flex;
  flex-direction: column;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 1.1rem; font-weight: 700; }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.stat-box {
  background: #ebf3ff;
  border: 1px solid #cce0ff;
  padding: 8px;
  border-radius: 6px;
  text-align: center;
}
.stat-box.active-count { background: #e6f9ed; border-color: #b7ebd0; }
.stat-box.out-count { background: #fdf5e6; border-color: #fae3b3; }
.stat-val { font-size: 1.25rem; font-weight: 800; color: #0c2340; }
.stat-lbl { font-size: 0.68rem; text-transform: uppercase; font-weight: 600; color: var(--text-muted); }

/* Form Styles */
.form-group { margin-bottom: 11px; position: relative; }
.form-row { display: flex; gap: 10px; }
.form-row .form-group { min-width: 0; }
.flex-3 { flex: 3; }
.flex-1 { flex: 1; }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #344563;
  margin-bottom: 4px;
}
.optional-tag { font-weight: normal; color: var(--text-muted); font-size: 11px; }
input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  font-size: 14px;
  border: 1px solid #c1c7d0;
  border-radius: 5px;
  outline: none;
  transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0,82,204,0.2);
}
textarea {
  resize: vertical;
  min-height: 48px;
  font-family: inherit;
}

/* Autocomplete */
.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1px solid var(--primary);
  border-radius: 0 0 6px 6px;
  max-height: 180px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  display: none;
}
.autocomplete-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  flex-direction: column;
}
.autocomplete-item:hover { background-color: #ebf3ff; }
.autocomplete-item strong { color: #0052cc; }
.autocomplete-sub { font-size: 11px; color: var(--text-muted); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: 5px;
  border: none;
  cursor: pointer;
  transition: background 0.2s;
}
.btn:active { opacity: 0.9; }
.btn-primary { background: var(--primary); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; width: 100%; }
.btn-success:hover { background: var(--success-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-outline {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 12px;
  font-size: 12.5px;
}
.btn-outline:hover { background: #f4f6f9; }

.btn-reset {
  background: #f4f6f9;
  border: 1px solid #c1c7d0;
  color: #42526e;
  width: 100%;
  margin-top: 8px;
}
.btn-reset:hover {
  background: #ebecf0;
  color: #172b4d;
}

/* Scanner Viewport */
#reader {
  width: 100%;
  margin-bottom: 12px;
  border-radius: 6px;
  overflow: hidden;
  display: none;
  border: 2px dashed #0052cc;
}

.status-badge {
  display: none;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 10px;
}
.status-found { background: #d4edda; color: #155724; }
.status-new { background: #fff3cd; color: #856404; }

/* Search Toolbar */
.table-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  align-items: center;
}
.search-box {
  flex: 1;
  padding: 8px 12px;
  font-size: 13.5px;
}

/* Table */
.table-wrapper {
  flex: 1;
  overflow-x: auto;
  max-height: 560px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
th {
  background: #fafbfc;
  padding: 9px 10px;
  font-weight: 600;
  color: #5e6c84;
  text-align: left;
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  color: #172b4d;
  white-space: nowrap;
}
tbody tr { cursor: pointer; user-select: none; transition: background 0.15s; }
tbody tr:hover { background-color: #ebf3ff; }

/* Status Badges */
.badge-in { background: #e6f9ed; color: #1b5e20; border: 1px solid #b7ebd0; font-weight: 700; padding: 2px 6px; border-radius: 4px; font-size: 11px; }
.badge-out { background: #f8f9fa; color: #6c757d; border: 1px solid #dee2e6; font-weight: 600; padding: 2px 6px; border-radius: 4px; font-size: 11px; }
.badge-overstay { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; font-weight: 700; padding: 2px 6px; border-radius: 4px; font-size: 11px; }

.badge-card-active { background: #e6f9ed; color: #1b5e20; font-weight:700; padding: 2px 6px; border-radius: 4px; font-size: 11px; }
.badge-card-missing { background: #ffebe6; color: #de350b; font-weight:700; padding: 2px 6px; border-radius: 4px; font-size: 11px; }

/* Card Add Box in Settings */
.card-add-box {
  background: #f8f9fa;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 12px;
}

/* Modals */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  padding: 16px;
}
.modal-card {
  background: #fff;
  border-radius: 10px;
  max-width: 520px;
  width: 100%;
  padding: 22px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  animation: fadeIn 0.15s ease-out;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-card.wide { max-width: 860px; }
@keyframes fadeIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 14px;
}
.modal-detail-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px dashed #f0f0f0;
  font-size: 13.5px;
}
.modal-detail-label { color: var(--text-muted); font-weight: 600; }
.modal-detail-value { font-weight: 700; text-align: right; }
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

/* Admin Tabs */
.admin-nav-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.tab-btn {
  background: #f4f6f9;
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
}
.tab-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

@media (max-width: 960px) {
  .container { grid-template-columns: 1fr; margin: 10px auto; padding: 0 10px; }
  .card { padding: 14px; }
  .table-wrapper { max-height: 380px; }
  .header-right { gap: 8px; }
}

/* 🌟 Full-bleed edge-to-edge layout */
body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

.container {
  max-width: 100% !important;
  width: 100% !important;
  margin: 12px 0 !important;
  padding: 0 12px !important; /* Only 12px gap from the left and right monitor edges */
  box-sizing: border-box !important;
  display: grid !important;
  /* Left Registration column expanded (420px to 26%), Right Live Log takes all remaining space */
  grid-template-columns: minmax(410px, 26%) minmax(0, 1fr) !important;
  gap: 14px !important;
  align-items: start;
}

.card {
  width: 100% !important;
  box-sizing: border-box !important;
}

.table-wrapper,
.table-wrapper table {
  width: 100% !important;
}

/* Category Badge in Live Table */
.badge-category {
  display: inline-block;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  background: #eef2f6;
  color: #334155;
  border: 1px solid #cbd5e1;
  white-space: nowrap;
}

@media (max-width: 1024px) {
  .container {
    grid-template-columns: 1fr !important;
    padding: 0 10px !important;
  }
}
