/* ══════════════════════════════════════════════════
   TRICARE Manuals — Web App Styles
   ══════════════════════════════════════════════════ */

/* ── CSS Custom Properties ─────────────────────── */
:root {
  --navy:          #003087;
  --navy-dark:     #001d5e;
  --navy-light:    #1a53b0;
  --accent:        #1976d2;
  --accent-light:  #e3f0ff;
  --surface:       #ffffff;
  --surface-2:     #f4f6f9;
  --border:        #dde2ea;
  --text-primary:  #1a1e2a;
  --text-secondary:#5a6278;
  --text-on-navy:  #ffffff;
  --toc-width:     300px;
  --reader-bar-h:  56px;
  --section-nav-h: 52px;
  --transition:    0.2s ease;
  --radius:        10px;
  --shadow-sm:     0 1px 4px rgba(0,0,0,.10);
  --shadow-md:     0 4px 16px rgba(0,0,0,.13);
}

[data-dark] {
  --navy:          #1a3a6e;
  --navy-dark:     #0f2347;
  --navy-light:    #2d5a9e;
  --accent:        #4d8de8;
  --accent-light:  #1a2d4a;
  --surface:       #1a1e2a;
  --surface-2:     #121520;
  --border:        #2a3045;
  --text-primary:  #e8ecf4;
  --text-secondary:#8892a8;
  --text-on-navy:  #ffffff;
  --shadow-sm:     0 1px 4px rgba(0,0,0,.30);
  --shadow-md:     0 4px 16px rgba(0,0,0,.40);
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--surface-2);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

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

/* ── Utility ────────────────────────────────────── */
.hidden  { display: none !important; }
.ml-auto { margin-left: auto; }

/* ── Views ──────────────────────────────────────── */
.view { display: none; min-height: 100dvh; }
.view.active { display: flex; flex-direction: column; }
#view-reader.active { display: block; height: 100dvh; overflow: hidden; }

/* ══════════════════════════════════════════════════
   HOME VIEW
   ══════════════════════════════════════════════════ */

/* App Bar */
.home-bar {
  background: var(--navy);
  color: var(--text-on-navy);
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 10;
}

.home-bar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.home-bar-logo {
  width: 40px;
  height: 40px;
  background: rgba(255,255,255,.15);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.home-bar-title {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: .01em;
}

.home-bar-subtitle {
  font-size: .78rem;
  opacity: .75;
  margin-top: 1px;
}

/* Hero banner */
.hero-banner {
  width: 100%;
  background: #0a1628;
  line-height: 0;
}
.hero-banner-img {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  object-position: center;
}

/* Main content */
.home-main {
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 16px 60px;
  width: 100%;
}

/* Manual Cards */
.manual-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 360px));
  gap: 16px;
  margin-bottom: 32px;
  justify-content: center;
}

/* Skeleton loaders */
.skeleton-card {
  background: var(--surface);
  border-radius: var(--radius);
  height: 140px;
  animation: skeleton-pulse 1.4s ease-in-out infinite;
}

@keyframes skeleton-pulse {
  0%, 100% { opacity: .6; }
  50%       { opacity: .25; }
}

/* Real manual card */
.manual-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), transform var(--transition);
  cursor: default;
}

.manual-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.manual-card-icon {
  width: 40px;
  height: 40px;
  background: var(--navy);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.manual-card-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.manual-card-meta {
  font-size: .82rem;
  color: var(--text-secondary);
}

.manual-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: .78rem;
  font-weight: 600;
}

[data-dark] .chip {
  color: #8fbfff;
}

.no-content-chip {
  background: #fff3e0;
  color: #e65100;
}

[data-dark] .no-content-chip {
  background: #3a2000;
  color: #ffb74d;
}

/* Buttons */
.btn-primary {
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 20px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
}

.btn-primary:hover { background: var(--navy-light); }
.btn-primary:disabled {
  background: var(--border);
  color: var(--text-secondary);
  cursor: not-allowed;
}

.icon-btn {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  border-radius: 8px;
  padding: 6px 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(128,128,128,.12); }

/* Export buttons on home cards (Download .md / Print PDF) */
.manual-card-exports {
  display: flex;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.btn-export-card {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: .78rem;
  font-weight: 600;
  padding: 6px 8px;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
}
.btn-export-card:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}
.btn-export-card svg { flex-shrink: 0; }

/* Home support link */
.home-support {
  font-size: .8rem;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 8px;
}

