/* ==========================================================================
   Document Annotator Stylesheet
   ========================================================================== */

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: #f0f0f0;
  color: #333;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

/* --- Toolbar --- */
#toolbar {
  height: 52px;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.toolbar-left .app-title {
  font-size: 19px;
  font-weight: 700;
  color: #2c3e50;
  letter-spacing: -0.5px;
}

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

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

#page-info {
  font-size: 14px;
  font-weight: 500;
  color: #555;
  min-width: 90px;
  text-align: center;
  user-select: none;
}

/* --- Buttons --- */
.tool-btn {
  background: #ffffff;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: #444;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  user-select: none;
}

.tool-btn:hover {
  background: #f7f7f7;
  border-color: #ccc;
}

.tool-btn.active {
  background: #002eac;
  color: #ffffff;
  border-color: #002eac;
}

.nav-btn {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 10px;
  color: #555;
  border-radius: 4px;
  transition: background-color 0.15s ease, color 0.15s ease;
  user-select: none;
}

.nav-btn:hover {
  background: #f0f0f0;
  color: #111;
}

.save-btn {
  background: #002eac;
  color: #ffffff;
  border: none;
  border-radius: 6px;
  padding: 8px 20px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
  transition: background-color 0.2s ease;
}

.save-btn:hover {
  background: #d4952e;
}

.mic-btn {
  font-size: 16px;
  padding: 6px 10px;
}

.mic-btn.recording {
  background: #ff4444 !important;
  color: #ffffff !important;
  border-color: #ff4444 !important;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* --- Main Content Area --- */
#content {
  flex: 1;
  position: relative;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* --- PDF View --- */
#pdf-view {
  padding: 24px 16px;
  overflow-y: auto;
}

#pdf-container {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
}

#pdf-canvas {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  background: #ffffff;
}

/* --- Reader View --- */
#reader-view {
  background-color: #f6f7fa;
  min-height: calc(100vh - 52px);
  padding: 40px 20px 80px;
}

#reader-content {
  max-width: 680px;
  margin: 0 auto;
  color: #111a2d;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 19px;
  line-height: 1.85;
}

.reader-page {
  margin-bottom: 48px;
  padding-bottom: 24px;
  border-bottom: 1px dashed #dcd3c3;
}

.reader-page:last-child {
  border-bottom: none;
}

.page-header {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #8c7d6b;
  margin-bottom: 24px;
  padding-bottom: 8px;
  border-bottom: 1px solid #eae2d3;
}

#reader-content p {
  margin-bottom: 1.5em;
  text-align: justify;
}

#reader-content p:last-child {
  margin-bottom: 0;
}

/* Words & Highlighting */
.word {
  display: inline;
  cursor: pointer;
  border-radius: 2px;
  padding: 1px 0;
  transition: background-color 0.12s ease;
  user-select: text;
}

.word:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

.word.highlighted {
  background-color: rgba(255, 235, 120, 0.4);
  box-shadow: 0 1px 0 #002eac;
}

.word.selecting {
  background-color: rgba(100, 149, 237, 0.3);
}

.word.selected {
  background-color: rgba(255, 213, 79, 0.5);
  box-shadow: 0 1px 0 #d4952e;
}

/* Error and empty state in reader */
.error {
  color: #c0392b;
  background: #fdf2f2;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid #f8d7da;
  font-family: sans-serif;
  font-size: 15px;
  text-align: center;
}

/* --- Annotation Popup --- */
.popup {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 420px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(0, 0, 0, 0.08);
  z-index: 1000;
  overflow: hidden;
  border: 1px solid #eee;
  animation: slideUpPopup 0.25s ease-out;
}

@keyframes slideUpPopup {
  from {
    transform: translate(-50%, 20px);
    opacity: 0;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}

.popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #f0f0f0;
}

.popup-title {
  font-size: 15px;
  font-weight: 600;
  color: #333;
}

.popup-close {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: #999;
  padding: 4px 8px;
  border-radius: 4px;
  line-height: 1;
}

.popup-close:hover {
  color: #333;
  background: #f5f5f5;
}

