﻿/* ==========================================================================
   CAAT DRONE LEARNING PORTAL - RESPONSIVE STYLESHEET
   Mobile (iOS/Android), Tablet (iPad), Mac, Laptop & Desktop Optimized
   ========================================================================== */
:root {
  --font-main: 'Sarabun', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-head: 'Chakra Petch', sans-serif;
  --font-code: 'JetBrains Mono', monospace;
  --font-base-size: 16px;
}

/* Dark Cockpit (Default) */
html[data-theme="dark"] {
  --bg-body: #070d17;
  --bg-card: #0f172a;
  --bg-surface: #1e293b;
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --primary: #38bdf8;
  --primary-hover: #0ea5e9;
  --primary-light: rgba(56, 189, 248, 0.12);
  --border: #334155;
  --accent: #f59e0b;
  --danger-bg: rgba(239, 68, 68, 0.15);
  --danger-text: #f87171;
  --success-bg: rgba(34, 197, 94, 0.15);
  --success-text: #4ade80;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
  --radar-grid: rgba(56, 189, 248, 0.2);
}

/* Clean Sky (Light) */
html[data-theme="light"] {
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-surface: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #475569;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-light: rgba(2, 132, 199, 0.1);
  --border: #cbd5e1;
  --accent: #d97706;
  --danger-bg: #fee2e2;
  --danger-text: #b91c1c;
  --success-bg: #dcfce7;
  --success-text: #15803d;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --radar-grid: rgba(2, 132, 199, 0.25);
}

/* Sepia Aviator */
html[data-theme="sepia"] {
  --bg-body: #f4ede2;
  --bg-card: #fdfbf7;
  --bg-surface: #e9dfd0;
  --text-main: #382d1d;
  --text-muted: #6b5842;
  --primary: #b45309;
  --primary-hover: #92400e;
  --primary-light: rgba(180, 83, 9, 0.12);
  --border: #d4c4b0;
  --accent: #0f766e;
  --danger-bg: #fef08a;
  --danger-text: #991b1b;
  --success-bg: #d9f99d;
  --success-text: #166534;
  --shadow: 0 4px 6px -1px rgba(56, 45, 29, 0.1);
  --radar-grid: rgba(180, 83, 9, 0.25);
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  overflow-x: hidden;
}

body {
  font-family: var(--font-main);
  font-size: var(--font-base-size);
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.65;
  transition: background-color 0.25s, color 0.25s;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-head);
  font-weight: 700;
  line-height: 1.3;
  color: var(--primary);
  margin-bottom: 0.6rem;
  word-break: break-word;
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* Layout */
.container {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Sticky Top Toolbar */
.top-toolbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.theme-select {
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border);
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  font-family: var(--font-main);
  font-size: 0.85rem;
  cursor: pointer;
  outline: none;
}

.font-btn, .sound-btn {
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border);
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  font-family: var(--font-head);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.font-btn:hover, .sound-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Header */
header {
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-surface) 100%);
  border-bottom: 1px solid var(--border);
  padding: 2rem 1rem;
  text-align: center;
}

header h1 {
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}

header p {
  color: var(--text-muted);
  max-width: 820px;
  margin: 0 auto 1.2rem auto;
  font-size: clamp(0.9rem, 2vw, 1.05rem);
  line-height: 1.6;
}

.header-tags {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tag-pill {
  display: inline-block;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
}

/* Navigation Tabs (Mobile Smooth Swipe) */
.nav-wrapper {
  position: sticky;
  top: 49px;
  z-index: 990;
  background: var(--bg-body);
  border-bottom: 1px solid var(--border);
  padding: 0.4rem 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.nav-wrapper::-webkit-scrollbar {
  display: none;
}

.nav-tabs {
  display: flex;
  gap: 0.4rem;
  padding: 0 1rem;
  max-width: 1240px;
  margin: 0 auto;
  width: max-content;
}

.tab-btn {
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-family: var(--font-head);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  min-height: 40px;
}

.tab-btn:hover {
  color: var(--text-main);
  border-color: var(--primary);
}

.tab-btn.active {
  background: var(--primary);
  color: #031527 !important;
  border-color: var(--primary);
  font-weight: 700;
}

/* Cards & Content */
.tab-content {
  display: none;
  padding: 1.5rem 0 3rem 0;
  animation: fadeIn 0.25s ease-in-out;
}
.tab-content.active {
  display: block;
}

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

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: clamp(1rem, 3vw, 1.75rem);
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.summary-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: clamp(1rem, 2.5vw, 1.5rem);
  margin-bottom: 1.75rem;
}

.summary-section h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.6rem;
  margin-bottom: 1rem;
  font-size: clamp(1.1rem, 2.5vw, 1.35rem);
}

