/* CSS System: Modern Glassmorphic Dark Theme with A4 Print Support */

:root {
  --bg-app: #F4F6F9; /* Surface variant */
  --bg-card: #FFFFFF; /* Neutral background card */
  --bg-card-hover: #F8FAFC;
  --border-color: #E2E8F0; /* Clean light border */
  --border-glow: rgba(0, 90, 156, 0.25);
  
  --primary: #005A9C; /* TGR Blue */
  --primary-hover: #00487C;
  --secondary: #5A5A5A; /* TGR Corporate Gray */
  --secondary-hover: #404040;
  
  --danger: #EF4444;
  --danger-hover: #DC2626;
  --success: #10B981;
  --warning: #F59E0B;
  
  --text-primary: #1E293B; /* slate-800 */
  --text-muted: #64748B; /* slate-500 */
  --text-dark: #0F172A; /* slate-900 */
  
  --font-display: 'Montserrat', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', 'Roboto Mono', monospace;
  
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-glow: 0 0 15px rgba(0, 90, 156, 0.15);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
}

/* Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  background-image: radial-gradient(circle at 10% 20%, rgba(0, 90, 156, 0.04) 0%, transparent 40%),
                    radial-gradient(circle at 90% 80%, rgba(90, 90, 90, 0.04) 0%, transparent 40%);
  background-attachment: fixed;
}

h1, h2, h3, h4, h5 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* Header & Banner */
header {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 1.25rem 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand img {
  height: 42px;
  width: auto;
  object-fit: contain;
  border-radius: 4px;
}

.brand-text-container {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-main {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.6rem;
  color: var(--primary);
  letter-spacing: -0.06em;
  text-transform: lowercase;
}

.brand-sub {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.7rem;
  color: var(--secondary);
  text-transform: lowercase;
  letter-spacing: 0.05em;
  margin-top: -2px;
}

.brand-group {
  letter-spacing: 0.18em;
  font-weight: 700;
}

.brand span {
  font-size: 0.75rem;
  background: rgba(0, 90, 156, 0.08);
  color: var(--primary);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-glow);
  font-family: var(--font-mono);
  margin-left: 0.5rem;
}

.sync-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.sync-dot.offline {
  background-color: var(--warning);
  box-shadow: 0 0 8px var(--warning);
}

/* Navigation Tabs */
nav.tabs {
  display: flex;
  overflow-x: auto;
  background: #FFFFFF;
  border-bottom: 1px solid var(--border-color);
  scrollbar-width: none;
  position: sticky;
  top: 80px;
  z-index: 99;
}

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

.tab-btn {
  padding: 1rem 1.5rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s ease;
  border-bottom: 2px solid transparent;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: rgba(0, 90, 156, 0.06);
}

/* App Container & Tabs Panels */
main.container {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1.5rem 6rem 1.5rem;
}

.tab-panel {
  display: none;
  animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.tab-panel.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Glass Cards */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-md);
  transition: border-color 0.3s ease;
}

.card:hover {
  border-color: rgba(0, 90, 156, 0.25);
}

.card-title {
  font-size: 1.25rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-dark);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.75rem;
}

.card-title svg {
  color: var(--primary);
  width: 20px;
  height: 20px;
}

/* Form Layout Grids */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input, select, textarea {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.95rem;
  transition: all 0.2s ease;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 90, 156, 0.15);
  background: #FFFFFF;
}

textarea {
  resize: vertical;
  min-height: 100px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: none;
  text-align: center;
  text-decoration: none;
  min-height: 48px;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow-glow);
}

.btn-secondary {
  background: #FFFFFF;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

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

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

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-icon-only {
  width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  border-radius: 50%;
}

/* GPS Info Panel */
.gps-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 90, 156, 0.05);
  border: 1px solid rgba(0, 90, 156, 0.15);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}

.gps-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.gps-info svg {
  color: var(--secondary);
  animation: pulse 2s infinite;
}

.gps-coords {
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

@keyframes pulse {
  0% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 0.8; }
}

/* Checklist custom UI */
.checklist-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 1rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border-color);
}

.checklist-item:last-child {
  border-bottom: none;
}

.checklist-desc {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.checklist-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.checklist-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.rfp-badge {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  margin-right: 0.5rem;
  color: var(--secondary);
}

/* Ambient Readings Table */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  margin-bottom: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

th {
  background: var(--bg-app);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.75rem 1rem;
  border-bottom: 2px solid var(--border-color);
  color: var(--text-dark);
}

td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  background: #FFFFFF;
}

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

table input {
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  min-width: 60px;
}

table select {
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  min-width: 100px;
}

.table-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 1rem;
  gap: 0.75rem;
}

/* Bents Inspection Checklist */
.bents-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.bent-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #FFFFFF;
}

.bent-header {
  padding: 1rem 1.5rem;
  background: #F8FAFC;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid transparent;
  transition: all 0.2s ease;
}

.bent-header:hover {
  background: #F1F5F9;
}

.bent-card.open .bent-header {
  border-bottom-color: var(--border-color);
  background: rgba(0, 90, 156, 0.06);
}

.bent-title-group {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.bent-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
}

.bent-badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  font-weight: 600;
}

