/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 */

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin: 0;
  background-color: #f5f5f5;
  color: #333;
}

.flash-message {
  margin: 16px;
  padding: 16px;
  border-radius: 6px;
  border: 1px solid transparent;
}

.flash-message.-notice {
  background-color: #ecfdf5;
  color: #047857;
  border-color: #a7f3d0;
}

.flash-message.-alert {
  background-color: #fef2f2;
  color: #b91c1c;
  border-color: #fecaca;
}

:root {
  --chat-bottom-offset: 0px;
  --chat-bottom-offset-negative: 0px;
  --chat-input-max-height: 80px;
}

.reader-shell {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.translation-modal__footer {
  padding-bottom: calc(16px + env(safe-area-inset-bottom) + var(--chat-bottom-offset, 0px));
  flex: 0 0 auto;
  position: sticky;
  bottom: 0;
  z-index: 2;
}

.reader-new-body {
  background-color: #111827;
  margin: 0;
  overflow-x: hidden;
}

.reader-new {
  --reader-font-base: 1.8rem;
  --reader-font-heading: 2.6rem;
  --reader-font-subheading: 1.9rem;
  --reader-font-label: 1.5rem;
  --reader-line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #1f2937 0%, #111827 100%);
  color: #f3f4f6;
  font-size: var(--reader-font-base);
  line-height: var(--reader-line-height);
  width: 100%;
  overflow-x: hidden;
}

@media (min-width: 768px) {
  .reader-new {
    --reader-font-base: 2rem;
    --reader-font-heading: 3rem;
    --reader-font-subheading: 2.1rem;
    --reader-font-label: 1.7rem;
  }
}

@media (min-width: 1024px) {
  .reader-new {
    --reader-font-base: 2.2rem;
    --reader-font-heading: 3.4rem;
    --reader-font-subheading: 2.3rem;
    --reader-font-label: 1.9rem;
  }
}

.reader-new__header {
  background: rgba(255, 255, 255, 0.05);
  padding: 16px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  position: sticky;
  top: 0;
  z-index: 2;
  backdrop-filter: blur(8px);
}

.reader-new__header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.reader-new__header-title {
  font-size: var(--reader-font-heading);
  font-weight: 600;
}

.reader-new__header-subtitle {
  font-size: var(--reader-font-subheading);
  color: #d1d5db;
}

.reader-new__header-pill {
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: var(--reader-font-label);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.reader-new__main {
  flex: 1;
  overflow-y: auto;
  padding-bottom: calc(180px + env(safe-area-inset-bottom));
}

.reader-new__main-inner {
  padding: 24px;
}

.reader-new__footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.95);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 16px 24px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom) + var(--chat-bottom-offset, 0px));
  z-index: 3;
  box-shadow: 0 -6px 30px rgba(0, 0, 0, 0.4);
  transform: translateY(var(--chat-bottom-offset-negative, 0px));
  will-change: transform;
  transition: transform 0.15s ease-out;
}

