/* HelpMe! PMR WIRA - Modern Humanitarian Design System */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Brand Palette (PMI Red, Medical Slate & Clean Modern Dark/Light) */
  --pmi-red-50: #FFF1F2;
  --pmi-red-100: #FFE4E6;
  --pmi-red-500: #E11D48;
  --pmi-red-600: #DC2626;
  --pmi-red-700: #B91C1C;
  --pmi-red-800: #991B1B;

  --pmi-primary: #DC2626;
  --pmi-primary-glow: rgba(220, 38, 38, 0.25);
  
  --bg-dark: #0B0F19;
  --bg-card: #131B2E;
  --bg-card-hover: #1A243D;
  --bg-card-alt: #1E293B;
  
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(220, 38, 38, 0.5);
  
  --text-main: #F8FAFC;
  --text-muted: #94A3B8;
  --text-subtle: #64748B;
  
  --accent-blue: #38BDF8;
  --accent-amber: #F59E0B;
  --accent-emerald: #10B981;
  --accent-purple: #A855F7;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px var(--pmi-primary-glow);

  --transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

html {
  overflow-x: hidden;
  max-width: 100vw;
  -webkit-text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

img, svg, video, canvas, audio, iframe, embed, object {
  display: block;
  max-width: 100%;
  height: auto;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-dark);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

/* Background Gradients */
.bg-glow {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  background: 
    radial-gradient(circle at 15% 15%, rgba(220, 38, 38, 0.12) 0%, transparent 40%),
    radial-gradient(circle at 85% 20%, rgba(56, 189, 248, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 50% 85%, rgba(220, 38, 38, 0.08) 0%, transparent 50%);
}

#app-container {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* NAVBAR */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  background: rgba(11, 15, 25, 0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  text-decoration: none;
}

.brand-cross {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #EF4444, #B91C1C);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.4);
  color: #fff;
  font-weight: 800;
  font-size: 1.3rem;
  user-select: none;
  flex-shrink: 0; /* CRITICAL: Prevent logo distortion on mobile */
}

.brand-text h1 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(to right, #FFFFFF, #FDA4AF);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.brand-badge {
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--pmi-red-800);
  color: #FFE4E6;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  letter-spacing: 0.5px;
  border: 1px solid rgba(225, 29, 72, 0.4);
  -webkit-text-fill-color: #FFE4E6;
}

.brand-tagline {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  list-style: none;
}

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.nav-link:hover, .nav-link.active {
  color: #FFFFFF;
  background: rgba(255, 255, 255, 0.06);
}

.nav-link.active {
  color: #FDA4AF;
  border-bottom: 2px solid var(--pmi-primary);
  border-radius: 6px 6px 0 0;
}

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

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font-main);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  user-select: none;
}

.btn-primary {
  background: linear-gradient(135deg, #DC2626, #B91C1C);
  color: #FFFFFF;
  box-shadow: 0 4px 16px rgba(220, 38, 38, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #EF4444, #DC2626);
  box-shadow: 0 6px 20px rgba(220, 38, 38, 0.5);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  border-color: var(--border-subtle);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
}

.btn-outline-danger {
  background: transparent;
  color: #F87171;
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-outline-danger:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: #EF4444;
}

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

.btn-lg {
  padding: 0.85rem 1.85rem;
  font-size: 1.05rem;
  border-radius: var(--radius-lg);
}

/* BADGES & CHIPS */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-primary {
  background: rgba(220, 38, 38, 0.2);
  color: #F87171;
  border: 1px solid rgba(220, 38, 38, 0.4);
}

.badge-supplementary {
  background: rgba(56, 189, 248, 0.15);
  color: #38BDF8;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.badge-active {
  background: rgba(16, 185, 129, 0.15);
  color: #34D399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-superseded {
  background: rgba(245, 158, 11, 0.15);
  color: #FBBF24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-draft {
  background: rgba(148, 163, 184, 0.15);
  color: #94A3B8;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.badge-archived {
  background: rgba(100, 116, 139, 0.15);
  color: #64748B;
  border: 1px solid rgba(100, 116, 139, 0.3);
}

/* MAIN CONTENT CONTAINER */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  width: 100%;
}

.view-section {
  display: none;
  width: 100%;
  animation: fadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.view-section.active {
  display: block;
}

#view-chat.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  width: 100%;
}

body.chat-mode {
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}

body.chat-mode #app-container {
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.chat-mode .navbar {
  flex-shrink: 0;
}

body.chat-mode .main-content {
  flex: 1;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: 0 !important;
}

body.chat-mode .footer {
  display: none !important;
}

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

/* HERO SECTION (LANDING) */
.hero-section {
  padding: 4rem 2rem 3rem;
  max-width: 1200px;
  margin: 0 auto;
  text-align: center;
}

.hero-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(220, 38, 38, 0.1);
  border: 1px solid rgba(220, 38, 38, 0.3);
  color: #FDA4AF;
  padding: 0.35rem 1rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
}