.bent-badge.ok {
  background: rgba(16, 185, 129, 0.15);
  color: var(--primary);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.bent-badge.warn {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.bent-toggle-icon {
  transition: transform 0.2s ease;
  color: var(--text-muted);
}

.bent-card.open .bent-toggle-icon {
  transform: rotate(180deg);
}

.bent-content {
  display: none;
  padding: 1.5rem;
  background: #FFFFFF;
  border-top: 1px solid var(--border-color);
}

.bent-card.open .bent-content {
  display: block;
}

.sub-section-title {
  font-size: 1rem;
  margin: 1.5rem 0 1rem 0;
  color: var(--secondary);
  border-bottom: 1px solid rgba(6, 182, 212, 0.1);
  padding-bottom: 0.4rem;
}

.sub-section-title:first-child {
  margin-top: 0;
}

/* Photo Slots & Custom Camera Input */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-top: 1rem;
}

.photo-slot {
  border: 1px dashed var(--border-color);
  background: #FFFFFF;
  border-radius: var(--radius-sm);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  min-height: 180px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.photo-slot:hover {
  border-color: var(--primary);
  background: rgba(0, 90, 156, 0.03);
}

.photo-slot-icon {
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.photo-slot-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.photo-slot-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.photo-slot input[type="file"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  z-index: 5;
}

.photo-preview-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
  z-index: 10;
  display: none;
}

.photo-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-remove-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(239, 68, 68, 0.85);
  color: white;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 15;
  transition: background 0.2s;
}

.photo-remove-btn:hover {
  background: var(--danger);
}

.photo-info-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 8px;
  padding: 4px 6px;
  text-align: left;
  line-height: 1.2;
  z-index: 12;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  pointer-events: none;
}

/* Signature Pad Component */
.signature-card {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.signature-canvas-wrapper {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  touch-action: none;
  width: 100%;
  max-width: 500px;
  height: 200px;
}

canvas.signature-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.signature-actions {
  display: flex;
  gap: 1rem;
  margin-top: 1rem;
  width: 100%;
  max-width: 500px;
}

.signature-actions button {
  flex: 1;
}

/* Footer Controls (For navigation inside form) */
.footer-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

/* Print Form Element - Hidden in App View */
#print-report-container {
  display: none;
}

/* A4 Print Layout Media Query */
@media print {
  @page {
    size: A4 portrait;
    margin: 12mm 15mm 15mm 15mm;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-family: Arial, Helvetica, sans-serif !important;
    font-size: 11px !important;
    line-height: 1.4 !important;
  }

  header, nav.tabs, main.container, .footer-nav, .btn, .sync-status, .photo-remove-btn {
    display: none !important;
  }

  #print-report-container {
    display: block !important;
    width: 100% !important;
    color: #000000 !important;
  }

  .print-page {
    page-break-after: always;
    position: relative;
    box-sizing: border-box;
    width: 100%;
  }

  .print-page:last-child {
    page-break-after: avoid;
  }

  /* Print Header */
  .print-header {
    border-bottom: 2px solid #000000;
    padding-bottom: 8px;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
  }

  .print-header h1 {
    font-size: 18px;
    font-family: inherit;
    font-weight: bold;
    color: #000000;
    margin: 0;
  }

  .print-header .subtitle {
    font-size: 10px;
    color: #555555;
    text-transform: uppercase;
    font-family: monospace;
  }

  .print-logo-text {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -1px;
    border: 2px solid #000;
    padding: 2px 6px;
  }

  /* Grid Layouts for Print */
  .print-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 15px;
  }

  .print-grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-bottom: 15px;
  }

  /* Data Groups */
  .print-group {
    border: 1px solid #cccccc;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 12px;
    background: #fafafa;
  }

  .print-group-title {
    font-weight: bold;
    font-size: 12px;
    border-bottom: 1px solid #777777;
    margin-bottom: 8px;
    padding-bottom: 3px;
    text-transform: uppercase;
  }

  .print-field {
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px dashed #dddddd;
    padding-bottom: 2px;
  }

  .print-field:last-child {
    border-bottom: none;
  }

  .print-label {
    font-weight: bold;
    color: #444444;
  }

  .print-value {
    font-family: monospace;
    font-weight: normal;
  }

  /* Tables for Print */
  table.print-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
    font-size: 10px;
  }

  table.print-table th {
    background-color: #eeeeee !important;
    color: #000000 !important;
    border: 1px solid #999999 !important;
    padding: 5px 6px !important;
    font-weight: bold !important;
    font-size: 9px !important;
  }

  table.print-table td {
    border: 1px solid #cccccc !important;
    padding: 4px 6px !important;
    background-color: transparent !important;
  }

  /* Checklist items in Print */
  .print-check-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid #eeeeee;
  }

  .print-check-row:last-child {
    border-bottom: none;
  }

  /* Photo Log Print styling: 2 photos per page */
  .print-photo-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 10px;
  }

  .print-photo-card {
    border: 1px solid #999999;
    padding: 8px;
    background: #ffffff;
    border-radius: 4px;
    text-align: center;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
  }

  .print-photo-wrapper {
    position: relative;
    width: 100%;
    height: 180px;
    background: #eeeeee;
    border: 1px solid #dddddd;
    overflow: hidden;
  }

  .print-photo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .print-photo-watermark {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.7);
    color: #ffffff;
    font-family: monospace;
    font-size: 7px;
    padding: 2px 4px;
    text-align: left;
    line-height: 1.1;
  }

  .print-photo-caption {
    font-weight: bold;
    font-size: 10px;
    margin-top: 5px;
  }

  .print-photo-tag {
    font-size: 8px;
    color: #666666;
    margin-top: 2px;
  }

  /* Signature section */
  .print-signature-section {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-top: 30px;
    border-top: 1px solid #aaaaaa;
    padding-top: 15px;
  }

  .print-sign-box {
    text-align: center;
    width: 200px;
  }

  .print-sign-img-wrapper {
    border-bottom: 1px solid #000;
    height: 50px;
    margin-bottom: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .print-sign-img {
    max-height: 45px;
    object-fit: contain;
  }
}
