/* ==========================================================================
   IMPECCABLE DESIGN SYSTEM: QR ATTENDANCE & GEMINI AI PLATFORM
   Precision typography, high contrast, purposeful motion, zero product slop.
   ========================================================================== */

:root {
  /* Neutral Color Palette (Zinc/Slate) */
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-subtle: #f1f5f9;
  --bg-muted: #e2e8f0;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --text-inverse: #ffffff;

  --border-subtle: #e2e8f0;
  --border-strong: #cbd5e1;
  --border-focus: #2563eb;

  /* Semantic Brand & Accents */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-active: #1e40af;
  --primary-surface: #eff6ff;
  --primary-border: #bfdbfe;

  --success: #059669;
  --success-surface: #ecfdf5;
  --success-border: #a7f3d0;
  --success-text: #065f46;

  --warning: #d97706;
  --warning-surface: #fffbeb;
  --warning-border: #fde68a;
  --warning-text: #92400e;

  --danger: #dc2626;
  --danger-surface: #fef2f2;
  --danger-border: #fecaca;
  --danger-text: #991b1b;

  --info: #0284c7;
  --info-surface: #f0f9ff;
  --info-border: #bae6fd;
  --info-text: #0369a1;

  /* Typography Stacks */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", monospace;

  /* Disciplined Typographic Scale */
  --font-size-xs: 0.75rem;   /* 12px - Captions, tags, micro-copy */
  --font-size-sm: 0.875rem;  /* 14px - Body, table cells, form labels */
  --font-size-base: 1rem;    /* 16px - Large body, primary buttons */
  --font-size-lg: 1.25rem;   /* 20px - Section headings */
  --font-size-xl: 1.625rem;  /* 26px - Page titles */
  --font-size-2xl: 2.25rem;  /* 36px - Metric numbers, clocks */

  /* Elevation (Clean 1-layer shadows with natural directional offset) */
  --shadow-xs: 0 1px 2px 0 rgba(15, 23, 42, 0.05);
  --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.08), 0 1px 2px -1px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);
  --shadow-modal: 0 20px 25px -5px rgba(15, 23, 42, 0.12), 0 8px 10px -6px rgba(15, 23, 42, 0.08);

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Motion */
  --ease-snappy: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast: 150ms;
  --duration-normal: 220ms;
}

/* Base Reset & Typography */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.5;
  letter-spacing: -0.011em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

/* Accessible focus ring */
:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* Numbers & Data */
.tabular-nums {
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: var(--font-mono);
  font-feature-settings: "liga" 0;
}

/* App Shell Layout */
.app-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
  background-color: rgba(255, 255, 255, 0.95);
}

.header-container {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0.875rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text-primary);
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: #0f172a;
  color: #ffffff;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  box-shadow: var(--shadow-xs);
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.page-container {
  max-width: 1360px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Surfaces & Containers */
.surface-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  padding: 1.25rem 1.5rem;
  transition: border-color var(--duration-fast) var(--ease-snappy);
}

.surface-card:hover {
  border-color: var(--border-strong);
}

/* Metric / KPI Bar (Refined Operative View) */
.metric-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.metric-cell {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.125rem 1.25rem;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.metric-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.metric-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: -0.005em;
}

.metric-number {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.metric-subtext {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Segmented Tabs Control */
.nav-tabs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-subtle);
  padding: 0.35rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  margin-bottom: 1.5rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav-tabs::-webkit-scrollbar {
  display: none;
}

.tab-item {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.95rem;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.835rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--duration-fast) var(--ease-snappy);
  font-family: inherit;
}

.tab-item:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.6);
}

.tab-item.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
  font-weight: 700;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  white-space: nowrap;
  transition: all var(--duration-fast) var(--ease-snappy);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: #0f172a;
  color: #ffffff;
  border-color: #0f172a;
}

.btn-primary:hover {
  background: #1e293b;
  border-color: #1e293b;
}

.btn-accent {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.btn-accent:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-subtle);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}

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

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

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.775rem;
  border-radius: var(--radius-sm);
}

/* Semantic Badges & Chips */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  font-size: 0.725rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  white-space: nowrap;
}

.badge-on-time {
  background: var(--success-surface);
  color: var(--success-text);
  border: 1px solid var(--success-border);
}

.badge-late {
  background: var(--warning-surface);
  color: var(--warning-text);
  border: 1px solid var(--warning-border);
}

.badge-absent {
  background: var(--danger-surface);
  color: var(--danger-text);
  border: 1px solid var(--danger-border);
}

.badge-neutral {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.badge-info {
  background: var(--info-surface);
  color: var(--info-text);
  border: 1px solid var(--info-border);
}

.badge-device {
  background: #f8fafc;
  color: #334155;
  border: 1px solid #cbd5e1;
  font-family: var(--font-mono);
  font-size: 0.7rem;
}

/* Tables (Dense, High-readability Operative Style) */
.table-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
  text-align: left;
}

table.data-table th {
  background: #f8fafc;
  color: var(--text-secondary);
  font-weight: 600;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
  letter-spacing: -0.01em;
}

table.data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text-primary);
  vertical-align: middle;
}

table.data-table tbody tr:hover td {
  background-color: #f8fafc;
}

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

/* Filter Toolbars */
.filter-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 0.875rem 1rem;
  margin-bottom: 1.25rem;
}

.control-input, .control-select {
  padding: 0.45rem 0.75rem;
  font-size: 0.835rem;
  font-family: inherit;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--duration-fast);
}

