/* ==========================================================================
   QR System - Main Stylesheet
   Extracted and consolidated styles for better maintainability
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Custom Properties (Design Tokens)
   -------------------------------------------------------------------------- */
:root {
  /* Brand Colors */
  --color-brand: #006699;
  --color-brand-strong: #003366;
  --color-brand-light: #4d9fcc;
  --color-brand-lighter: #b3d9f2;

  /* Neutral Colors */
  --color-slate-50: #f8fafc;
  --color-slate-100: #f1f5f9;
  --color-slate-200: #e2e8f0;
  --color-slate-300: #cbd5e1;
  --color-slate-400: #94a3b8;
  --color-slate-500: #64748b;
  --color-slate-600: #475569;
  --color-slate-700: #334155;
  --color-slate-800: #1e293b;
  --color-slate-900: #0f172a;

  /* Semantic Colors */
  --color-success: #16a34a;
  --color-success-bg: #dcfce7;
  --color-success-border: #bbf7d0;
  --color-warning: #ca8a04;
  --color-warning-bg: #fef3c7;
  --color-error: #dc2626;
  --color-error-bg: #fee2e2;
  --color-info: #2563eb;
  --color-info-bg: #dbeafe;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.04), 0 2px 4px -1px rgba(0, 0, 0, 0.02);
  --shadow-lg: 0 4px 12px rgba(0, 51, 102, 0.06);
  --shadow-brand: 0 2px 8px rgba(0, 102, 153, 0.12);
  --shadow-brand-light: 0 1px 4px rgba(0, 102, 153, 0.06);

  /* Spacing */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

/* --------------------------------------------------------------------------
   Base Styles
   -------------------------------------------------------------------------- */
html, body {
  height: 100%;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--color-slate-800);
  background: var(--color-slate-50);
  min-height: 100dvh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --------------------------------------------------------------------------
   Layout Components
   -------------------------------------------------------------------------- */
.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px max(20px, env(safe-area-inset-right)) 24px max(20px, env(safe-area-inset-left));
}

.wrap.admin {
  max-width: min(1600px, calc(100vw - 40px));
}

@media (max-width: 768px) {
  .wrap.admin {
    max-width: 100vw;
    padding: 0;
    margin: 0;
  }

  .wrap.admin .card {
    border-radius: 0;
    border: none;
    box-shadow: none;
  }
}

/* --------------------------------------------------------------------------
   Card Component
   -------------------------------------------------------------------------- */
.card {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--color-slate-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.card.narrow {
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}

/* --------------------------------------------------------------------------
   Header Component
   -------------------------------------------------------------------------- */
.header {
  padding: 32px 24px 28px;
  text-align: center;
  border-bottom: 1px solid var(--color-slate-100);
  background: #ffffff;
}

.brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.brand img {
  height: 40px;
  width: auto;
  opacity: 0.9;
}

.title {
  margin-top: 20px;
  margin-bottom: 16px;
  font-weight: 600;
  font-size: clamp(20px, 2.2vw, 28px);
  line-height: 1.3;
  letter-spacing: -0.02em;
  color: var(--color-slate-800);
}

@media (min-width: 768px) {
  .title {
    margin-top: 24px;
    margin-bottom: 18px;
  }

  .header {
    padding-top: 36px;
    padding-bottom: 32px;
  }
}

/* Reference Badge */
.ref {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 12px;
  color: var(--color-slate-500);
  background: var(--color-slate-50);
  border: 1px solid var(--color-slate-200);
  border-radius: var(--radius-md);
  font-weight: 500;
}

.ref .label {
  opacity: 0.8;
  font-weight: 400;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ref .value {
  font-weight: 600;
  color: var(--color-slate-600);
  font-family: var(--font-mono);
}

/* --------------------------------------------------------------------------
   Content Area
   -------------------------------------------------------------------------- */
.content {
  padding: 28px 24px;
}

.content.narrow {
  max-width: 560px;
  margin: 0 auto;
}

.content.full {
  width: 100%;
}

/* --------------------------------------------------------------------------
   Footer Component
   -------------------------------------------------------------------------- */
.footer {
  padding: 24px 28px 28px;
  text-align: center;
  color: var(--color-slate-500);
  background: var(--color-slate-50);
  border-top: 1px solid var(--color-slate-100);
}

.footer .meta {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--color-slate-600);
}

.footer .copy {
  font-size: 11px;
  opacity: 0.8;
  margin-top: 8px;
  font-weight: 400;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  padding: 0 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-slate-300);
  font-weight: 500;
  font-size: 13px;
  color: var(--color-slate-700);
  background: #ffffff;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  background: #f9fafb;
  border-color: var(--color-brand);
  color: var(--color-brand);
  box-shadow: 0 2px 4px 0 rgba(0, 102, 153, 0.08);
  transform: translateY(-0.5px);
}

