/* Reset & base */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #1f2937;
  background: #f3f4f6;
}
.hidden { display: none !important; }
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* Top nav */
.topnav {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: #1e293b;
  color: #f8fafc;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}
.topnav-brand { font-weight: 600; font-size: 16px; }
.topnav-links { display: flex; gap: 8px; flex: 1; }
.topnav-links a {
  color: #cbd5e1;
  padding: 6px 12px;
  border-radius: 6px;
  transition: background 0.15s;
}
.topnav-links a:hover { background: #334155; text-decoration: none; }
.topnav-links a.active { background: #3b82f6; color: #fff; }
.topnav-user { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.topnav-user #topnav-username { color: #cbd5e1; }
.topnav-user a { color: #f87171; }
.topnav-user #topnav-settings { color: #cbd5e1; font-size: 16px; }
.topnav-user #topnav-settings:hover { color: #fff; text-decoration: none; }

/* Main container */
main {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 24px;
}
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-title { font-size: 22px; font-weight: 600; }
.page-subtitle { color: #6b7280; font-size: 13px; margin-top: 2px; }

/* Cards */
.card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.card h2 { font-size: 16px; margin-bottom: 12px; }
.card h3 { font-size: 14px; margin-bottom: 8px; color: #374151; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
  color: #374151;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 200px; }
.form-error { color: #dc2626; font-size: 12px; margin-top: 4px; }
.field-error { color: #dc2626; font-size: 12px; margin-top: 2px; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  background: #3b82f6;
  color: #fff;
  transition: background 0.15s;
  border: none;
}
.btn:hover { background: #2563eb; }
.btn:disabled { background: #9ca3af; cursor: not-allowed; }
.btn-secondary { background: #6b7280; }
.btn-secondary:hover { background: #4b5563; }
.btn-danger { background: #dc2626; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { display: block; width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Tables */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid #e5e7eb;
}
th {
  background: #f9fafb;
  font-weight: 600;
  color: #374151;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
tbody tr:hover { background: #f9fafb; }
td .btn-row { gap: 4px; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
}
.badge-active { background: #d1fae5; color: #065f46; }
.badge-broken { background: #fee2e2; color: #991b1b; }
.badge-retired { background: #e5e7eb; color: #374151; }

/* Auth pages */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.auth-card {
  background: #fff;
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}
.auth-card h1 { font-size: 22px; margin-bottom: 4px; }
.auth-card .auth-sub { color: #6b7280; font-size: 13px; margin-bottom: 24px; }
.auth-card .auth-foot { text-align: center; margin-top: 16px; font-size: 13px; color: #6b7280; }

/* Stats grid */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-tile {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 16px 20px;
}
.stat-tile .stat-label { color: #6b7280; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-tile .stat-value { font-size: 28px; font-weight: 700; color: #1e293b; margin-top: 4px; }

/* Quick actions */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.quick-action {
  display: block;
  padding: 16px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  color: #1f2937;
  text-align: center;
  font-weight: 500;
  transition: all 0.15s;
}
.quick-action:hover {
  border-color: #3b82f6;
  background: #eff6ff;
  text-decoration: none;
  transform: translateY(-1px);
}
.quick-action .qa-icon { font-size: 28px; display: block; margin-bottom: 6px; }

/* QR display */
.qr-display {
  text-align: center;
  padding: 20px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}
.qr-display img {
  max-width: 280px;
  border: 4px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.qr-display .qr-caption { margin-top: 12px; font-family: monospace; font-size: 14px; color: #374151; }

/* Scan result */
.scan-result {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 20px;
  margin-top: 20px;
}
.scan-result .result-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.scan-result .result-title { font-size: 18px; font-weight: 600; }
.scan-result .result-meta { color: #6b7280; font-size: 13px; }
.scan-result .result-section { margin-top: 20px; padding-top: 16px; border-top: 1px solid #e5e7eb; }

/* Loading & empty */
.loading { text-align: center; padding: 40px; color: #6b7280; }
.empty {
  text-align: center;
  padding: 32px;
  color: #9ca3af;
  font-size: 13px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  background: #1f2937;
  color: #fff;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 1000;
  max-width: 360px;
  font-size: 13px;
}
.toast.toast-error { background: #dc2626; }
.toast.toast-success { background: #059669; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: #fff;
  border-radius: 8px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 { font-size: 16px; }
.modal-close { background: none; border: none; font-size: 20px; color: #6b7280; cursor: pointer; }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid #e5e7eb; display: flex; justify-content: flex-end; gap: 8px; }

/* Detail grid */
.detail-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 16px;
  font-size: 13px;
}
.detail-grid dt { font-weight: 500; color: #6b7280; }
.detail-grid dd { color: #1f2937; }

/* History list */
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
  padding: 10px 12px;
  background: #f9fafb;
  border-left: 3px solid #3b82f6;
  border-radius: 4px;
}
.history-item .h-date { font-size: 12px; color: #6b7280; }
.history-item .h-param { font-weight: 600; color: #1e293b; }
.history-item .h-officer { font-size: 13px; color: #4b5563; }
.history-item .h-notes { font-size: 12px; color: #6b7280; margin-top: 2px; font-style: italic; }

@media (max-width: 640px) {
  .topnav { flex-wrap: wrap; gap: 8px; padding: 10px 16px; }
  .topnav-links { order: 3; width: 100%; overflow-x: auto; }
  main { padding: 0 16px; margin: 16px auto; }
  .page-header { flex-direction: column; align-items: flex-start; }
}