/* Visitor counter — retro easter egg 🥚 */
.visitor-counter {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-top: 16px;
  background: #0a0a0a;
  border: 2px solid #2a2a2a;
  border-radius: 6px;
  padding: 8px 20px;
  font-family: 'Courier New', Courier, monospace;
  box-shadow: inset 0 2px 6px rgba(0,0,0,.7), 0 0 12px rgba(0,200,80,.1);
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
  cursor: default;
  user-select: none;
}

.vc-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0 16px;
}

.vc-label {
  font-size: .6rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: #3a8a5a;
}

.vc-num {
  font-size: 1.3rem;
  font-weight: bold;
  letter-spacing: .15em;
  color: #00e060;
  min-width: 6ch;
  text-align: center;
  text-shadow: 0 0 8px rgba(0,220,80,.6);
}

.vc-divider {
  width: 1px;
  height: 36px;
  background: #2a2a2a;
  flex-shrink: 0;
}

/* Support / buy me a drink row */
.support-row {
  display: flex;
  justify-content: center;
  margin-top: 24px;
}

.btn-support {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #FFDD00;
  color: #000;
  font-weight: 700;
  font-size: .92rem;
  padding: 10px 24px;
  border-radius: 24px;
  text-decoration: none;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
  white-space: nowrap;
}
.btn-support:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  text-decoration: none;
}

/* Logo image */
.home-bar-logo img {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  display: block;
}

/* Home footer note */
.home-note {
  font-size: .82rem;
  color: var(--text-secondary);
  text-align: center;
  max-width: 560px;
  margin: 0 auto;
  line-height: 1.6;
}

/* ══════════════════════════════════════════════════
   READER VIEW
   ══════════════════════════════════════════════════ */

.reader-layout {
  display: flex;
  height: 100dvh;
  position: relative;
  overflow: hidden;
}

/* ── TOC Sidebar ────────────────────────────────── */
.toc-panel {
  width: var(--toc-width);
  min-width: var(--toc-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform var(--transition);
  z-index: 20;
}

.toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--navy);
  color: var(--text-on-navy);
  flex-shrink: 0;
}

.toc-title {
  font-weight: 600;
  font-size: .95rem;
}

.toc-header .icon-btn { color: var(--text-on-navy); }
.toc-header .icon-btn { display: none; } /* hidden on desktop */

.toc-search-wrap {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#toc-search {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: .85rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition);
}
#toc-search:focus { border-color: var(--accent); }
#toc-search::placeholder { color: var(--text-secondary); }

.toc-list {
  overflow-y: auto;
  flex: 1;
  padding: 6px 0;
}

/* TOC Items */
.toc-item {
  display: block;
  padding: 8px 16px;
  font-size: .85rem;
  color: var(--text-primary);
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
  line-height: 1.4;
}

.toc-item:hover { background: var(--accent-light); color: var(--accent); }

.toc-item.active {
  background: var(--accent-light);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

.toc-item.chapter-heading {
  font-weight: 700;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-secondary);
  padding-top: 14px;
  cursor: default;
  pointer-events: none;
  border-left-color: transparent !important;
  background: none !important;
}

.toc-item.section-item { padding-left: 24px; }

/* overlay (mobile) */
.toc-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 15;
  cursor: pointer;
}

