/* ==========================================================================
   දියුණුවට මඟ (Diyunuwata Maga) — Reader & Portal Stylesheet
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Sinhala:wght@400;500;600;700;800&family=Outfit:wght@400;500;600;700&display=swap');

:root {
  --yellow: #edc642;
  --yellow-hover: #f4d566;
  --ink: #151713;
  --ink-light: #242820;
  --muted: #656760;
  --paper: #faf9f4;
  --card-bg: #ffffff;
  --line: #e4e4dc;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 3px rgba(21, 23, 19, 0.05);
  --shadow-md: 0 4px 16px rgba(21, 23, 19, 0.08);
  --shadow-lg: 0 10px 30px rgba(21, 23, 19, 0.12);
  --green: #10b981;
  --red: #ef4444;
}

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

html, body {
  background: var(--paper);
  color: var(--ink);
  font-family: 'Noto Sans Sinhala', 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* --------------------------------------------------------------------------
   Layout Containers & Headers
   -------------------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.top-bar {
  background: rgba(250, 249, 244, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 100;
}

.top-bar-inner {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo-badge {
  width: 42px;
  height: 42px;
  background: var(--yellow);
  color: var(--ink);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 20px;
  box-shadow: 0 2px 8px rgba(237, 198, 66, 0.4);
}

.brand-text h1 {
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.2;
}

.brand-text span {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  display: block;
}

/* --------------------------------------------------------------------------
   Buttons & Pills
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 15px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--yellow);
  color: var(--ink);
}

.btn-primary:hover {
  background: var(--yellow-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(237, 198, 66, 0.35);
}

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

.btn-dark:hover {
  background: var(--ink-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(21, 23, 19, 0.25);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.btn-outline:hover {
  background: #ffffff;
  border-color: var(--ink);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.btn-danger {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fecaca;
}

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

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --------------------------------------------------------------------------
   Alerts & Notifications
   -------------------------------------------------------------------------- */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.alert-success {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.alert-error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* --------------------------------------------------------------------------
   Cards & Layout Components
   -------------------------------------------------------------------------- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.card-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --------------------------------------------------------------------------
   Form Elements
   -------------------------------------------------------------------------- */
.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--ink);
}

.form-control {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  outline: none;
  transition: all 0.2s ease;
}

.form-control:focus {
  border-color: #b28a00;
  box-shadow: 0 0 0 3px rgba(237, 198, 66, 0.25);
}

.form-help {
  font-size: 12px;
  color: var(--muted);
  margin-top: 5px;
}

/* --------------------------------------------------------------------------
   Stats Grid (Admin Dashboard)
   -------------------------------------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.stat-card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.stat-card.highlight {
  border-left: 5px solid var(--yellow);
}

.stat-card.online-highlight {
  border-left: 5px solid var(--green);
}

.stat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.1;
  font-family: 'Outfit', sans-serif;
}

.stat-meta {
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
}

/* Live Pulse Indicator */
.pulse-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  background-color: var(--green);
  border-radius: 50%;
  position: relative;
}

.pulse-dot::after {
  content: '';
  position: absolute;
  top: -3px;
  left: -3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(16, 185, 129, 0.4);
  animation: pulse-ring 1.8s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(0.7); opacity: 0.9; }
  100% { transform: scale(2.2); opacity: 0; }
}

/* --------------------------------------------------------------------------
   Table & Badges
   -------------------------------------------------------------------------- */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

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

.data-table th {
  background: #f7f6f0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.data-table th:first-child {
  border-top-left-radius: var(--radius-md);
}

.data-table th:last-child {
  border-top-right-radius: var(--radius-md);
}

.data-table td {
  padding: 16px 18px;
  font-size: 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background: #fdfdfc;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
}

.badge-success {
  background: #ecfdf5;
  color: #059669;
}

.badge-warning {
  background: #fef3c7;
  color: #d97706;
}

.badge-muted {
  background: #f3f4f6;
  color: #6b7280;
}

/* --------------------------------------------------------------------------
   Login Page Styling
   -------------------------------------------------------------------------- */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: radial-gradient(circle at 50% 10%, #fffbe6 0%, var(--paper) 70%);
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 36px 30px;
  box-shadow: var(--shadow-lg);
}

.auth-header {
  text-align: center;
  margin-bottom: 28px;
}

.auth-header .brand-logo-badge {
  margin: 0 auto 16px;
  width: 56px;
  height: 56px;
  font-size: 26px;
}

.auth-header h2 {
  font-size: 24px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.3;
}

.auth-header p {
  color: var(--muted);
  font-size: 14px;
  margin-top: 6px;
}