.reader-new__footer-inner {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.reader-new__footer-label {
  font-size: var(--reader-font-label);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #9ca3af;
}

.reader-new__footer-input {
  width: 100%;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background-color: rgba(15, 23, 42, 0.8);
  color: #f3f4f6;
  padding: 14px 16px;
  resize: vertical;
  min-height: 96px;
  font-size: var(--reader-font-base);
  line-height: 1.5;
}

.reader-new__footer-button {
  align-self: flex-end;
  background-color: #3b82f6;
  color: #fff;
  border: none;
  padding: 16px 32px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 1.2rem;
  min-height: 58px;
}

.reader-new__placeholder {
  background-color: rgba(15, 23, 42, 0.6);
  border-radius: 16px;
  padding: 20px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.reader-new__placeholder-heading {
  font-size: var(--reader-font-heading);
  font-weight: 600;
  margin-bottom: 12px;
}

.reader-new__placeholder-text {
  color: #d1d5db;
  margin-bottom: 16px;
  font-size: var(--reader-font-subheading);
}

.reader-new__placeholder-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.reader-new__placeholder-item {
  background-color: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 12px 14px;
}

.reader-new__placeholder-label {
  font-size: var(--reader-font-label);
  color: #9ca3af;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.reader-new__placeholder-body {
  color: #f3f4f6;
  font-size: var(--reader-font-base);
  line-height: 1.7;
}

.translation-page {
  background-color: #fff;
  padding: 0;
  margin: 0;
  display: flex;
  flex: 1;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.translation-page > #translation-modal {
  flex: 1;
  display: flex;
  min-height: 0;
}

body:has(.translation-page) {
  background-color: #fff;
  height: 100%;
}

#translation-modal.translation-modal {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

body.reader-mode .translation-page {
  height: 100%;
}

/* Utility */
.hidden { display: none !important; }

/* Header bar */
.header-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand { font-weight: 600; font-size: 1.1rem; color: #1f2937; text-decoration: none; }
.brand:hover { text-decoration: underline; }

.nav { display: flex; align-items: center; gap: 16px; }
.nav-link { color: #4b5563; text-decoration: none; }
.nav-link:hover { color: #111827; text-decoration: underline; }

/* Desktop vs mobile visibility */
.nav-desktop { display: none; }
.nav-mobile { display: block; }
@media (min-width: 768px) {
  .nav-desktop { display: flex; }
  .nav-mobile { display: none; }
}

/* Account button & dropdown */
.account-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #d1d5db;
  padding: 4px 8px;
  border-radius: 20px;
  background: #fff;
  cursor: pointer;
}
.account-btn:hover { background: #f9fafb; }
.account-label { display: none; color: #111827; font-size: 0.9rem; }
@media (min-width: 1024px) { .account-label { display: inline; } }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: #667eea; color: #fff; font-weight: 600; font-size: 0.8rem;
  display: inline-flex; align-items: center; justify-content: center;
}
.avatar-lg { width: 36px; height: 36px; font-size: 0.9rem; }
.caret { color: #6b7280; font-size: 0.8rem; }

.menu { position: relative; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px);
  width: 200px; padding: 6px 0; background: #fff;
  border: 1px solid #e5e7eb; border-radius: 8px; box-shadow: 0 8px 20px rgba(0,0,0,0.08);
}
.menu-item { display: block; padding: 8px 12px; color: #111827; text-decoration: none; font-size: 0.9rem; }
.menu-item:hover { background: #f9fafb; }
.menu-item.danger { color: #b91c1c; }
.menu-item.danger:hover { background: #fef2f2; }

/* Mobile menu */
.hamburger-btn {
  width: 40px; height: 40px; border: 1px solid #d1d5db; border-radius: 6px;
  background: #fff; cursor: pointer;
}
.hamburger-btn:hover { background: #f9fafb; }
.hamburger-icon { display: inline-block; width: 18px; height: 2px; background: #374151; position: relative; }
.hamburger-icon::before, .hamburger-icon::after { content: ""; position: absolute; left: 0; width: 18px; height: 2px; background: #374151; }
.hamburger-icon::before { top: -6px; }
.hamburger-icon::after { top: 6px; }

.mobile-panel {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  border-top: 1px solid #e5e7eb;
  background: #fff;
}
.mobile-panel-inner { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.mobile-account { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.mobile-account-label { font-size: 0.95rem; color: #111827; }
.mobile-link { display: block; padding: 8px 10px; border-radius: 6px; color: #111827; text-decoration: none; }
.mobile-link:hover { background: #f9fafb; }
.mobile-link.primary { background: #667eea; color: #fff; text-align: center; }
.mobile-link.primary:hover { background: #5a67d8; }
.mobile-link.danger { color: #b91c1c; }
.mobile-link.danger:hover { background: #fef2f2; }

/* Full-screen reader mode */
body.reader-mode {
  padding: 0;
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
}

.bookshelf {
  max-width: 1200px;
  margin: 0 auto;
}

.bookshelf-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 2px solid #ddd;
}

.bookshelf-header h1 {
  margin: 0;
  color: #2c3e50;
  font-size: 2rem;
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.book-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}

.book-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.book-cover {
  height: 200px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.book-placeholder {
  font-size: 3rem;
  color: white;
}

.book-info {
  padding: 15px;
}

.book-title {
  margin: 0 0 10px 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: #2c3e50;
  line-height: 1.3;
}

.book-file {
  margin: 0 0 15px 0;
  font-size: 0.85rem;
  color: #666;
  word-break: break-word;
}

.empty-bookshelf {
  text-align: center;
  padding: 60px 20px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.empty-bookshelf h2 {
  color: #666;
  margin-bottom: 10px;
}

.empty-bookshelf p {
  color: #999;
  margin-bottom: 30px;
}

.upload-book {
  max-width: 600px;
  margin: 0 auto;
  background: white;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.upload-book h1 {
  margin-top: 0;
  color: #2c3e50;
  text-align: center;
  margin-bottom: 30px;
}

.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  margin-bottom: 5px;
  font-weight: 600;
  color: #555;
}

.form-control {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
  box-sizing: border-box;
}

.form-control:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.form-text {
  display: block;
  margin-top: 5px;
  font-size: 0.85rem;
  color: #666;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 30px;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.2s;
  display: inline-block;
  text-align: center;
}

.btn-primary {
  background-color: #667eea;
  color: white;
}

.btn-primary:hover {
  background-color: #5a67d8;
}

.btn-secondary {
  background-color: #6c757d;
  color: white;
}

.btn-secondary:hover {
  background-color: #5a6268;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.875rem;
}

.error-messages {
  background-color: #f8d7da;
  color: #721c24;
  padding: 15px;
  border-radius: 4px;
  margin-bottom: 20px;
  border: 1px solid #f5c6cb;
}

.error-messages h4 {
  margin-top: 0;
  margin-bottom: 10px;
}

.error-messages ul {
  margin-bottom: 0;
  padding-left: 20px;
}

/* EPUB Reader Styles */
.reader-container {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.reader-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: #f8f9fa;
  border-bottom: 1px solid #dee2e6;
  flex-shrink: 0;
}

.reader-nav .back-btn {
  color: #667eea;
  text-decoration: none;
  font-weight: 500;
}

.reader-nav .back-btn:hover {
  color: #5a67d8;
}

.book-title h1 {
  margin: 0;
  font-size: 1.2rem;
  color: #2c3e50;
  text-align: center;
}

.reader-controls {
  display: flex;
  gap: 10px;
}

.control-btn {
  background: #667eea;
  color: white;
  border: none;
  border-radius: 4px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
}

.control-btn:hover {
  background: #5a67d8;
}

.reader-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.reader-sidebar {
  width: 300px;
  background: #f8f9fa;
  border-right: 1px solid #dee2e6;
  padding: 20px;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  position: absolute;
  height: calc(100vh - 120px);
  z-index: 10;
}

.reader-sidebar.visible {
  transform: translateX(0);
}

.reader-sidebar h3 {
  margin-top: 0;
  color: #2c3e50;
  font-size: 1.1rem;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-list li {
  margin-bottom: 8px;
}

.toc-list a {
  color: #667eea;
  text-decoration: none;
  display: block;
  padding: 8px 12px;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.toc-list a:hover {
  background: #e9ecef;
  color: #5a67d8;
}

.reader-content {
  flex: 1;
  position: relative;
  overflow: hidden;
  padding-bottom: 80px;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  box-sizing: border-box;
}

#epub-viewer {
  width: 100%;
  height: 100%;
  background: white;
}

/* Short highlights often render as HTML overlays (.epubjs-hl). */
.epubjs-hl.bookr-highlight--translation::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  border-bottom: 2px dotted #7a7a7a;
  pointer-events: none;
}

/* Multi-line highlights can render as SVG <g> nodes; we inject <line> elements. */
.bookr-translation-underline {
  stroke: #7a7a7a;
  stroke-width: 2;
  stroke-dasharray: 4 2;
  pointer-events: none;
}

.loading-message, .error-message {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: #666;
}

.error-message {
  color: #dc3545;
  flex-direction: column;
  padding: 20px;
}

.reader-footer {
  padding: 15px 20px 15px;
  padding-bottom: calc(15px + env(safe-area-inset-bottom));
  background: #f8f9fa;
  border-top: 1px solid #dee2e6;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 5;
}

.reading-progress {
  display: flex;
  align-items: center;
  gap: 15px;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: #e9ecef;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

.progress-bar::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  background: #667eea;
  border-radius: 50%;
  cursor: pointer;
}

.progress-bar::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: #667eea;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

.progress-text {
  font-size: 0.9rem;
  color: #666;
  min-width: 35px;
  text-align: right;
}

/* Action Menu Styles */
.action-menu-popup {
  position: fixed;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  padding: 8px;
  z-index: 1000;
  border: 1px solid #e9ecef;
  min-width: 120px;
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.1s ease, transform 0.1s ease;
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
}

.action-menu-popup.visible {
  opacity: 1;
  transform: scale(1);
}

.action-menu-popup.hidden {
  opacity: 0;
  transform: scale(0.9);
  pointer-events: none;
}

.action-menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: transparent;
  pointer-events: auto;
  display: none;
}

.action-menu-backdrop.visible {
  display: block;
}

.action-menu-backdrop.hidden {
  display: none;
}

.action-btn {
  background: #667eea;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 8px 16px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1.25;
  letter-spacing: normal;
  transition: background-color 0.2s;
  white-space: nowrap;
}

.action-btn:hover {
  background: #5a67d8;
}

.action-btn:active {
  background: #4c51bf;
  transform: translateY(1px);
}

.highlight-btn {
  background: #28a745;
}

.highlight-btn:hover {
  background: #218838;
}

.highlight-btn:active {
  background: #1e7e34;
}
.translate-btn {
  background: #17a2b8;
}
.translate-btn:hover {
  background: #138496;
}
.translate-btn:active {
  background: #0f6674;
}

/* Translation Modal Styles */
.translation-modal.fixed {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2000;
  transition: opacity 0.3s ease;
}

.translation-modal:not(.fixed) {
  position: relative;
  width: 100%;
  height: 100%;
  margin: 0;
  transition: opacity 0.3s ease;
}

.translation-modal.visible {
  opacity: 1;
  pointer-events: all;
}

.translation-modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.translation-modal.fixed .translation-modal-overlay {
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
}

.translation-modal-content {
  background: #fff;
  border-radius: 0;
  box-shadow: none;
  width: 100%;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
}

.translation-modal__summary,
.translation-modal__conversation,
.translation-modal__footer {
  transition: opacity 0.2s ease;
}

.translation-modal__summary {
  flex: 0 0 auto;
  max-height: 40vh;
  overflow-y: auto;
}

.translation-modal__conversation {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.translation-chat {
  background-color: #f8fafc;
}

.translation-chat__header {
  flex: 0 0 auto;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 40vh;
  overflow-y: auto;
}

.translation-chat__closebar {
  display: flex;
  justify-content: flex-end;
}

.translation-chat__label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #64748b;
  font-weight: 600;
  margin: 0 0 4px 0;
}

.translation-chat__translated-text {
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1.4;
  color: #111827;
  margin: 0;
}

.translation-chat__details {
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #f8fafc;
  padding: 8px 12px;
}

.translation-chat__details[open] {
  background: #fff;
}

.translation-chat__details-summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: #475569;
  list-style: none;
}

.translation-chat__details-summary::-webkit-details-marker {
  display: none;
}

.translation-chat__details-summary::marker {
  content: "";
}

.translation-chat__details-panel {
  margin-top: 12px;
}

.translation-chat__details-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.translation-chat__details-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #2563eb;
}

.translation-chat__details-text {
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.5;
  color: #111827;
  margin-top: 8px;
}

.translation-chat__details-actions {
  display: flex;
  justify-content: flex-end;
}

.translation-chat__messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 16px calc(12px + env(safe-area-inset-bottom) + var(--chat-input-height, 0px));
  background: #f8fafc;
}

.translation-chat__input {
  flex: 0 0 auto;
  background: #fff;
  border-top: 1px solid #e5e7eb;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom) + var(--chat-bottom-offset, 0px));
  position: sticky;
  bottom: 0;
  z-index: 2;
}

@media (max-width: 768px) {
  #translation-modal .translation-modal__summary {
    max-height: 30vh;
    overflow-y: auto;
  }

  .keyboard-open #translation-modal .translation-modal__summary {
    max-height: 20vh;
  }

  .translation-chat__translated-text {
    font-size: 1.05rem;
  }
}

.keyboard-open .translation-chat__header {
  max-height: 25vh;
  padding-bottom: 8px;
}

.keyboard-open .translation-chat__translated-text {
  font-size: 1rem;
}

.keyboard-open .translation-chat__details {
  display: none;
}

.translation-modal-content--inline {
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
}

.translation-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid #e2e8f0;
  background-color: #f8f9fa;
  flex-shrink: 0;
}

.translation-header h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #1a202c;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: #718096;
  text-decoration: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  line-height: 1;
}

.modal-close:hover {
  background-color: #f7fafc;
  color: #2d3748;
}

.translation-body {
  padding: 16px 20px 8px 20px;
  flex-shrink: 0;
  border-bottom: 1px solid #e2e8f0;
}

.original-section,
.translation-section {
  margin-bottom: 12px;
}

.translation-section:last-child {
  margin-bottom: 0;
}

.original-section label,
.translation-section label {
  display: block;
  font-weight: 600;
  color: #6b7280;
  margin-bottom: 4px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.original-text,
.translated-text {
  background-color: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 8px 10px;
  margin: 0;
  line-height: 1.4;
  color: #374151;
  font-size: 0.875rem;
  min-height: 60px;
}

.language-selectors {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 8px 0;
  padding: 8px;
  background-color: #f8f9fa;
  border-radius: 6px;
}

.language-select {
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background-color: white;
  color: #374151;
  font-size: 0.875rem;
  min-width: 140px;
}

.language-select:focus {
  outline: none;
  border-color: #17a2b8;
  box-shadow: 0 0 0 2px rgba(23, 162, 184, 0.2);
}

.language-arrow {
  font-size: 1.2rem;
  color: #6b7280;
  font-weight: bold;
}

.loading-state {
  text-align: center;
  color: #6b7280;
  font-style: italic;
  padding: 20px;
}

.error-state {
  color: #dc2626;
  background-color: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  padding: 12px;
  margin: 8px 0;
}

/* Conversation container fills remaining space under translation body */
.conversation-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0; /* allow inner scroll area to size correctly */
  overflow: hidden;
}

.conversation-section {
  /* Section that contains the input form, pinned to bottom of modal */
  flex: 0 0 auto;
  display: block;
  padding: 0;
  position: sticky;
  bottom: 0;
  background-color: #f8f9fa;
  z-index: 5;
  padding-bottom: var(--chat-bottom-offset, 0px);
}

.message-input {
  width: 100%;
  min-height: 60px;
  max-height: 120px;
  padding: 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  resize: none;
  font-family: inherit;
  font-size: 0.875rem;
  overflow-wrap: break-word;
  box-sizing: border-box;
  line-height: 1.4;
}

.message-input:focus {
  outline: none;
  border-color: #17a2b8;
  box-shadow: 0 0 0 2px rgba(23, 162, 184, 0.2);
}

.message-input:disabled {
  background-color: #f9fafb;
  color: #9ca3af;
  cursor: not-allowed;
}

.send-btn {
  background-color: #3b82f6;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
  font-size: 0.875rem;
  align-self: flex-end;
  min-width: 70px;
  height: 32px;
}

.send-btn:hover:not(:disabled) {
  background-color: #2563eb;
}

.send-btn:disabled {
  background-color: #9ca3af;
  cursor: not-allowed;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .reader-header {
    padding: 10px 15px;
  }

  .book-title h1 {
    font-size: 1rem;
  }

  .reader-sidebar {
    width: 280px;
  }

  .control-btn {
    width: 35px;
    height: 35px;
    font-size: 1rem;
  }

  .action-menu-popup {
    min-width: 140px;
    padding: 10px;
  }

  .action-btn {
    padding: 10px 18px;
    font-size: 1rem;
  }
}

@media (max-width: 600px) {
  .translation-body {
    padding: 16px 12px 8px 12px;
  }

  .language-selectors {
    flex-direction: column;
    align-items: stretch;
    padding: 8px 0;
    gap: 6px;
  }

  .language-selectors .language-arrow {
    display: none;
  }

  .language-select {
    width: 100%;
    min-width: 0;
  }

  .conversation-content {
    padding: 0 12px 12px;
  }
}

/* Large-display layout (desktop) */
@media (min-width: 1024px) {
  /* Two-column layout for original/translation blocks */
  .translation-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "selectors selectors"
      "original  translation";
    grid-column-gap: 16px;
    grid-row-gap: 12px;
    align-items: start;
  }

  .translation-body .language-selectors { grid-area: selectors; justify-content: center; }
  .translation-body .original-section     { grid-area: original; }
  .translation-body .translation-section  { grid-area: translation; }

  /* Improve visual balance on large screens */
  .original-text,
  .translated-text {
    min-height: 110px;
  }

  /* Visually separate conversation area from the top grid */
  .conversation-content {
    border-top: 1px solid #e5e7eb;
  }
}

/* Translation Conversation Styles (Slice 2) */
.translation-display {
  padding: 20px;
}

.translation-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e5e7eb;
}

.language-pair {
  font-weight: 600;
  color: #374151;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b7280;
  text-decoration: none;
}

.modal-close:hover {
  color: #374151;
  background-color: #f3f4f6;
  border-radius: 4px;
}

.translation-content {
  margin-bottom: 20px;
}

.original-text, .translated-text {
  margin-bottom: 15px;
}

.original-text label, .translated-text label {
  display: block;
  font-weight: 600;
  margin-bottom: 5px;
  color: #374151;
  font-size: 0.875rem;
}

.original-text p, .translated-text p {
  margin: 0;
  padding: 10px;
  background-color: #f9fafb;
  border-left: 3px solid #3b82f6;
  border-radius: 4px;
  color: #1f2937;
}

.conversation-history {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  background-color: white;
  margin: 0;
  min-height: 0;
}

.message {
  margin-bottom: 15px;
  padding: 12px;
  border-radius: 8px;
  max-width: 85%;
}

.message-user {
  background-color: #3b82f6;
  color: white;
  margin-left: auto;
  text-align: right;
}

.message-assistant {
  background-color: #ffffff;
  color: #1f2937;
  border: 1px solid #d1d5db;
  margin-right: auto;
}

.message-role {
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 5px;
  opacity: 0.8;
}

.message-content {
  line-height: 1.5;
}

.message-content p {
  margin: 0 0 8px 0;
}

.message-content p:last-child {
  margin-bottom: 0;
}

/* Input form sits at the bottom INSIDE the modal */
.conversation-form {
  position: static;
  width: 100%;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom) + var(--chat-bottom-offset, 0px));
  background-color: #f8f9fa;
  border-top: 1px solid #e5e7eb;
  border-radius: 0 0 12px 12px; /* match modal corners at bottom */
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: none;
}

.conversation-input {
  border-top: 1px solid #e5e7eb;
  padding-top: 20px;
}

.translation-question-input {
  width: 100%;
  min-height: 80px;
  padding: 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.875rem;
  resize: vertical;
  margin-bottom: 10px;
}

.translation-question-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.translation-question-input:disabled {
  background-color: #f3f4f6;
  cursor: not-allowed;
}

.conversation-actions {
  display: flex;
  justify-content: flex-end;
}

.btn.btn-primary {
  background-color: #3b82f6;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.875rem;
}

.btn.btn-primary:hover:not(:disabled) {
  background-color: #2563eb;
}

.btn.btn-primary:disabled {
  background-color: #9ca3af;
  cursor: not-allowed;
}

/* Typing Indicator Styles */
.typing-indicator {
  opacity: 1;
  transition: opacity 0.3s ease;
}

.typing-indicator.fade-out {
  opacity: 0;
}

.typing-animation {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #6b7280;
  font-style: italic;
}

.typing-text {
  font-size: 0.875rem;
}

.typing-dots {
  display: flex;
  gap: 2px;
  align-items: center;
}

.typing-dots .dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background-color: #6b7280;
  animation: typing-bounce 1.4s infinite;
}

.typing-dots .dot:nth-child(1) {
  animation-delay: 0s;
}

.typing-dots .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots .dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* Typing indicator specific styling for assistant messages */
.message.message-assistant.typing-indicator {
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  opacity: 0.9;
  animation: fade-in 0.3s ease;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 0.9;
    transform: translateY(0);
  }
}

/* Prevent horizontal scrolling in modal */
.translation-modal-content * {
  box-sizing: border-box;
}

.translation-modal-content {
  overflow-x: hidden;
}

/* Ensure text content doesn't cause horizontal overflow */
.original-text,
.translation-section p,
.message-content {
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}