.control-input:focus, .control-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* Forms */
.form-field {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.form-input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-size: 0.9rem;
  font-family: inherit;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
  transition: all var(--duration-fast);
}

.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* Status Indicator Dot */
.status-beacon {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  display: inline-block;
  box-shadow: 0 0 0 2px rgba(5, 150, 105, 0.2);
}

/* Modal Dialog */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal-overlay.active {
  display: flex;
}

.modal-sheet {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.875rem;
  margin-bottom: 1.25rem;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

/* Terminal / Code Viewer */
.code-terminal {
  background: #090d16;
  border: 1px solid #1e293b;
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: #38bdf8;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ==========================================================================
   UNIVERSAL POPUP DIALOG SYSTEM (Replaces alerts & confirms with iOS-grade popups)
   ========================================================================== */

.popup-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 1.25rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms cubic-bezier(0.16, 1, 0.3, 1);
}

.popup-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.popup-overlay.closing {
  opacity: 0;
  pointer-events: none;
}

.popup-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 22px;
  box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.25), 0 0 0 1px rgba(15, 23, 42, 0.06);
  width: 100%;
  max-width: 420px;
  padding: 1.75rem 1.5rem;
  text-align: center;
  transform: scale(0.92) translateY(12px);
  transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1);
}

.popup-overlay.active .popup-card {
  transform: scale(1) translateY(0);
}

.popup-overlay.closing .popup-card {
  transform: scale(0.92) translateY(12px);
}

.popup-icon-box {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  margin: 0 auto 1.125rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  user-select: none;
}

.popup-icon-danger {
  background: #fef2f2;
  border: 2px solid #fecaca;
  box-shadow: 0 0 0 5px rgba(220, 38, 38, 0.1);
}

.popup-icon-warning, .popup-icon-lock {
  background: #fffbeb;
  border: 2px solid #fde68a;
  box-shadow: 0 0 0 5px rgba(217, 119, 6, 0.1);
}

.popup-icon-success {
  background: #ecfdf5;
  border: 2px solid #a7f3d0;
  box-shadow: 0 0 0 5px rgba(5, 150, 105, 0.1);
}

.popup-icon-info {
  background: #eff6ff;
  border: 2px solid #bfdbfe;
  box-shadow: 0 0 0 5px rgba(37, 99, 235, 0.1);
}

.popup-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  margin-bottom: 0.65rem;
  line-height: 1.3;
}

.popup-message {
  font-size: 0.925rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 1.5rem;
  word-break: break-word;
}

.popup-actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.popup-actions-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.popup-btn-confirm {
  width: 100%;
  padding: 0.85rem 1.25rem;
  font-size: 1rem;
  font-weight: 700;
  border-radius: 12px;
}

.popup-btn-cancel {
  width: 100%;
  padding: 0.85rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 12px;
}

/* ==========================================================================
   MOBILE RESPONSIVE SYSTEM (Mobile-First Polish for Phones & Tablets)
   ========================================================================== */

@media (max-width: 768px) {
  /* Safe-area insets for notched iPhones and gesture nav */
  body {
    padding-bottom: env(safe-area-inset-bottom, 1rem);
  }

  .header-container {
    flex-direction: column;
    align-items: stretch;
    gap: 0.875rem;
    padding: 0.875rem 1rem;
  }

  .header-container > div:last-child {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .header-container .btn {
    flex: 1 1 auto;
    justify-content: center;
    font-size: 0.75rem;
    padding: 0.5rem 0.65rem;
  }

  .page-container {
    padding: 0.875rem 0.75rem;
  }

  /* 2-column compact grid for KPI Metrics on phone screens */
  .metric-strip {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.65rem;
  }

  .metric-cell {
    padding: 0.875rem 0.75rem;
  }

  .metric-number {
    font-size: 1.625rem !important;
  }

  .metric-label {
    font-size: 0.75rem !important;
  }

  /* Horizontally scrollable navigation tabs with smooth touch swiping */
  .nav-tabs {
    display: flex;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0.4rem;
    padding-bottom: 0.35rem;
    margin-bottom: 1.125rem;
  }

  .nav-tabs::-webkit-scrollbar {
    display: none;
  }

  .tab-item {
    flex: 0 0 auto !important;
    font-size: 0.8125rem !important;
    padding: 0.55rem 0.85rem;
    white-space: nowrap;
  }

  /* Filter Toolbar responsive stacking */
  .filter-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }

  .filter-toolbar > div {
    width: 100% !important;
  }

  .filter-toolbar input,
  .filter-toolbar select {
    width: 100% !important;
    font-size: 16px !important; /* Prevents auto-zoom in Safari iOS */
  }

  .filter-toolbar .btn {
    width: 100%;
    justify-content: center;
    padding: 0.65rem;
  }

  /* Modals on mobile */
  .modal-sheet {
    padding: 1.125rem 1rem;
    border-radius: 18px;
    max-height: 85vh;
  }

  /* Form controls: 16px prevents iOS Safari form zoom */
  .control-input,
  .form-input {
    font-size: 16px !important;
  }

  /* Table panel */
  .table-panel {
    border-radius: var(--radius-md);
  }

  .data-table th, 
  .data-table td {
    padding: 0.65rem 0.6rem;
    font-size: 0.8rem;
  }
}

@media (max-width: 480px) {
  /* Extra compact phones (iPhone SE, 360px Android) */
  .metric-strip {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.5rem;
  }

  .popup-card {
    padding: 1.5rem 1.125rem;
    border-radius: 20px;
  }

  .popup-title {
    font-size: 1.15rem;
  }

  .popup-message {
    font-size: 0.875rem;
  }
}