.auth-help-box {
  margin-top: 24px;
  padding: 16px;
  background: #fbfbfa;
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

/* --------------------------------------------------------------------------
   Mobile-First Reader Component Styling
   -------------------------------------------------------------------------- */
.reader-page {
  position: fixed;
  inset: 0;
  background: #202225;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* Themes for Reader */
.reader-theme-day {
  background: #faf9f4;
  color: #151713;
}

.reader-theme-sepia {
  background: #f4ecd8;
  color: #3e3124;
}

.reader-theme-night {
  background: #181a1b;
  color: #d1cdc7;
}

.reader-nav {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 95vw;
  width: auto;
  height: 46px;
  background: rgba(18, 20, 22, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  gap: 8px;
  z-index: 100;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
}

.reader-nav.hidden {
  transform: translateX(-50%) translateY(-70px);
  opacity: 0;
  pointer-events: none;
}

.reader-dock {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 95vw;
  width: auto;
  height: 46px;
  background: rgba(18, 20, 22, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  gap: 12px;
  z-index: 100;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
}

.reader-dock.hidden {
  transform: translateX(-50%) translateY(70px);
  opacity: 0;
  pointer-events: none;
}

.reader-viewport {
  position: fixed;
  inset: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 64px 10px 72px 10px;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  touch-action: pan-x pan-y pinch-zoom;
}

.canvas-container {
  position: relative;
  box-shadow: 0 8px 35px rgba(0, 0, 0, 0.45);
  border-radius: 4px;
  background: #ffffff;
  margin: auto;
  flex-shrink: 0;
  transition: transform 0.12s ease-out;
}

#pdf-canvas {
  display: block;
  /* Removed max-width: 100% so full zoom expands freely without scratching or squishing */
}

/* Watermark overlay - clearly visible to deter piracy, yet translucent for reading */
.watermark-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(5, 1fr);
  opacity: 0.07; /* Clearly visible, legible deterrent */
  z-index: 10;
}

.watermark-item {
  transform: rotate(-30deg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #111111;
  text-align: center;
  line-height: 1.25;
}

/* PDF Clickable Links Layer */
.pdf-links-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 15;
}

.pdf-interactive-link {
  position: absolute;
  pointer-events: auto;
  background: rgba(237, 198, 66, 0.08);
  border-radius: 3px;
  border-bottom: 1.5px solid rgba(237, 198, 66, 0.7);
  cursor: pointer;
  transition: background 0.15s ease;
}

.pdf-interactive-link:hover {
  background: rgba(237, 198, 66, 0.25);
}

.pdf-interactive-link:active {
  background: rgba(237, 198, 66, 0.4);
}

/* Tap Navigation Zones on Mobile */
.tap-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 30;
}

.tap-zone.tap-left {
  left: 0;
  width: 18%;
}

.tap-zone.tap-right {
  right: 0;
  width: 18%;
}

/* Toast Notification */
.reader-toast {
  position: fixed;
  top: 66px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(21, 23, 19, 0.92);
  color: #ffffff;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(237, 198, 66, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 9999;
}

.reader-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Quick Page Jump Modal & Bookmarks Drawer */
.reader-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 999;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

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

.reader-modal-card {
  background: #ffffff;
  color: var(--ink);
  max-width: 420px;
  width: 100%;
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  box-shadow: var(--shadow-lg);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.bookmark-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 6px;
  background: #f9f9f6;
  border: 1px solid var(--line);
  margin-bottom: 8px;
  transition: background 0.15s ease;
}

.bookmark-item:hover {
  background: #f1efdf;
}

/* Anti-Capture Shield Overlay */
.privacy-shield {
  display: none;
  position: fixed;
  inset: 0;
  background: #151713;
  color: #ffffff;
  z-index: 9999;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 30px;
}

.privacy-shield.active {
  display: flex;
}

.privacy-shield h3 {
  font-size: 22px;
  color: var(--yellow);
  margin-bottom: 12px;
}

.privacy-shield p {
  color: #aaa;
  max-width: 420px;
  font-size: 15px;
}

/* Reading Progress Bar */
.reader-progress-track {
  height: 4px;
  width: 100%;
  background: rgba(255, 255, 255, 0.2);
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 52;
}

.reader-progress-bar {
  height: 100%;
  background: var(--yellow);
  width: 0%;
  transition: width 0.2s ease;
}

/* --------------------------------------------------------------------------
   Print protection: completely hide on print
   -------------------------------------------------------------------------- */
@media print {
  body, html, * {
    display: none !important;
    visibility: hidden !important;
  }
}

/* --------------------------------------------------------------------------
   Mobile responsiveness
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  body {
    font-size: 15px;
  }

  .top-bar-inner {
    height: 64px;
  }

  .brand-text h1 {
    font-size: 17px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .stat-card {
    padding: 16px;
  }

  .stat-value {
    font-size: 24px;
  }

  .card {
    padding: 16px;
    border-radius: var(--radius-md);
  }

  .auth-card {
    padding: 24px 18px;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}