.btn-primary {
  background: var(--color-brand);
  border-color: var(--color-brand);
  color: #ffffff;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--color-brand-strong);
  border-color: var(--color-brand-strong);
  color: #ffffff;
  transform: translateY(-0.5px);
}

.btn-danger {
  background: var(--color-error);
  border-color: var(--color-error);
  color: #ffffff;
}

.btn-danger:hover {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #ffffff;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.btn-ghost:hover {
  background: var(--color-slate-100);
  border-color: transparent;
}

/* Action buttons grid */
.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  width: min(400px, 100%);
  margin: 18px auto 0;
}

/* --------------------------------------------------------------------------
   Form Validation Styles
   -------------------------------------------------------------------------- */
.just-validate-error-label {
  color: var(--color-error) !important;
  font-size: 12px !important;
  margin-top: 4px !important;
  display: block !important;
  font-weight: 500 !important;
}

.is-invalid {
  border-color: var(--color-error) !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1) !important;
}

.is-valid {
  border-color: var(--color-success) !important;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.1) !important;
}

/* --------------------------------------------------------------------------
   Links
   -------------------------------------------------------------------------- */
a.no-underline {
  text-decoration: none;
}

a.no-underline:hover {
  text-decoration: none;
}

/* --------------------------------------------------------------------------
   Alpine.js Utilities
   -------------------------------------------------------------------------- */
[x-cloak] {
  display: none !important;
}

.alpine-loading {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.alpine-loaded {
  opacity: 1;
}

/* --------------------------------------------------------------------------
   Admin-Specific Styles
   -------------------------------------------------------------------------- */
.admin-wrapper {
  max-width: min(1600px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 20px max(20px, env(safe-area-inset-right)) 24px max(20px, env(safe-area-inset-left));
}

@media (max-width: 768px) {
  .admin-wrapper {
    max-width: 100vw;
    padding: 0;
    margin: 0;
  }
}

.admin-card {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--color-slate-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

@media (max-width: 768px) {
  .admin-card {
    border-radius: 0;
    border: none;
    box-shadow: none;
  }
}

.admin-header {
  padding: 32px 24px 28px;
  text-align: center;
  border-bottom: 1px solid var(--color-slate-100);
  background: linear-gradient(135deg, var(--color-slate-50) 0%, var(--color-slate-200) 100%);
  color: var(--color-slate-800);
}

.admin-brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 16px;
}

.admin-brand img {
  height: 32px;
  width: auto;
  opacity: 0.95;
}

.admin-title {
  font-weight: 600;
  font-size: clamp(20px, 2.2vw, 28px);
  line-height: 1.3;
  letter-spacing: -0.02em;
  margin: 0;
}

.admin-subtitle {
  font-size: 14px;
  opacity: 0.85;
  margin-top: 6px;
  font-weight: 400;
}

.admin-content {
  padding: 28px 24px;
  min-height: 600px;
}

/* --------------------------------------------------------------------------
   Stats Cards
   -------------------------------------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: #ffffff;
  border: 1px solid var(--color-slate-200);
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  padding: 20px;
  transition: all 0.2s ease;
}

.stat-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
  border-color: var(--color-brand);
}

.stat-icon {
  width: 40px;
  height: 40px;
  padding: 8px;
  border-radius: var(--radius-md);
  margin-bottom: 12px;
}

.stat-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-slate-500);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--color-slate-800);
  line-height: 1.2;
}

.stat-desc {
  font-size: 12px;
  color: var(--color-slate-400);
  margin-top: 4px;
}

/* --------------------------------------------------------------------------
   Tab Navigation
   -------------------------------------------------------------------------- */
.tab-nav {
  display: flex;
  gap: 2px;
  background: var(--color-slate-100);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: 24px;
}

.tab-button {
  flex: 1;
  padding: 12px 16px;
  border-radius: 6px;
  background: transparent;
  border: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-slate-500);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-button.active {
  background: #ffffff;
  color: var(--color-brand);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   Search & Controls
   -------------------------------------------------------------------------- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
  align-items: center;
}

.search-input {
  flex: 1;
  min-width: 200px;
  height: 42px;
  padding: 0 16px;
  border: 1px solid var(--color-slate-300);
  border-radius: var(--radius-md);
  font-size: 14px;
  background: #ffffff;
  transition: all 0.15s ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px rgba(0, 102, 153, 0.1);
}

/* --------------------------------------------------------------------------
   Data Tables
   -------------------------------------------------------------------------- */
.table-container {
  background: #ffffff;
  border: 1px solid var(--color-slate-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  background: var(--color-slate-50);
  padding: 16px 12px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-slate-600);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--color-slate-200);
}

.data-table td {
  padding: 16px 12px;
  border-bottom: 1px solid var(--color-slate-100);
  font-size: 14px;
  vertical-align: top;
}

.data-table tr:hover {
  background: #fafbfc;
}

.data-table tr:last-child td {
  border-bottom: none;
}

/* --------------------------------------------------------------------------
   Badges
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-success {
  background: var(--color-success-bg);
  color: #166534;
}

.badge-warning {
  background: var(--color-warning-bg);
  color: #92400e;
}

.badge-error {
  background: var(--color-error-bg);
  color: #991b1b;
}

.badge-info {
  background: var(--color-info-bg);
  color: #1e40af;
}

/* --------------------------------------------------------------------------
   Code Blocks
   -------------------------------------------------------------------------- */
.code {
  display: inline-block;
  padding: 4px 8px;
  background: var(--color-slate-100);
  border: 1px solid var(--color-slate-200);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--color-slate-600);
}

