/*
 * 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.
 */

/* Import Tailwind CSS */
@import "application.tailwind.css";

/* Ensure the library sidebar has proper height constraints */
.library-sidebar {
  background-color: white;
  border-right: 1px solid #d6d3d1; /* stone-300 */
  overflow-x: hidden;
  min-width: 0; /* Prevents flex/grid sizing issues */
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0; /* Critical for flexbox scrolling */
}

/* Mobile-first responsive library grid */
.library-grid {
  display: grid;
  /* Mobile: Full-width sidebar by default */
  grid-template-columns: 1fr 0fr;
  overflow-x: hidden;
  width: 100%;
  height: 100%;
  min-height: 0; /* Critical for flexbox scrolling */
}

/* Medium screens: Fixed width sidebar */
@media (min-width: 768px) and (max-width: 1279px) {
  .library-grid {
    grid-template-columns: 427px 1fr;
  }
  
  /* Collapsed sidebar state */
  .library-grid.sidebar-collapsed {
    grid-template-columns: 0fr 1fr;
  }
}

/* Large screens: Proportional sidebar */
@media (min-width: 1280px) {
  .library-grid {
    grid-template-columns: 33.333% 1fr;
  }
  
  /* Collapsed sidebar state */
  .library-grid.sidebar-collapsed {
    grid-template-columns: 0fr 1fr;
  }
}

/* Mobile: Show content when book is selected */
.library-grid.mobile-content-view {
  grid-template-columns: 0fr 1fr;
}

/* Ensure the library layout has proper height constraints */
.library-layout {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
  height: calc(100vh - 64px) !important; /* Override inline styles */
  height: calc(100dvh - 64px) !important; /* Dynamic viewport height for mobile browser UI */
  min-height: 0; /* Critical for flexbox scrolling */
  position: absolute;
  top: 64px;
  left: 0;
  right: 0;
  width: 100vw;
  max-width: 100vw;
}

.library-content {
  background-color: white;
  overflow-x: hidden;
  min-width: 0; /* Prevents flex/grid sizing issues */
}

/* Mobile-specific content styling */
@media (max-width: 767px) {
  /* Allow natural scrolling for Chrome mobile address bar behavior */
  body.library-mobile {
    overflow-x: hidden; /* Only prevent horizontal scrolling */
    height: 100vh;
    /* Use dynamic viewport units that adapt to mobile browser UI */
    height: 100dvh; /* Dynamic viewport height - adapts to browser UI changes */
  }
  
  .library-content {
    /* Ensure content takes full width on mobile */
    width: 100%;
    min-width: 100%;
  }
  
  /* Mobile back button styling */
  .mobile-back-button {
    background-color: white;
    border: 1px solid #d6d3d1;
    border-radius: 8px;
    padding: 8px 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: opacity 150ms ease-in-out;
    display: flex;
    align-items: center;
    min-height: 44px; /* iOS touch target */
    width: fit-content;
  }
  
  .mobile-back-button:hover {
    background-color: #f9fafb;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  }
  
  .mobile-back-button:active {
    opacity: 0.8;
    background-color: #f3f4f6;
  }
  
}



/* Ensure proper scrolling for the book list */
.sidebar-book-list {
  overflow-y: auto !important;
  overflow-x: hidden;
  height: 0; /* Allow flex-1 to work properly */
  min-height: 0; /* Critical for flexbox scrolling */
  flex: 1 1 auto; /* Ensure it takes remaining space */
  max-height: none; /* Remove any max-height constraints */
}



/* Ensure the sidebar header content has proper height constraints */
.sidebar-header-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0; /* Critical for flexbox scrolling */
  flex: 1 1 auto; /* Ensure it takes remaining space */
}



