/* Hadara Academic Standalone Reader */
* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, Arial, sans-serif;
  color: #153A5B;
  background: #eef3f8;
  direction: rtl;
}

html[dir="ltr"], html[dir="ltr"] body {
  direction: ltr;
}

.hadara-standalone-reader {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  min-height: 0;
}

/* Header styled with unified Quality Assurance palette */
.hadara-reader-header {
  height: 52px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 20px;
  background: #153A5B;
  border-bottom: 1px solid #0d273e;
  box-shadow: 0 2px 8px rgba(15, 43, 67, 0.15);
  color: #ffffff;
  z-index: 10;
}

.hadara-reader-versions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.hadara-reader-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
  flex: 1;
  min-width: 0;
  padding: 0 8px;
  letter-spacing: -0.2px;
}

html[dir="ltr"] .hadara-reader-title {
  text-align: left;
}

.hadara-reader-header.has-versions .hadara-reader-title {
  text-align: center;
}

.hadara-reader-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.hadara-reader-actions button,
.hadara-reader-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.hadara-reader-actions button:hover,
.hadara-reader-actions a:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.45);
  color: #ffffff;
  transform: translateY(-1px);
}

.hadara-reader-actions button:active,
.hadara-reader-actions a:active {
  transform: translateY(0);
}

/* Version buttons */
.hadara-version-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 14px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.hadara-version-btn:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.5);
}

.hadara-version-btn.active {
  background: #ffffff !important;
  color: #153A5B !important;
  border-color: #ffffff !important;
  font-weight: 700 !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Standalone Content */
.hadara-standalone-content {
  flex: 1;
  min-height: 0;
  width: 100%;
  height: calc(100vh - 52px);
  position: relative;
  background: #eef3f8;
  overflow: hidden;
}

/* Reader Wrap */
.hadara-document-reader-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: stretch;
  overflow: hidden;
  box-sizing: border-box;
}

.hadara-document-reader {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: center;
  gap: 16px; /* Exactly adjacent with 16px gap! */
  width: 100%;
  max-width: 1180px;
  height: 100%;
  padding: 16px 20px;
  box-sizing: border-box;
  position: relative;
}

/* Side Thumbnails (الورق الجانبي الصغير - أكبر وأوضح وأجمل تنسيقاً) */
.hadara-document-thumbnails {
  width: 212px;
  flex: 0 0 212px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border: 1px solid #c4d3e2;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 18px rgba(21, 58, 91, 0.09);
}

.hadara-document-thumbnails-header {
  padding: 12px 16px;
  background: #153A5B;
  color: #ffffff;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #0d273e;
  flex-shrink: 0;
  letter-spacing: -0.2px;
}

.hadara-document-total {
  font-size: 12px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
  padding: 2px 9px;
  border-radius: 12px;
}

/* In RTL: direction ltr puts scrollbar on outer right edge, away from document */
html[dir="rtl"] .hadara-document-thumbnails-list {
  direction: ltr;
}
html[dir="ltr"] .hadara-document-thumbnails-list {
  direction: rtl;
}

.hadara-document-thumbnails-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  scrollbar-width: thin;
  scrollbar-color: #9ebcd3 #dfe5ee;
}

.hadara-document-thumbnail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #f7fafc;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-sizing: border-box;
  direction: rtl;
  position: relative;
}

html[dir="ltr"] .hadara-document-thumbnail {
  direction: ltr;
}

.hadara-document-thumbnail:hover {
  background: #eef5fb;
  border-color: #bcd0e2;
  transform: translateY(-1px);
}

.hadara-document-thumbnail.active,
.hadara-document-thumbnail[aria-current="page"] {
  background: #eaf2f9;
  border-color: #153A5B;
  box-shadow: 0 4px 14px rgba(21, 58, 91, 0.18);
  transform: translateY(-1px);
}

.hadara-document-thumbnail canvas {
  display: block;
  width: 100% !important;
  height: auto !important;
  background: #ffffff;
  border: 1px solid #d4e0ec;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(15, 43, 67, 0.08);
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  transition: box-shadow 0.2s, border-color 0.2s;
}

.hadara-document-thumbnail:hover canvas {
  box-shadow: 0 4px 12px rgba(15, 43, 67, 0.14);
}

.hadara-document-thumbnail.active canvas {
  border-color: #153A5B;
  box-shadow: 0 4px 14px rgba(21, 58, 91, 0.22);
}

.hadara-document-thumbnail .hadara-thumb-label {
  font-size: 13px;
  font-weight: 700;
  color: #153A5B;
  background: #e4edf5;
  padding: 2px 14px;
  border-radius: 12px;
  min-width: 36px;
  text-align: center;
  line-height: 1.5;
  transition: all 0.2s;
}

.hadara-document-thumbnail.active .hadara-thumb-label {
  background: #153A5B;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(21, 58, 91, 0.35);
}

/* Big Document Canvas Wrap (الورق الكبير - نزول وصعود) */
html[dir="rtl"] .hadara-document-canvas-wrap {
  direction: ltr;
}
html[dir="ltr"] .hadara-document-canvas-wrap {
  direction: rtl;
}

.hadara-document-canvas-wrap {
  flex: 1;
  max-width: 900px;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  background: #d8e2ec;
  border: 1px solid #c8d7e6;
  border-radius: 8px;
  padding: 24px 32px;
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: #9ebcd3 #dfe5ee;
  position: relative;
  outline: none;
}

.hadara-document-pages-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 100%;
  direction: rtl;
}

html[dir="ltr"] .hadara-document-pages-container {
  direction: ltr;
}

.hadara-document-page-card {
  background: #ffffff;
  border-radius: 4px;
  box-shadow: 0 4px 20px rgba(21, 58, 91, 0.16);
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  overflow: hidden;
  transition: box-shadow 0.2s ease;
}

.hadara-document-page-card canvas {
  display: block;
  background: #ffffff;
  image-rendering: -webkit-optimize-contrast;
}

/* Spinner & Loading */
.hadara-document-loading-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.96);
  padding: 22px 34px;
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(21, 58, 91, 0.18);
  font-weight: 700;
  color: #153A5B;
  z-index: 5;
  direction: rtl;
}

.hadara-document-loading-indicator.hidden {
  display: none !important;
}

.hadara-spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(21, 58, 91, 0.18);
  border-top-color: #153A5B;
  border-radius: 50%;
  animation: hadara-spin 0.8s linear infinite;
}

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

/* Responsive adjustments */
@media (max-width: 860px) {
  .hadara-document-reader {
    gap: 10px;
    padding: 10px;
  }
  .hadara-document-thumbnails {
    width: 140px;
    flex: 0 0 140px;
  }
  .hadara-document-canvas-wrap {
    padding: 12px;
  }
  .hadara-document-pages-container {
    gap: 14px;
  }
}

@media (max-width: 768px) {
  .hadara-reader-header {
    height: auto;
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 8px;
  }
  .hadara-reader-title {
    order: -1;
    width: 100%;
    margin-bottom: 2px;
  }
  .hadara-reader-actions button,
  .hadara-reader-actions a,
  .hadara-version-btn {
    font-size: 11px;
    padding: 4px 8px;
  }
  .hadara-standalone-content {
    height: calc(100vh - 84px);
  }
}

@media (max-width: 600px) {
  .hadara-document-reader {
    flex-direction: column;
  }
  .hadara-document-thumbnails {
    width: 100%;
    flex: 0 0 134px;
    height: 134px;
  }
  .hadara-document-thumbnails-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .hadara-document-thumbnail {
    width: 90px;
    flex: 0 0 90px;
  }
}