/* --------------------------------------------------------------------------
   Form Controls
   -------------------------------------------------------------------------- */
.checkbox {
  width: 16px;
  height: 16px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--color-slate-300);
  cursor: pointer;
}

.checkbox:checked {
  background: var(--color-brand);
  border-color: var(--color-brand);
}

/* --------------------------------------------------------------------------
   Alerts
   -------------------------------------------------------------------------- */
.alert {
  padding: 16px 20px;
  border-radius: var(--radius-md);
  margin: 20px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.alert-success {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid var(--color-success-border);
}

.alert-info {
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

.alert-error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* --------------------------------------------------------------------------
   Empty States
   -------------------------------------------------------------------------- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-slate-500);
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-slate-700);
  margin-bottom: 8px;
}

.empty-desc {
  font-size: 14px;
  color: var(--color-slate-500);
}

/* --------------------------------------------------------------------------
   Utility Classes
   -------------------------------------------------------------------------- */
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------------------
   Responsive Adjustments
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .admin-header {
    padding: 24px 16px 20px;
  }

  .admin-content {
    padding: 20px 16px;
  }

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

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .search-input {
    min-width: auto;
  }

  .table-container {
    overflow-x: auto;
  }

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

/* --------------------------------------------------------------------------
   Modal Component
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  max-width: 480px;
  width: 100%;
  max-height: calc(100vh - 40px);
  overflow: hidden;
  transform: scale(0.95);
  transition: transform 0.2s ease;
}

.modal-overlay.active .modal-content {
  transform: scale(1);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--color-slate-200);
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-slate-800);
  margin: 0;
}

.modal-body {
  padding: 24px;
  max-height: 400px;
  overflow-y: auto;
}

.modal-body p {
  margin: 0;
  font-size: 14px;
  color: var(--color-slate-600);
  line-height: 1.6;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--color-slate-200);
  background: var(--color-slate-50);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* --------------------------------------------------------------------------
   Sortable Table Headers
   -------------------------------------------------------------------------- */
.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.sortable:hover {
  background: var(--color-slate-100);
}

.sort-indicator {
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  color: var(--color-slate-400);
}

.sortable.asc .sort-indicator::after {
  content: '\25B2';
  color: var(--color-brand);
}

.sortable.desc .sort-indicator::after {
  content: '\25BC';
  color: var(--color-brand);
}

.sortable:not(.asc):not(.desc) .sort-indicator::after {
  content: '\25B2\25BC';
  font-size: 8px;
  letter-spacing: -2px;
}

/* --------------------------------------------------------------------------
   Clickable Message Cell
   -------------------------------------------------------------------------- */
.message-preview {
  cursor: pointer;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-preview:hover {
  color: var(--color-brand);
}

/* Keep room for the search icon after the shared input padding rule. */
.search-input.pl-10 { padding-left: 2.5rem; }
