/* Additional CSS fixes for the manga tracking system */

/* Card enhancements for homepage */
.card {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.card-body {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.card-body .btn {
  margin-top: auto;
}

/* Fix consistency between card-img and manga-cover */
.card .manga-cover {
  height: 160px;
  margin-bottom: 0;
  border-radius: 0;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
}

/* Consistent card heights and styling */
.manga-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1.5rem;
  margin-top: 2rem;
}

/* Desktop layout fixes */
@media (min-width: 769px) {  /* Ensure desktop header maintains proper layout */
  header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.3rem 1rem; /* Reduced vertical padding to match style.css */
  }
    /* Ensure proper logo size */
  header .logo img {
    height: 40px; /* Slightly smaller logo to match style.css */
  }
  
  /* Push navigation menu to the right */
  header .main-nav {
    margin-left: auto;
  }
  
  /* Add extra space between logo and menu */
  header .logo {
    margin-right: 3rem;
  }
  
  /* Fix desktop navigation */
  header nav {
    display: flex;
    gap: 1.2rem;
    max-height: none;
    overflow: visible;
  }
  
  /* Ensure containers maintain desktop styling */
  .container {
    max-width: 1140px;
    margin: 2rem auto;
    padding: 1.5rem;
  }
}

.manga-item {
  background: white;
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 3px 10px rgba(0,0,0,0.06);
  transition: transform 0.2s;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 350px;
  position: relative;
  overflow: hidden !important;
}

.manga-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

/* Ensure consistent button styling */
.action-buttons {
  margin-top: auto;
  width: 100%;
  padding-top: 1rem;
  margin-bottom: 0;
  position: relative;
  overflow: hidden;
}

.manga-btn-container {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  flex-wrap: nowrap;
  margin-bottom: 0;
  overflow: hidden;
}

.manga-btn-form {
  margin: 0;
  flex: 1;
  display: flex;
  align-items: stretch;
  min-width: 0; /* Allows flex items to shrink below content size */
  overflow: hidden;
}

.manga-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
  border: none;
  border-radius: 5px;
  color: white;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;  white-space: nowrap;
  width: 100%;
  height: 32px;
  box-sizing: border-box;
  margin: 0;
  overflow: hidden !important;
  max-width: 100%;
  text-overflow: ellipsis;
  display: inline-flex; /* Ensure better flex behavior */
}

.manga-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 3px 5px rgba(0,0,0,0.2);
  opacity: 0.9;
}

.manga-btn:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.manga-btn i {
  margin-right: 4px;
  flex-shrink: 0; /* Prevent icon from shrinking */
  font-size: 0.9rem;
}

.manga-btn span {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  white-space: nowrap;
  font-size: 0.8rem;
}

.manga-btn-danger {
  background: var(--danger);
}

.manga-btn-primary {
  background: var(--primary);
}

.manga-btn-edit {
  background: var(--gray);
  min-width: 0;
  width: 100%;
  flex-shrink: 1;
  position: relative;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  display: inline-flex !important; 
  align-items: center !important;
  justify-content: center !important;
  padding-left: 0.6rem !important;
  padding-right: 0.6rem !important;
}

/* Fix for button container to ensure nothing breaks out */
.manga-btn-container, .manga-btn-form, .manga-btn {
  box-sizing: border-box !important;
  max-width: 100% !important;
}