/* ── Reader Main ────────────────────────────────── */
.reader-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.reader-bar {
  height: var(--reader-bar-h);
  background: var(--navy);
  color: var(--text-on-navy);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 8px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.back-btn {
  background: none;
  border: none;
  color: var(--text-on-navy);
  cursor: pointer;
  border-radius: 8px;
  padding: 6px 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .9rem;
  font-weight: 500;
  transition: background var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
}
.back-btn:hover { background: rgba(255,255,255,.15); }

.reader-bar-center {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
}

.reader-manual-name {
  font-weight: 600;
  font-size: .9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.reader-change-badge {
  font-size: .72rem;
  opacity: .8;
}

.toc-toggle-btn { color: var(--text-on-navy); display: none; }

.reader-body {
  flex: 1;
  overflow-y: auto;
  background: var(--surface-2);
}

.reader-content {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

/* Section content styling */
.reader-content h1,
.reader-content h2,
.reader-content h3,
.reader-content h4 {
  color: var(--text-primary);
  margin: 1.4em 0 .5em;
  line-height: 1.3;
}
.reader-content h1 { font-size: 1.4rem; border-bottom: 2px solid var(--border); padding-bottom: .4em; }
.reader-content h2 { font-size: 1.2rem; }
.reader-content h3 { font-size: 1.05rem; }

.reader-content p { margin: .75em 0; font-size: .95rem; }
.reader-content ul,
.reader-content ol { margin: .75em 0 .75em 1.5em; font-size: .95rem; }
.reader-content li { margin-bottom: .3em; }

.reader-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  font-size: .88rem;
  overflow-x: auto;
  display: block;
}
.reader-content th,
.reader-content td {
  border: 1px solid var(--border);
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
}
.reader-content th {
  background: var(--navy);
  color: #fff;
  font-weight: 600;
}
.reader-content tr:nth-child(even) td { background: var(--surface-2); }

.reader-content a { color: var(--accent); }

.reader-content img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

/* Splash / empty state */
.splash {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  color: var(--text-secondary);
  font-size: 1rem;
}

/* Loading spinner */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 300px;
  color: var(--text-secondary);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* No-content message */
.no-content-msg {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}
.no-content-msg strong { display: block; font-size: 1.1rem; color: var(--text-primary); margin-bottom: 8px; }
.no-content-msg a { color: var(--accent); }

/* Section prev/next nav */
.section-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--section-nav-h);
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.section-nav-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 16px;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--accent);
  transition: background var(--transition), border-color var(--transition);
}
.section-nav-btn:hover:not(:disabled) { background: var(--accent-light); border-color: var(--accent); }
.section-nav-btn:disabled { color: var(--text-secondary); cursor: not-allowed; border-color: var(--border); }

.section-counter {
  font-size: .78rem;
  color: var(--text-secondary);
}

/* ══════════════════════════════════════════════════
   TOAST
   ══════════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #333;
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: .88rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  z-index: 100;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ══════════════════════════════════════════════════
   PRINT / PDF
   ══════════════════════════════════════════════════ */

#print-container { display: none; }

@media print {
  /* Hide the entire SPA; show only the print container */
  #app, #toast { display: none !important; }

  #print-container {
    display: block !important;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 11pt;
    line-height: 1.6;
    color: #000;
  }

  #print-container h1 {
    font-size: 20pt;
    font-weight: 700;
    border-bottom: 2px solid #003087;
    padding-bottom: 6pt;
    margin-bottom: 4pt;
    color: #003087;
  }

  #print-container .pm {          /* print meta line */
    font-size: 9pt;
    color: #555;
    margin-bottom: 28pt;
  }

  /* Each section gets its own logical block */
  .ps {
    margin-bottom: 24pt;
    page-break-inside: avoid;
  }

  .ps h2 {
    font-size: 13pt;
    font-weight: 700;
    color: #003087;
    border-bottom: 1px solid #ccc;
    padding-bottom: 3pt;
    margin: 0 0 8pt;
    page-break-after: avoid;
  }

  .ps p  { margin: 4pt 0; font-size: 10.5pt; }
  .ps ul,
  .ps ol { margin: 4pt 0 4pt 18pt; font-size: 10.5pt; }
  .ps li { margin-bottom: 2pt; }

  .ps table {
    border-collapse: collapse;
    width: 100%;
    font-size: 9pt;
    margin: 6pt 0;
  }
  .ps th,
  .ps td {
    border: 1px solid #aaa;
    padding: 3pt 6pt;
    vertical-align: top;
  }
  .ps th {
    background: #dde8f5 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    font-weight: 700;
  }

  /* Alternate row shading */
  .ps tr:nth-child(even) td {
    background: #f5f7fa !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  a { color: #000; text-decoration: underline; }

  @page {
    margin: 0.75in;
    size: letter portrait;
  }
}

/* ══════════════════════════════════════════════════
   MOBILE / RESPONSIVE  (≤768px)
   ══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  :root { --toc-width: min(300px, 88vw); }

  .toc-panel {
    position: fixed;
    top: 0;
    left: 0;
    height: 100dvh;
    transform: translateX(-100%);
    box-shadow: var(--shadow-md);
  }
  .toc-panel.open  { transform: translateX(0); }
  .toc-header .icon-btn { display: inline-flex; }

  .toc-overlay { display: block; }
  .toc-overlay.visible { display: block; pointer-events: auto; }

  .toc-toggle-btn { display: inline-flex; }

  .reader-bar { gap: 4px; padding: 0 8px 0 4px; }

  .reader-content { padding: 16px 14px 40px; }

  .manual-grid { grid-template-columns: 1fr; }

  .back-btn span { display: none; }

  .home-main { padding: 20px 12px 60px; }

  /* 2 columns on tablet */
  .manual-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  /* 1 column on phone */
  .manual-grid { grid-template-columns: 1fr; }
}