.hero-title {
  font-size: 3.2rem;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -1px;
  margin-bottom: 1.25rem;
  background: linear-gradient(135deg, #FFFFFF 30%, #FDA4AF 70%, #F43F5E 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-subtitle {
  font-size: 1.2rem;
  color: var(--text-muted);
  max-width: 720px;
  margin: 0 auto 2.5rem;
  line-height: 1.6;
}

.hero-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 3rem;
  flex-wrap: wrap;
}

/* QUICK TOPIC CARDS */
.quick-topics-container {
  max-width: 1200px;
  margin: 0 auto 4rem;
  padding: 0 2rem;
}

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

.section-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
}

.topic-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  transition: var(--transition);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.topic-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, var(--pmi-primary), transparent);
  opacity: 0;
  transition: var(--transition);
}

.topic-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-focus);
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.topic-card:hover::before {
  opacity: 1;
}

.topic-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: rgba(220, 38, 38, 0.12);
  color: #F87171;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  margin-bottom: 1rem;
  flex-shrink: 0; /* CRITICAL: Prevent icon squishing */
}

.topic-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.4rem;
}

.topic-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 1rem;
  flex: 1;
}

.topic-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-subtle);
  border-top: 1px solid var(--border-subtle);
  padding-top: 0.75rem;
}

/* FOOTER */
.footer {
  margin-top: auto;
  border-top: 1px solid var(--border-subtle);
  background: rgba(11, 15, 25, 0.95);
  padding: 2.5rem 2rem 1.5rem;
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1.5rem;
}

.footer-info p {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.footer-badge {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-subtle);
}

/* ====================================================
   MOBILE BOTTOM NAVIGATION BAR
   ==================================================== */
.mobile-bottom-nav {
  display: none;
}

.chat-mobile-header {
  display: none;
}

.chat-mobile-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: #FFF;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  flex: 1;
  min-width: 0;
}

@media (max-width: 768px) {
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 60px;
    background: rgba(11, 15, 25, 0.94);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-subtle);
    z-index: 999;
    align-items: center;
    justify-content: space-around;
    padding: 0 0.25rem;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
  }

  body.chat-mode .mobile-bottom-nav {
    display: none !important;
  }

  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-subtle);
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 0.35rem 0.5rem;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    cursor: pointer;
    background: transparent;
    border: none;
    flex: 1;
    text-align: center;
    user-select: none;
  }

  .mobile-nav-item:hover,
  .mobile-nav-item.active {
    color: #FDA4AF;
  }

  .mobile-nav-icon {
    font-size: 1.25rem;
    line-height: 1;
    transition: transform 0.2s ease;
  }

  .mobile-nav-item.active .mobile-nav-icon {
    transform: translateY(-2px);
    filter: drop-shadow(0 0 6px rgba(220, 38, 38, 0.6));
  }

  /* Padding on views to ensure content is never obscured by mobile bottom nav */
  body:not(.chat-mode) .main-content {
    padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px));
  }

  body:not(.chat-mode) .footer {
    margin-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
  }
}

/* ====================================================
   COMPREHENSIVE RESPONSIVE STYLES
   ==================================================== */