/* Settings Modal Styles */
.save-btn {
  min-width: 6rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.password-btn {
  min-width: 8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.action-btn {
  min-width: 10rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.delete-field {
  width: 24rem !important;
}

.toggle-switch {
  width: 2.75rem;
  height: 1.5rem;
  position: relative;
  display: inline-block;
  flex-shrink: 0;
}

.toggle-handle {
  width: 1.25rem;
  height: 1.25rem;
  position: absolute;
  top: 0.125rem;
  left: 0.125rem;
  transition: transform 0.2s ease-in-out;
}

.toggle-switch.bg-stone-200 .toggle-handle {
  transform: translateX(0);
}

.toggle-switch.bg-indigo-600 .toggle-handle {
  transform: translateX(1.25rem);
}

/* Tooltip styles for collapsed state */
.collapsed-tooltip {
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 8px;
  background-color: #1f2937; /* gray-800 */
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease-in-out;
  z-index: 50;
  max-width: 200px;
  /* Prevent tooltip from causing horizontal overflow */
  right: auto;
  overflow: hidden;
}

/* Only show tooltips on larger screens to avoid overflow issues */
@media (min-width: 768px) {
  .collapsed-item:hover .collapsed-tooltip {
    opacity: 1;
  }
}

/* Collapsed book cover/initial styling */
.collapsed-book-item {
  position: relative;
  width: 40px;
  height: 40px;
  margin: 4px auto;
  border-radius: 4px;
  cursor: pointer;
  transition: all 150ms ease-in-out;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 40px;
  overflow: hidden;
  box-sizing: border-box;
}

.collapsed-book-item:hover {
  background-color: #e7e5e4; /* stone-200 */
}

.collapsed-book-item.selected {
  background-color: #eef2ff; /* indigo-50 */
  border: 2px solid #4f46e5; /* indigo-600 */
}

.collapsed-book-cover {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 2px;
  max-width: 32px;
  max-height: 32px;
}

.collapsed-book-initial {
  width: 32px;
  height: 32px;
  background-color: #a8a29e; /* stone-400 */
  color: white;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  max-width: 32px;
  max-height: 32px;
  overflow: hidden;
}

/* Mobile adjustments for collapsed items */
@media (max-width: 640px) {
  .collapsed-book-item {
    width: 36px;
    height: 36px;
  }
  
  .collapsed-book-cover,
  .collapsed-book-initial {
    width: 28px;
    height: 28px;
  }
  
  .collapsed-tooltip {
    font-size: 11px;
    padding: 3px 6px;
  }
}

/* Mobile-optimized book list items */
@media (max-width: 767px) {
  /* Larger touch targets for mobile */
  .library-sidebar [data-highlight-id] {
    min-height: 80px;
    padding: 16px;
  }
  
  /* Better spacing for mobile book covers */
  .library-sidebar .flex-shrink-0 img {
    width: 48px;
    height: 64px;
  }
  
  /* Improved text sizing for mobile */
  .library-sidebar h3 {
    font-size: 16px;
    line-height: 1.4;
  }
  
  .library-sidebar p {
    font-size: 14px;
    line-height: 1.3;
  }
  
  /* Better mobile button sizing */
  .library-sidebar button {
    min-height: 44px; /* iOS recommended touch target */
    min-width: 44px;
  }
  
  /* Mobile-optimized header */
  .library-sidebar .px-4 {
    padding-left: 16px;
    padding-right: 16px;
  }
  
  .library-sidebar .py-3 {
    padding-top: 16px;
    padding-bottom: 16px;
  }
  
  /* Mobile title sizing */
  .library-sidebar h1 {
    font-size: 24px;
  }
  
  /* Mobile count text */
  .library-sidebar .text-sm {
    font-size: 13px;
  }
}

/* Custom modal spacing to override Tailwind's reset */
.modal-content-spacing {
  padding-top: 0.75rem !important;
  padding-bottom: 0.75rem !important;
}

.modal-content-spacing-top {
  padding-top: 0.75rem !important;
}

.modal-content-spacing-bottom {
  padding-bottom: 0.75rem !important;
}

/* Custom styles for Markdown rendering */
.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
  font-weight: 600;
  line-height: 1.25;
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

.prose h1 {
  font-size: 1.875rem;
}

.prose h2 {
  font-size: 1.5rem;
}

.prose h3 {
  font-size: 1.25rem;
}

.prose p {
  margin-bottom: 1em;
  line-height: 1.6;
}

.prose ul, .prose ol {
  margin-bottom: 1em;
  padding-left: 1.5em;
}

.prose li {
  margin-bottom: 0.25em;
}

.prose ul li {
  list-style-type: disc;
}

.prose ol li {
  list-style-type: decimal;
}

.prose strong {
  font-weight: 600;
}

.prose em {
  font-style: italic;
}

.prose code {
  background-color: #f3f4f6;
  padding: 0.125rem 0.25rem;
  border-radius: 0.25rem;
  font-size: 0.875em;
}

.prose pre {
  background-color: #f3f4f6;
  padding: 1rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  margin-bottom: 1em;
}

.prose blockquote {
  border-left: 4px solid #e5e7eb;
  padding-left: 1rem;
  margin-left: 0;
  margin-bottom: 1em;
  font-style: italic;
  color: #6b7280;
}

/* Ensure consistent hover behavior */
button, 
[role="button"],
a[href]:not([tabindex="-1"]),
input[type="submit"],
input[type="button"],
input[type="reset"],
.cursor-pointer {
  cursor: pointer;
}

/* Disable pointer cursor for disabled elements */
button:disabled,
[role="button"]:disabled,
input[type="submit"]:disabled,
input[type="button"]:disabled,
input[type="reset"]:disabled,
.cursor-not-allowed {
  cursor: not-allowed;
}

/* Mobile-optimized content viewer */
@media (max-width: 767px) {
  /* Mobile content padding */
  .library-content .p-6 {
    padding: 16px;
  }
  
  /* Mobile book cover sizing */
  .library-content [style*="width: 125px"] {
    width: 100px !important;
    height: 144px !important;
  }
  
  /* Mobile title sizing */
  .library-content .text-2xl {
    font-size: 20px;
    line-height: 1.3;
  }
  
  .library-content .text-lg {
    font-size: 16px;
    line-height: 1.3;
  }
  
  /* Mobile metadata spacing */
  .library-content .space-y-1 > * + * {
    margin-top: 8px;
  }
  
  /* Mobile highlight items */
  .library-content .py-3 {
    padding-top: 12px;
    padding-bottom: 12px;
  }
  
  /* Mobile action buttons */
  .library-content .w-10 {
    width: 44px;
    height: 44px;
  }
  
  /* Mobile highlight text */
  .library-content .text-stone-700 {
    font-size: 15px;
    line-height: 1.5;
  }
  
  /* Mobile note styling */
  .library-content .text-xs {
    font-size: 12px;
  }
  
  /* Mobile tag styling */
  .library-content .px-2 {
    padding-left: 8px;
    padding-right: 8px;
  }
  
  .library-content .py-1 {
    padding-top: 6px;
    padding-bottom: 6px;
  }
}

/* Mobile touch-friendly interactions */
@media (max-width: 767px) {
  /* Replace hover with active states for mobile */
  .library-sidebar [data-highlight-id]:active {
    background-color: #eef2ff !important;
    border-left-color: #4f46e5 !important;
  }
  
  /* Mobile-friendly button interactions */
  button:active,
  [role="button"]:active {
    opacity: 0.8;
    transition: opacity 100ms ease-in-out;
  }
  
  /* Mobile highlight interactions */
  .library-content [data-highlight-index]:active {
    background-color: #f3f4f6 !important;
  }
  
  /* Mobile action button interactions */
  .library-content button:active {
    background-color: #e5e7eb !important;
  }
  
  
  /* Mobile back button simple appearance */
  .mobile-back-button {
    transition: opacity 150ms ease-in-out;
  }
  
  /* Mobile book list item improvements */
  .library-sidebar [data-highlight-id] {
    transition: background-color 150ms ease-in-out;
  }
  
  /* Mobile book cover improvements */
  .library-sidebar .flex-shrink-0 {
    border-radius: 4px;
    overflow: hidden;
  }
  
  /* Mobile text improvements */
  .library-sidebar h3 {
    font-weight: 600;
  }
  
  .library-sidebar p {
    font-weight: 400;
  }
}