.selected-quote {
  border-left: 3px solid #002eac;
  background: #e9eef9;
  padding: 10px 14px;
  font-style: italic;
  font-size: 14px;
  color: #555;
  margin: 12px 16px 0;
  border-radius: 0 6px 6px 0;
  max-height: 80px;
  overflow-y: auto;
  line-height: 1.4;
}

.popup-body {
  padding: 12px 16px 16px;
}

#comment-input {
  width: 100%;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  min-height: 70px;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.2s ease;
}

#comment-input:focus {
  border-color: #002eac;
  box-shadow: 0 0 0 2px rgba(232, 168, 56, 0.15);
}

.popup-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.name-input {
  flex: 1;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s ease;
}

.name-input:focus {
  border-color: #002eac;
}

/* --- Annotations Sidebar --- */
.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 360px;
  height: 100vh;
  background: #ffffff;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 1050;
  display: flex;
  flex-direction: column;
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
}

.sidebar-header h2 {
  font-size: 17px;
  font-weight: 600;
  color: #2c3e50;
  margin: 0;
}

#annotations-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.empty-state {
  color: #888;
  text-align: center;
  padding: 40px 16px;
  font-size: 14px;
  font-style: italic;
  line-height: 1.5;
}

.annotation-card {
  background: #ffffff;
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 12px;
  border: 1px solid #edf2f7;
  border-left: 3px solid #002eac;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
  position: relative;
  transition: box-shadow 0.2s ease;
}

.annotation-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.annotation-card .quote {
  font-style: italic;
  color: #666;
  font-size: 13px;
  margin-bottom: 8px;
  padding-right: 22px;
  line-height: 1.4;
}

.annotation-card .comment {
  font-size: 14px;
  color: #2d3748;
  line-height: 1.45;
  word-break: break-word;
}

.annotation-card .meta {
  font-size: 12px;
  color: #a0aec0;
  margin-top: 10px;
}

.annotation-card .delete-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: #cbd5e0;
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.annotation-card .delete-btn:hover {
  color: #e53e3e;
  background: #fff5f5;
}

/* --- Analytics View --- */
#analytics-view {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  padding: 0 0 24px 0;
}

.stat-card {
  background: #ffffff;
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  border: 1px solid #eef2f6;
}

.stat-number {
  font-size: 48px;
  font-weight: 700;
  color: #002eac;
  line-height: 1.1;
  margin-bottom: 6px;
}

.stat-label {
  font-size: 13px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
}

#word-cloud-container {
  background: #ffffff;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  border: 1px solid #eef2f6;
}

#word-cloud-container h2, #recent-feed h2 {
  font-size: 18px;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 16px;
}

#word-cloud {
  min-height: 280px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 14px;
  padding: 20px 10px;
}

.cloud-word {
  display: inline-block;
  padding: 4px 10px;
  cursor: default;
  transition: transform 0.2s ease, opacity 0.2s ease;
  font-weight: 500;
  user-select: none;
  border-radius: 4px;
}

.cloud-word:hover {
  transform: scale(1.15);
  opacity: 1 !important;
}

#recent-feed {
  background: transparent;
}

.recent-comment {
  background: #ffffff;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  border: 1px solid #eef2f6;
}

.recent-comment .comment {
  font-size: 14px;
  color: #333;
  line-height: 1.45;
}

.recent-comment .meta {
  font-size: 12px;
  color: #999;
  margin-top: 8px;
}

/* --- Toast Notification --- */
.toast {
  position: fixed;
  bottom: 28px;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: fit-content;
  max-width: 90%;
  background: #2d3748;
  color: #ffffff;
  padding: 12px 24px;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  font-size: 14px;
  font-weight: 500;
  z-index: 2000;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
  text-align: center;
}

/* --- Responsive Design (Mobile) --- */
@media (max-width: 768px) {
  #toolbar {
    padding: 0 12px;
  }

  .toolbar-center #page-info {
    display: none;
  }

  .sidebar {
    width: 100%;
  }

  .annotation-popup, #annotation-popup {
    width: calc(100% - 32px);
    left: 16px;
    transform: none;
  }

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

  #reader-view {
    padding: 24px 16px 60px;
  }

  #reader-content {
    font-size: 17px;
    line-height: 1.75;
  }

  .tool-btn {
    padding: 5px 8px;
    font-size: 13px;
  }
}