@media (max-width: 768px) {
  /* Prevent iOS Safari from auto-zooming and distorting page */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="file"],
  textarea,
  select {
    font-size: 16px !important;
  }

  /* Top Navbar */
  .navbar {
    padding: 0.6rem 0.85rem;
    min-height: 58px;
    gap: 0.5rem;
  }

  .nav-brand {
    gap: 0.5rem;
    min-width: 0;
    max-width: 75%;
  }

  .brand-cross {
    width: 32px;
    height: 32px;
    font-size: 1.15rem;
    border-radius: 8px;
  }

  .brand-text h1 {
    font-size: 1.05rem;
    letter-spacing: -0.3px;
  }

  .brand-badge {
    font-size: 0.58rem;
    padding: 0.1rem 0.35rem;
  }

  .brand-tagline {
    display: none; /* Hide tagline on mobile to keep header clean */
  }

  .nav-links {
    display: none; /* Handled via modern mobile bottom nav */
  }

  .nav-actions {
    gap: 0.35rem;
    flex-shrink: 0;
  }

  .nav-actions .btn {
    padding: 0.35rem 0.55rem;
    font-size: 0.78rem;
    gap: 0.25rem;
  }

  /* Hero Section */
  .hero-section {
    padding: 2rem 1rem 1.5rem;
  }

  .hero-pill {
    font-size: 0.75rem;
    padding: 0.35rem 0.75rem;
    margin-bottom: 1.25rem;
    white-space: normal;
    text-align: center;
    line-height: 1.4;
    border-radius: var(--radius-md);
  }

  .hero-title {
    font-size: 1.85rem;
    line-height: 1.25;
    letter-spacing: -0.5px;
    margin-bottom: 1rem;
    word-break: break-word;
  }

  br.hero-br {
    display: none;
  }

  .hero-subtitle {
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 1.75rem;
    padding: 0 0.25rem;
  }

  .hero-cta {
    flex-direction: column;
    width: 100%;
    gap: 0.75rem;
    margin-bottom: 2rem;
  }

  .hero-cta .btn {
    width: 100%;
    font-size: 0.95rem;
    padding: 0.75rem 1rem;
    justify-content: center;
  }

  .hero-quick-search {
    margin-bottom: 2rem !important;
    padding: 0 0.25rem;
  }

  .hero-quick-search .chat-form {
    padding: 0.4rem 0.6rem;
    gap: 0.4rem;
  }

  .hero-quick-search .chat-input {
    font-size: 0.85rem;
    min-width: 0;
  }

  .hero-quick-search .btn {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
  }

  /* Quick Topics */
  .quick-topics-container {
    padding: 0 1rem;
    margin-bottom: 2.5rem;
  }

  .section-header {
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .section-title {
    font-size: 1.2rem;
  }

  .quick-grid {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  .topic-card {
    padding: 1.15rem;
  }

  .topic-icon {
    width: 38px;
    height: 38px;
    font-size: 1.2rem;
    margin-bottom: 0.75rem;
  }

  .topic-title {
    font-size: 1.05rem;
  }

  .topic-desc {
    font-size: 0.82rem;
    margin-bottom: 0.75rem;
  }

  .chat-mobile-header {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.6rem 0.85rem;
    background: rgba(15, 23, 42, 0.95);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    z-index: 10;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
  }

  .chat-mobile-header .btn {
    flex-shrink: 0;
    white-space: nowrap;
  }

  /* Chat View Layout */
  #view-chat.active {
    flex: 1;
    height: 100%;
    min-height: 0;
    max-height: 100%;
  }

  .chat-layout {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    height: 100% !important;
  }

  .chat-main {
    width: 100% !important;
    max-width: 100% !important;
    flex: 1 !important;
  }

  /* Mobile Chat Sidebar Overlay / Drawer */
  .chat-sidebar {
    position: fixed;
    top: 0;
    left: -300px;
    width: 285px;
    max-width: 85vw;
    height: 100vh;
    height: 100dvh;
    z-index: 1050;
    transition: left 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 0 35px rgba(0, 0, 0, 0.85);
    background: #0D1322;
    display: flex !important;
    flex-direction: column;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .chat-sidebar-close-btn {
    display: flex !important;
  }

  .chat-sidebar.open {
    left: 0;
  }

  .chat-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1040;
  }

  .chat-sidebar-backdrop.active {
    display: block;
  }

  .chat-messages {
    padding: 0.75rem 0.75rem 1rem;
    gap: 1rem;
    max-width: 100%;
    box-sizing: border-box;
  }

  .chat-input-container {
    padding: 0.5rem 0.75rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .prompt-suggestions {
    padding-bottom: 0.45rem;
  }

  .prompt-pill {
    font-size: 0.72rem;
    padding: 0.25rem 0.65rem;
  }

  .chat-form {
    padding: 0.35rem 0.5rem;
    gap: 0.4rem;
  }

  .chat-input {
    font-size: 0.9rem;
    padding: 0.35rem;
    min-width: 0;
  }

  #btn-send-chat {
    flex-shrink: 0;
    padding: 0.45rem 0.85rem;
    font-size: 0.85rem;
  }

  /* Page Containers (Materials, Sources, Admin, Profile) */
  .page-container {
    margin: 1rem auto !important;
    padding: 0 1rem !important;
  }

  .page-title {
    font-size: 1.55rem !important;
    line-height: 1.25;
  }

  .page-subtitle {
    font-size: 0.85rem !important;
  }

  .materials-header {
    margin-bottom: 1.25rem !important;
    gap: 0.75rem !important;
  }

  .materials-filter-bar {
    width: 100%;
    flex-direction: column;
    gap: 0.5rem !important;
  }

  .materials-filter-bar select,
  .materials-filter-bar input {
    width: 100% !important;
  }

  /* Footer */
  .footer {
    padding: 1.5rem 1rem 1.25rem;
  }

  .footer-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .footer-badge {
    flex-direction: column;
    gap: 0.35rem;
  }
}

@media (max-width: 480px) {
  .hero-title {
    font-size: 1.6rem;
  }

  .navbar {
    padding: 0.5rem 0.65rem;
  }

  .brand-cross {
    width: 30px;
    height: 30px;
    font-size: 1.05rem;
  }

  .brand-text h1 {
    font-size: 0.95rem;
  }
}
