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

/*
 *= require_self
 *= require_tree .
 */

/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.6;
  color: #333;
  background-color: #f5f7fa;
  padding: 20px;
}

@media (max-width: 600px) {
  body {
    padding: 0; /* Remove body padding on mobile for full-width content */
  }
}

/* Navigation bar */
.user-nav {
  background-color: white;
  padding: 1rem;
  margin: -20px -20px 20px -20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
}

@media (max-width: 600px) {
  .user-nav {
    margin: 0 0 1rem 0; /* Reset margins on mobile */
    padding: 0.75rem 1rem; /* Slightly less padding */
    flex-wrap: wrap; /* Allow wrapping on very small screens */
    font-size: 0.9rem; /* Slightly smaller text */
  }
}

.user-nav form {
  margin: 0;
  display: inline-block;
}

.user-nav button {
  background: none;
  border: none;
  color: #e53e3e;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.user-nav button:hover {
  background-color: #fff5f5;
}

/* Flash messages */
.notice, .alert {
  padding: 1rem;
  margin-bottom: 1rem;
  border-radius: 4px;
  font-weight: 500;
}

.notice {
  background-color: #e6fffa;
  color: #047857;
  border: 1px solid #a7f3d0;
}

.alert {
  background-color: #fff5f5;
  color: #e53e3e;
  border: 1px solid #fca5a5;
}

/* Main container styling */
.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  box-sizing: border-box;
}

/* Center edit forms more prominently */
body.items-edit .container,
body.items-new .container {
  max-width: 700px;
  margin: 2rem auto;
}

/* Ensure container is centered on verification page */
body.sessions-verify_2fa .container,
.container.verify-2fa-container {
  max-width: 800px;
  padding: 2rem;
}

@media (max-width: 600px) {
  .container {
    padding: 1rem 0; /* Minimal padding on mobile - let content handle its own spacing */
    border-radius: 0; /* Full-width on mobile */
    box-shadow: none; /* Remove shadow on mobile */
    margin: 0; /* Full width */
    max-width: 100%; /* Full width */
  }
}

/* Typography */
h1 {
  font-size: 2rem;
  font-weight: 600;
  color: #1a202c;
  margin-bottom: 1.5rem;
}

h2 {
  font-size: 1.5rem;
  font-weight: 500;
  color: #2d3748;
  margin: 1.5rem 0 1rem;
}

/* Links */
a {
  color: #3182ce;
  text-decoration: none;
  transition: color 0.2s;
}

a:hover {
  color: #2c5282;
  text-decoration: underline;
}

/* Forms */
/* Form layout */
.recommendation-form {
  max-width: 300px;
  margin: 0 auto;
}

.form-field {
  position: relative;
  margin-bottom: 1rem;
  width: 100%;
  max-width: 300px;
  /* margin: 0 auto; /* Center align the form fields */
}

/* Search input styling */
.form-field input[type="text"] {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.375rem;
  font-size: 1rem;
  /* margin: 0 auto; /* Center align the search input */
}

/* New item section */
.new-item-section {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.375rem;
  background-color: #f8fafc;
}

/* Form inputs */
input[type="text"],
input[type="password"],
input[type="email"],
select,
textarea {
  width: 100%;
  max-width: 300px;
  padding: 0.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  font-size: 1rem;
  transition: border-color 0.2s;
  box-sizing: border-box;
  /* margin: 0 auto; /* Center align the form inputs */
}

/* Style labels consistently */
.form-field label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: #1a202c;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #3182ce;
  box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.1);
}

/* Search results dropdown - base styles are in search.css */
/* Hide search-results when empty to prevent visible borders */
.search-results:empty {
  display: none !important;
  border: none !important;
  margin-top: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
}