/* Ensure the button text doesn't overflow */
.manga-btn span {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Ensure action buttons container properly contains all children */
.action-buttons {
  position: relative;
  overflow: hidden;
}

/* Fix for edit button with long onclick attributes */
.manga-btn-edit {
  max-width: 100%;
  position: relative;
}

/* Better text overflow handling */
.manga-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.manga-description {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #eee;
  font-size: 0.9rem;
  color: var(--gray);
  max-height: 80px;
  overflow: hidden;
  text-overflow: ellipsis;  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
}

.manga-notes {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #eee;
  font-size: 0.9rem;
  color: var(--gray);
  max-height: 60px;
  overflow: hidden;
  text-overflow: ellipsis;  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Cover image container with fixed aspect ratio */
.manga-cover {
  width: 100%;
  height: 180px;
  margin-bottom: 1rem;
  overflow: hidden;
  border-radius: 6px;
}

.manga-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.placeholder-cover {
  width: 100%;
  height: 100%;
  background-color: #eee;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Improved chapter grid styling */
.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  margin-top: 20px;
}

@media (min-width: 768px) {
  .chapter-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }
}

.chapter-box {
  border: 1px solid #ddd;
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.2s ease;
  position: relative;
  height: 65px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  margin: 1px;
}

.chapter-box button {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  padding: 10px 5px 15px;
  transition: background-color 0.2s;
  font-weight: 500;
}

.chapter-unread {
  background-color: #f5f5f5;
  color: #555;
  border: 1px solid #ddd;
}

.chapter-read {
  background-color: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.chapter-box:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
  z-index: 2;
}

.read-date {
  font-size: 0.7rem;
  position: absolute;
  bottom: 3px;
  left: 0;
  right: 0;
  text-align: center;
  padding-top: 2px;
  background: rgba(255, 255, 255, 0.6);
}

/* Form improvements */
.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.form-row > div {
  flex: 1;
  min-width: 200px;
}

.form-actions {
  margin-top: 1.5rem;
  text-align: right;
}

/* Search results styling */
.search-results {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.search-result {
  display: flex;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 3px 10px rgba(0,0,0,0.06);
  background-color: white;
  transition: transform 0.2s, box-shadow 0.2s;
}

.search-result:hover {
  transform: translateY(-3px);
  box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.search-result-image {
  width: 120px;
  height: 180px;
  object-fit: cover;
}

.search-result-content {
  padding: 1rem;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.search-result-content h3 {
  margin-top: 0;
  margin-bottom: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-content p {
  margin-bottom: 0.5rem;
}

.search-result-actions {
  margin-top: auto;
  display: flex;
  justify-content: flex-end;
}

/* Manga detail page specific styles */
.manga-header {
  background-color: white;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.06);
  margin-bottom: 30px;
}

.set-max-form {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: #f9f9f9;
  padding: 10px 15px;
  border-radius: 6px;
}

.set-max-form label {
  margin-bottom: 0;
  font-weight: 500;
}

.set-max-form input {
  width: 80px;
  padding: 5px 10px;
}

/* Notification system for AJAX responses */
.notification {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 20px;
  background-color: white;
  color: #155724;
  border-radius: 6px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.2);
  z-index: 1000;
  transform: translateY(100px);
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
}

.notification.show {
  transform: translateY(0);
  opacity: 1;
}

.notification-success {
  background-color: #d4edda;
  border-left: 4px solid #28a745;
}

.notification-error {
  background-color: #f8d7da;
  color: #721c24;
  border-left: 4px solid #dc3545;
}

/* Responsive improvements */
@media (max-width: 768px) {
  .manga-header {
    flex-direction: column;
  }
  
  .manga-header-img {
    width: 100% !important;
    max-width: 240px !important;
    margin: 0 auto 20px auto;
  }
  
  .search-result {
    flex-direction: column;
  }
  
  .search-result-image {
    width: 100%;
    height: 200px;
  }
  
  .form-row {
    flex-direction: column;
  }
  
  .form-row > div {
    width: 100%;
  }
  
  .chapter-grid {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  }
  
  .notification {
    left: 20px;
    right: 20px;
    text-align: center;
  }
  
  /* Mobile button adjustments */
  .manga-btn-container {
    flex-wrap: nowrap;
    gap: 5px;
  }
  
  .manga-btn {
    padding: 0.4rem;
    font-size: 0.8rem;
    min-width: 0;
  }
}

/* Small mobile screens */
@media (max-width: 480px) {
  .manga-btn i {
    margin-right: 0;
  }
  
  .manga-btn span {
    display: none;
  }
}

/* Additional responsive styles for buttons */
@media (max-width: 768px) {
  .manga-btn {
    font-size: 0.8rem;
    padding: 0.4rem 0.6rem;
  }
  
  .manga-btn i {
    margin-right: 3px;
  }
}

@media (max-width: 480px) {
  .manga-btn span {
    display: none;
  }
  
  .manga-btn i {
    margin-right: 0;
    font-size: 0.9rem;
  }
  
  .manga-btn {
    padding: 0.25rem;
    justify-content: center;
    height: 28px;
  }
}

/* Enhanced button fixes to ensure Edit button stays properly contained */
.manga-btn-edit {
  word-break: keep-all;
  font-size: 0.85rem;
  min-width: 0;
  width: 100%;
  text-overflow: ellipsis;
  overflow: hidden;
  padding: 0.5rem 0.6rem;
}

/* Final adjustments for cleaner button appearance */
.manga-btn-container {
  gap: 5px;
}

.manga-btn {
  line-height: 1;
  letter-spacing: -0.2px;
}

/* Make button text more compact */
.manga-btn span {
  line-height: 1;
  margin-top: 1px;
}

/* Force proper containment for flexbox items */
.manga-btn-container {
  contain: content;
  display: flex;
  max-width: 100%;
}

.manga-btn-form {
  position: relative;
  max-width: 100%;
  flex-basis: 0;
  flex-grow: 1;
}

.manga-btn-form button,
.manga-btn-form a {
  max-width: 100%;
  width: 100%;
}

/* Fix for long title text in Edit button onclick */
.manga-btn-edit span {
  display: inline-block;
  max-width: calc(100% - 20px); /* Account for icon */
  text-overflow: ellipsis;
  overflow: hidden;
}

/* Ensure container has consistent styling */
.action-buttons {
  contain: layout;
  max-width: 100%;
}

/* Strong containment rules to prevent button overflow */
.manga-item {
  overflow: hidden !important;
}

.action-buttons,
.manga-btn-container,
.manga-btn-form,
.manga-btn {
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* Fix specifically for the Edit button which tends to overflow */
.manga-btn-edit {
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  display: inline-flex !important; 
  align-items: center !important;
  justify-content: center !important;
  padding-left: 0.6rem !important;
  padding-right: 0.6rem !important;
}

/* Smaller button styling for manga cards */
.manga-btn-container .manga-btn {
  font-size: 0.75rem;
  height: 30px;
  padding: 0.25rem 0.4rem;
}

.manga-btn-container .manga-btn i {
  font-size: 0.85rem;
  margin-right: 3px;
}

.manga-btn-container .manga-btn span {
  font-size: 0.75rem;
}

.manga-btn-container .manga-btn-edit {
  font-size: 0.75rem;
  padding: 0.25rem 0.4rem !important;
}

/* Reduce vertical spacing for buttons container */
.action-buttons {
  padding-top: 0.75rem;
}