.key-rule {
  background: var(--bg-surface);
  border-left: 4px solid var(--primary);
  padding: 0.85rem 1.1rem;
  border-radius: 0 8px 8px 0;
  margin: 1rem 0;
  font-size: 0.95rem;
  line-height: 1.65;
}

.citation-badge {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary);
  padding: 0.15rem 0.55rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 700;
  vertical-align: middle;
}

/* Search Bar */
.search-bar {
  width: 100%;
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: var(--font-main);
  margin-bottom: 1.25rem;
  outline: none;
  transition: border-color 0.2s;
}
.search-bar:focus {
  border-color: var(--primary);
}

/* Images & Diagrams */
.img-diagram {
  margin: 1.25rem 0;
  text-align: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem;
  overflow: hidden;
}

.img-diagram img {
  width: 100%;
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  display: block;
  margin: 0 auto;
  transition: transform 0.25s ease;
}

.img-caption {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0.6rem 0.4rem 0.2rem;
  font-weight: 600;
}

/* Tables (Responsive Horizontal Scroll) */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1rem 0;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 550px;
  border-collapse: collapse;
  text-align: left;
}

th, td {
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

th {
  background: var(--bg-surface);
  color: var(--primary);
  font-family: var(--font-head);
  font-weight: 700;
}

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

/* Calculator Grid */
.calc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 1rem;
}

.calc-input-box, .calc-res-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
}

.calc-input-box label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  margin: 0.7rem 0 0.3rem;
  color: var(--text-main);
}
.calc-input-box label:first-of-type {
  margin-top: 0;
}

.calc-input-box select, .calc-input-box input {
  width: 100%;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border);
  padding: 0.55rem 0.8rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: var(--font-main);
  outline: none;
}

.calc-status-tag {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-weight: 700;
  margin-bottom: 1rem;
  text-align: center;
  font-size: 0.95rem;
}

.res-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.5rem 0;
  border-bottom: 1px dashed var(--border);
  font-size: 0.9rem;
  gap: 0.5rem;
}
.res-item .label {
  color: var(--text-muted);
  flex-shrink: 0;
}
.res-item .val {
  font-weight: 600;
  text-align: right;
}

/* Flashcards 3D */
.fc-deck-wrapper {
  perspective: 1000px;
  width: 100%;
  max-width: 600px;
  margin: 1.5rem auto;
  cursor: pointer;
}

.fc-box {
  width: 100%;
  min-height: 240px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 14px;
}
.fc-box.flipped {
  transform: rotateY(180deg);
}

.fc-front, .fc-back {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 14px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  border: 2px solid var(--border);
  box-shadow: var(--shadow);
}

.fc-front {
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-surface) 100%);
}

.fc-back {
  background: linear-gradient(135deg, var(--bg-surface) 0%, var(--bg-card) 100%);
  transform: rotateY(180deg);
  border-color: var(--primary);
}

/* PDF Modal */
.pdf-modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.85);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.pdf-modal-container {
  background: var(--bg-card);
  border-radius: 12px;
  width: 100%;
  max-width: 1000px;
  height: 90vh;
  display: flex;
  flex-direction: column;
  border: 2px solid var(--primary);
  overflow: hidden;
}

/* General Buttons */
.btn-submit-all {
  width: 100%;
  background: var(--primary);
  color: #031527;
  border: none;
  padding: 0.85rem;
  border-radius: 8px;
  font-family: var(--font-head);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 44px;
}
.btn-submit-all:hover {
  background: var(--primary-hover);
}

/* ==========================================================================
   MEDIA QUERIES (RESPONSIVE BREAKPOINTS)
   ========================================================================== */

/* Mobile Phones (max-width: 640px) */
@media (max-width: 640px) {
  :root {
    --font-base-size: 15px;
  }
  
  .top-toolbar {
    flex-direction: column;
    align-items: stretch;
    padding: 0.5rem;
  }
  
  .toolbar-group {
    justify-content: space-between;
    width: 100%;
  }
  
  .calc-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .res-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
  }
  .res-item .val {
    text-align: left;
  }
  
  .nav-wrapper {
    top: 86px;
  }
  
  .fc-box {
    min-height: 220px;
  }
  
  .pdf-modal-container {
    height: 95vh;
    padding: 0;
  }
  
  #gis-map-container {
    height: 380px !important;
  }
}

/* Tablets (641px - 1024px) */
@media (min-width: 641px) and (max-width: 1024px) {
  .calc-grid {
    grid-template-columns: 1fr;
  }
  #gis-map-container {
    height: 440px !important;
  }
}

/* Print Optimization */
@media print {
  .top-toolbar, .nav-wrapper, .sound-btn, .font-btn, button {
    display: none !important;
  }
  body {
    background: #fff !important;
    color: #000 !important;
  }
  .card, .summary-section {
    border: 1px solid #ccc !important;
    box-shadow: none !important;
  }
}