.search-result {
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.search-result:hover {
  background-color: #f7fafc;
}

/* Preferences page styling */
.preferences-section {
  margin-bottom: 2rem;
  padding: 1.5rem;
  background-color: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

.preferences-section h2 {
  margin-top: 0;
  margin-bottom: 1.5rem;
  font-size: 1.25rem;
  color: #1a202c;
}

.current-email {
  margin-bottom: 1.5rem;
  padding: 0.75rem;
  background-color: white;
  border-radius: 4px;
  border: 1px solid #e2e8f0;
}

/* Checkbox field styling */
.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.checkbox-input {
  width: auto;
  margin: 0;
  cursor: pointer;
}

.checkbox-label {
  display: inline;
  margin: 0;
  font-weight: 500;
  color: #1a202c;
  cursor: pointer;
}

/* Form inputs in preferences */
.preferences-section .form-field input[type="password"],
.preferences-section .form-field input[type="email"],
.preferences-section .form-field select {
  max-width: 100%;
  width: 100%;
}

.preferences-section .form-field {
  max-width: 100%;
}

.form-select {
  width: 100%;
  max-width: 100%;
  padding: 0.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  font-size: 1rem;
  background-color: white;
}

.form-input {
  width: 100%;
  max-width: 100%;
  padding: 0.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  font-size: 1rem;
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: #3182ce;
  box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.1);
}

/* Form actions */
.form-actions {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e2e8f0;
}

.form-actions input[type="submit"] {
  background-color: #3182ce;
  color: white;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
}

.form-actions input[type="submit"]:hover {
  background-color: #2c5282;
}

.form-actions a {
  padding: 0.75rem 1.5rem;
  border-radius: 4px;
  background-color: #e2e8f0;
  color: #4a5568;
  transition: background-color 0.2s;
}

.form-actions a:hover {
  background-color: #cbd5e0;
  text-decoration: none;
}

.search-result.selected {
  background-color: #e5edff;
  color: #1a365d;
  font-weight: 600;
  border-left: 2px solid #3b82f6;
}

/* Remove any animation on selection */
.search-result.selected {
  animation: none;
}

/* Accessibility improvements */
.search-result {
  position: relative;
  outline: none;
}

.search-result:focus-visible {
  box-shadow: 0 0 0 2px #3b82f6;
}

/* Search field wrapper */
.search-field-wrapper {
  position: relative;
  width: 100%;
}

/* Clear button positioning */
.search-clear-button {
  position: absolute;
  right: 8px;
  top: 50%;
  /*transform: translateY(-1%);*/
  background: transparent;
  border: none;
  color: #64748b;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
  line-height: 0.5;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 20px;
  width: 20px;
  border-radius: 50%;
  z-index: 2;
}

.search-clear-button:hover {
  background-color: #f1f5f9;
  color: #475569;
}

.search-clear-button:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* Screen reader only text */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Loading state */
.search-loading {
  padding: 8px 12px;
  color: #64748b;
  font-style: italic;
}

/* No results state */
.search-no-results {
  padding: 8px 12px;
  color: #64748b;
  font-style: italic;
}

/* Keyboard shortcut hints */
.keyboard-hint {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  font-size: 0.75rem;
  pointer-events: none;
}

/* Error messages */
.error-messages {
  width: 100%;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background-color: #fff5f5;
  border: 1px solid #feb2b2;
  border-radius: 4px;
  box-sizing: border-box;
}

.error-messages h2 {
  color: #c53030;
  font-size: 1rem;
  margin: 0 0 0.5rem 0;
}

.error-messages ul {
  margin: 0;
  padding-left: 1.5rem;
  color: #c53030;
}

.error-messages li {
  margin: 0.25rem 0;
}

/* Page header and footer */
.page-header,
.page-footer {
  text-align: center;
  margin: 0 auto;
}

.page-header h1 {
  font-size: 2rem;
  font-weight: 600;
  color: #1a202c;
  margin-bottom: 1.5rem;
}

.page-footer a {
  color: #3182ce;
  text-decoration: none;
  transition: color 0.2s;
}

.page-footer a:hover {
  color: #2c5282;
  text-decoration: underline;
}

/* ISBN field styling */
.isbn-field {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.isbn-status {
  font-size: 0.9rem;
}

.isbn-status.loading {
  color: #4a5568;
}

.isbn-status.success {
  color: #047857;
}

.isbn-status.error {
  color: #dc2626;
}

/* User search specific styling */
[data-controller="search"] {
  position: relative;
  width: 100%
  max-width: 300px;
}

[data-controller="search"] input[type="text"] {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.375rem;
  font-size: 1rem;
}

[data-controller="search"] .search-results {
  position: absolute;
  z-index: 1000;
  background: white;
  border: 1px solid #e2e8f0;
  border-top: none !important; /* Remove top border to prevent visible line */
  border-radius: 0.375rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  width: 100%;
  max-height: 200px;
  overflow-y: auto;
  margin-top: 2px;
  left: 0;
}

/* Item search specific styling */
[data-controller="item-search"] {
  position: relative;
  width: 100%;
  max-width: 300px; /* Adjusted to 300px */
}

[data-controller="item-search"] input[type="text"] {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.375rem;
  font-size: 1rem;
}

[data-controller="item-search"] .search-results {
  position: absolute;
  z-index: 1000;
  background: white;
  border: 1px solid #e2e8f0;
  border-top: none !important; /* Remove top border to prevent visible line */
  border-radius: 0.375rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  width: 100%;
  max-height: 200px;
  overflow-y: auto;
  margin-top: 2px;
  left: 0;
}

/* Generic search dropdown rows (search controller) */
[data-controller="search"] .search-result {
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

[data-controller="search"] .search-result:hover,
[data-controller="search"] .search-result.selected {
  background-color: #f7fafc;
}

/* Adjust input padding to accommodate clear button */
[data-controller="search"] input[type="text"],
[data-controller="item-search"] input[type="text"] {
  padding-right: 32px;
}

.user-recommendations {
  padding: 20px;
}

.recommendations-section {
  margin-bottom: 30px;
}

.recommendations-list {
  display: grid;
  gap: 15px;
  margin-top: 10px;
}

.recommendation-item {
  background-color: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 8px;
  padding: 15px;
}

.recommendation-date {
  color: #6c757d;
  font-size: 0.9em;
  margin-top: 5px;
}

.user-link {
  color: #0d6efd;
  text-decoration: none;
  font-weight: 500;
}

.user-link:hover {
  text-decoration: underline;
}

/* Modal styles */
.modal-backdrop {
  position: fixed !important;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.75) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  z-index: 9999 !important;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: white !important;
  border-radius: 12px !important;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04) !important;
  width: 90% !important;
  max-width: 600px !important;
  margin: 2rem !important;
  position: relative !important;
  overflow: hidden !important;
  animation: slideIn 0.2s ease-out;
}

.modal-header {
  background: #f8f9fa !important;
  padding: 1rem 1.5rem !important;
  border-bottom: 1px solid #e9ecef !important;
  display: flex !important;
  justify-content: space-between !important;
  align-items: center !important;
}

.modal-title {
  margin: 0 !important;
  font-size: 1.25rem !important;
  font-weight: 600 !important;
  color: #1a1a1a !important;
  flex: 1 !important;
}

.modal-header-actions {
  display: flex !important;
  align-items: center !important;
  gap: 0.5rem !important;
}

.btn-edit-small {
  padding: 0.375rem 0.75rem !important;
  font-size: 0.875rem !important;
  font-weight: 500 !important;
  color: #fff !important;
  background-color: #0d6efd !important;
  border: 1px solid #0d6efd !important;
  border-radius: 0.25rem !important;
  text-decoration: none !important;
  transition: all 0.2s !important;
  display: inline-block !important;
  line-height: 1.5 !important;
}

.btn-edit-small:hover {
  background-color: #0b5ed7 !important;
  border-color: #0a58ca !important;
  color: #fff !important;
  text-decoration: none !important;
}

.modal-close {
  background: none !important;
  border: none !important;
  font-size: 1.5rem !important;
  padding: 0.5rem !important;
  cursor: pointer !important;
  color: #666 !important;
  width: 2.5rem !important;
  height: 2.5rem !important;
  border-radius: 50% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: all 0.2s !important;
  margin: -0.5rem -0.5rem -0.5rem auto !important;
}

.modal-close:hover {
  background-color: #f3f4f6 !important;
  color: #1a1a1a !important;
}

.modal-body {
  padding: 1.5rem !important;
  max-height: calc(100vh - 200px) !important;
  overflow-y: auto !important;
}

/* Item details styling */
.modal-body p {
  margin-bottom: 1rem !important;
  line-height: 1.5 !important;
}

.modal-body strong {
  color: #4a5568 !important;
  font-weight: 600 !important;
  display: inline-block !important;
  width: 120px !important;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* TOTP Setup */
.totp-setup {
  max-width: 600px;
  margin: 0 auto;
}

.qr-code {
  background: white;
  padding: 20px;
  display: inline-block;
  margin: 20px 0;
  border-radius: 8px;
}

.qr-code svg {
  display: block;
}

/* Verification - Centered TOTP with fallback */
.verify-2fa-page {
  text-align: center;
}

.verification-primary {
  max-width: 400px;
  margin: 2rem auto;
  text-align: center;
}

.verification-primary h2 {
  margin-bottom: 1.5rem;
  font-size: 1.3em;
}

.verification-primary .form-field {
  margin-bottom: 1.5rem;
  margin-left: auto;
  margin-right: auto;
  width: 280px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.verification-primary .form-field label {
  text-align: left;
  margin-bottom: 0.5rem;
}

.verification-primary .form-field input[type="text"] {
  width: 100%;
  box-sizing: border-box;
}

.verification-primary .submit-button {
  width: 280px;
  margin-left: auto;
  margin-right: auto;
  padding: 0.75rem;
  font-size: 1.1em;
  box-sizing: border-box;
}

.verification-fallback {
  margin-top: 2rem;
  text-align: center;
  font-size: 0.9em;
  color: #6b7280;
}

.verification-fallback a {
  color: #4b5563;
  text-decoration: none;
  border-bottom: 1px dashed #9ca3af;
}

.verification-fallback a:hover {
  color: #1f2937;
  border-bottom-color: #1f2937;
}

/* Style button_to as a link */
.verification-fallback .link-button {
  background: none;
  border: none;
  padding: 0;
  color: #4b5563;
  text-decoration: none;
  border-bottom: 1px dashed #9ca3af;
  font-size: inherit;
  cursor: pointer;
}

.verification-fallback .link-button:hover {
  color: #1f2937;
  border-bottom-color: #1f2937;
}

@media (prefers-color-scheme: dark) {
  .verification-fallback {
    color: #9ca3af;
  }

  .verification-fallback a {
    color: #d1d5db;
    border-bottom-color: #6b7280;
  }

  .verification-fallback a:hover {
    color: #f3f4f6;
    border-bottom-color: #9ca3af;
  }

  .verification-fallback .link-button {
    color: #d1d5db;
    border-bottom-color: #6b7280;
  }

  .verification-fallback .link-button:hover {
    color: #f3f4f6;
    border-bottom-color: #9ca3af;
  }
}

/* TOTP Status in Preferences */
.totp-status {
  margin: 20px 0;
}

.status-enabled {
  color: #38a169;
  font-weight: bold;
}

.status-disabled {
  color: #718096;
}

.info-box {
  background: #edf2f7;
  border-left: 4px solid #4299e1;
  padding: 15px;
  margin: 15px 0;
}

@media (prefers-color-scheme: dark) {
  .qr-code {
    background: white;
  }

  .info-box {
    background: #2d3748;
    border-left-color: #63b3ed;
  }
}

/* Settings page card containers */
.settings-card {
  background-color: white;
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  border: 1px solid #e2e8f0;
}

.settings-card .card-header {
  margin-bottom: 1.5rem;
  border-bottom: 2px solid #e2e8f0;
  padding-bottom: 1rem;
  background-color: #f8fafc;
  margin: -1.5rem -1.5rem 1.5rem -1.5rem;
  padding: 1.25rem 1.5rem;
  border-radius: 8px 8px 0 0;
}

.settings-card .card-header h2 {
  font-size: 1.25rem;
  margin-bottom: 0.25rem;
  color: #2d3748;
  margin-top: 0;
}

.settings-card .card-subtitle {
  font-size: 0.9rem;
  color: #718096;
  margin: 0;
}

.settings-card .preferences-section {
  margin-bottom: 1.5rem;
  padding: 0;
  background-color: transparent;
  border-radius: 0;
  border: none;
}

.settings-card .preferences-section:last-of-type {
  margin-bottom: 1rem;
}

.settings-card .preferences-section h3 {
  font-size: 1.1rem;
  margin-top: 0;
  margin-bottom: 1rem;
  color: #1a202c;
  font-weight: 600;
}

/* Button styling consistency */
.btn-primary {
  background-color: #3182ce;
  color: white;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
  text-decoration: none;
  display: inline-block;
}

.btn-primary:hover {
  background-color: #2c5282;
  text-decoration: none;
}

.btn-secondary {
  background-color: #e2e8f0;
  color: #4a5568;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
  text-decoration: none;
  display: inline-block;
}

.btn-secondary:hover {
  background-color: #cbd5e0;
  text-decoration: none;
  color: #4a5568;
}

.btn-danger {
  background-color: #e53e3e;
  color: white;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
  text-decoration: none;
  display: inline-block;
}

.btn-danger:hover {
  background-color: #c53030;
  text-decoration: none;
  color: white;
}

/* Danger zone styling */
.danger-zone {
  border-color: #fc8181;
  border-width: 2px;
}

.danger-zone .card-header {
  background-color: #fed7d7;
  border-bottom-color: #fc8181;
}

.danger-zone-content {
  margin-top: 1rem;
}

.warning-message {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background-color: #fff5f5;
  border-left: 4px solid #e53e3e;
  border-radius: 4px;
}

.warning-message strong {
  color: #c53030;
  font-size: 1.1rem;
}

.deletion-list {
  margin: 0.75rem 0;
  padding-left: 1.5rem;
  color: #4a5568;
}

.deletion-list li {
  margin-bottom: 0.5rem;
}

/* Back link styling */
.back-link {
  text-align: center;
  margin-top: 2rem;
  margin-bottom: 2rem;
}

.back-link a {
  color: #4a5568;
  font-size: 0.9rem;
}

/* Mobile responsiveness for settings cards */
@media (max-width: 600px) {
  .settings-card {
    padding: 1rem;
    margin-bottom: 1.5rem;
    border-radius: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
    border-left: none;
    border-right: none;
  }

  .settings-card .card-header {
    margin: -1rem -1rem 1rem -1rem;
    padding: 1rem;
    border-radius: 0;
  }

  .settings-card .card-header h2 {
    font-size: 1.1rem;
  }

  .btn-primary,
  .btn-secondary {
    width: 100%;
    text-align: center;
  }
}
