@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #f8fafc;
  --text: #1f2937;
  --emeraldDeep: #064e3b;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #e2e8f0;
  --muted: #64748b;
  --accent: #15803d;
  --accent-strong: #166534;
  --accent-soft: #dcfce7;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 10px 24px rgba(15, 23, 42, 0.06);
  --emeraldSoft: #dcfce7;
  --stoneDeep: #1f2937;
}

  * {
    box-sizing: border-box;
  }

  html {
    scroll-behavior: smooth;
    background-color: #f8fafc;
    color: #1f2937;
  }

  body {
    margin: 0;
    min-height: 100vh;
    background-color: #f8fafc;
    color: #1f2937;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  }

  html[dir='rtl'] body {
    font-family: Cairo, 'Segoe UI', Tahoma, Arial, sans-serif;
  }

  html[dir='rtl'] .brand-title,
  html[dir='rtl'] .hero-copy h1,
  html[dir='rtl'] .panel h2,
  html[dir='rtl'] .section-heading h3 {
    font-family: Cairo, 'Segoe UI', Tahoma, Arial, sans-serif;
    letter-spacing: 0;
  }

  img {
    display: block;
    max-width: 100%;
  }

  button,
  input,
  textarea,
  select {
    font: inherit;
  }

  a {
    color: inherit;
  }

  .page-shell {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 2rem 56px;
  }

  .auth-shell {
    width: min(980px, calc(100% - 32px));
  }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 18px 22px;
    margin-bottom: 28px;
    border: 1px solid rgba(226, 232, 240, 0.9);
    border-radius: 1.5rem;
    background: transparent;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: var(--shadow-soft);
  }

  .brand-title,
  .hero-copy h1,
  .panel h2,
  .section-heading h3 {
    margin: 0;
    font-family: Cinzel, Georgia, serif;
    letter-spacing: 0.01em;
  }

  .brand-title {
    font-size: clamp(1.5rem, 2vw, 2.1rem);
    color: var(--emeraldDeep);
  }

  .eyebrow,
  .section-label {
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.24em;
    text-transform: uppercase;
  }

  .nav-links {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
  }

  .nav-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 10px 16px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--stoneDeep);
    text-decoration: none;
    font-weight: 600;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
  }

  .nav-link:hover,
  .nav-link.active {
    transform: translateY(-1px);
    border-color: #b7e4c7;
    background: #f0fdf4;
    box-shadow: 0 8px 20px rgba(21, 128, 61, 0.08);
  }

  .nav-user-button {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #mobile-menu {
    transition: all 0.3s ease-in-out;
    z-index: 100;
  }

  #welcome-message {
    color: #475569;
    font-size: 0.875rem;
    font-weight: 500;
  }

  .hero-card,
  .panel,
  .book-card {
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow);
  }

  .hero-card {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    padding: 28px;
    border-radius: 2rem;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  }

  .hero-copy {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .hero-copy .section-label {
    margin-bottom: 0;
  }

  .hero-copy h1,
  .panel h2,
  .section-heading h3 {
    font-size: clamp(1.7rem, 3vw, 2.6rem);
    line-height: 1.08;
    color: var(--text);
  }

  .hero-text {
    margin: 14px 0 0;
    max-width: 62ch;
    color: var(--muted);
    line-height: 1.7;
  }

  .hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 24px;
  }

  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    padding: 12px 18px;
    border-radius: 999px;
    border: 1px solid transparent;
    text-decoration: none;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease;
  }

  .btn:hover {
    transform: translateY(-1px);
  }

  .btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #ffffff;
    box-shadow: 0 14px 26px rgba(21, 128, 61, 0.18);
  }

  .btn-secondary {
    background: #ffffff;
    color: var(--text);
    border-color: var(--border);
  }

  .btn-delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 12px 18px;
    border-radius: 12px;
    border: none;
    background: #fee2e2;
    color: #991b1b;
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
    letter-spacing: 0;
    text-transform: none;
  }

  .btn-delete:hover {
    background: #fecaca;
    color: #991b1b;
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(239, 68, 68, 0.14);
  }

  .hero-panel {
    padding: 20px;
    border-radius: 1.5rem;
    background: linear-gradient(180deg, #f0fdf4 0%, #ffffff 100%);
    border: 1px solid #d1fae5;
  }

  .content-grid,
  .dashboard-layout,
  .auth-grid {
    display: grid;
    gap: 24px;
    margin-top: 28px;
  }

  .auth-grid {
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: 1.75rem;
    background: #ffffff;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
  }

  .panel {
    padding: 24px;
    border-radius: 1.75rem;
    background: #ffffff;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    border-top: 4px solid var(--accent);
  }

  .books-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0;
    width: 100%;
    border: 1px solid #e5e7eb;
  }

  @media (min-width: 1024px) {
    .books-grid {
      grid-template-columns: repeat(4, minmax(0, 1fr));
    }
  }

  .book-card {
    display: flex;
    flex-direction: column;
    width: 100%;
    margin: 0;
    padding: 0;
    border: 0.5px solid #e5e7eb;
    border-radius: 0;
    background-color: transparent;
    box-shadow: none;
    overflow: hidden;
    color: var(--text);
    transition: transform 0.2s ease, border-color 0.2s ease;
  }

  .book-card:hover {
    transform: translateY(-3px);
    border-color: #cbd5e1;
  }

  .book-card .btn {
    width: fit-content;
    min-height: 38px;
    margin: 0 auto 12px;
    padding: 8px 12px;
    font-size: 0.8rem;
    font-weight: 600;
  }

  .book-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: auto;
  }

  @media (min-width: 640px) {
    .book-actions {
      flex-direction: row;
      align-items: stretch;
    }

    .book-actions > * {
      flex: 1 1 0;
    }
  }

  .book-placeholder {
    padding: 20px;
    color: var(--muted);
  }

  .book-title {
    margin: 0 0 8px;
    font-size: 1rem;
    line-height: 1.3;
    color: var(--stoneDeep);
  }

  .book-meta {
    margin: 0.3rem 0;
    color: var(--muted);
    font-size: 0.92rem;
  }

  .book-description {
    margin: 0.35rem 0 0.5rem;
    color: #475569;
    font-size: 0.9rem;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
  }

  #gallery-modal {
    position: fixed;
    inset: 0;
    align-items: center;
    justify-content: center;
    z-index: 9999 !important;
    pointer-events: auto;
    animation: galleryFadeIn 0.22s ease-out;
  }

  #gallery-modal img {
    max-width: 90vw;
    max-height: 80vh;
    width: auto;
    height: auto;
    object-fit: contain;
  }

  #main-gallery-img {
    max-height: 70vh;
    object-fit: contain;
    transition: opacity 0.2s ease;
  }

  #gallery-modal button[aria-label="Previous image"],
  #gallery-modal button[aria-label="Next image"] {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: #ffffff;
    font-size: 2rem;
    cursor: pointer;
  }

  #gallery-modal button[aria-label="Previous image"] {
    left: 0;
  }

  #gallery-modal button[aria-label="Next image"] {
    right: 0;
  }

  #gallery-thumbnails {
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap;
  }

  #gallery-thumbnails img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border: 2px solid transparent;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
  }

  #gallery-thumbnails button:hover img {
    opacity: 0.85;
    transform: translateY(-1px);
  }

  #gallery-thumbnails button.active img,
  #gallery-thumbnails button[aria-current="true"] img {
    border-color: #ffffff;
    opacity: 1;
  }

  #gallery-modal [data-gallery-close] {
    position: absolute;
    z-index: 10000;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #ffffff;
    padding: 10px 20px;
    cursor: pointer;
    pointer-events: auto;
  }

  #gallery-modal [data-gallery-close]:hover {
    background: rgba(255, 255, 255, 0.4);
  }

  .book-card img {
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    margin: 0;
    padding: 0;
    border: 2px solid #e5e7eb;
    border-radius: 1rem;
    transition: opacity 0.2s ease, transform 0.2s ease;
  }

  .book-card > div:first-of-type {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 12px;
    min-height: 72px;
  }

  /* If #e5e7eb feels too light, try #d1d5db (Stone 300) for a slightly darker gray border. */

  .book-cover-image {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    margin: 0;
    padding: 0;
    background: #f1f5f9;
    border-bottom: 1px solid #e5e7eb;
    transition: opacity 0.2s ease, transform 0.2s ease;
  }

  .image-container {
    position: relative;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
  }

  .photo-count-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 1;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.78);
    color: #ffffff;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.02em;
  }

  .upload-slot {
    display: grid;
    gap: 8px;
  }

  .upload-slot-title {
    color: #475569;
    font-size: 0.875rem;
    font-weight: 600;
  }

  .upload-dropzone {
    display: flex;
    min-height: 46px;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    border: 1px dashed #cbd5e1;
    border-radius: 1rem;
    background: #f8fafc;
    color: #475569;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    text-align: center;
    transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
  }

  .upload-dropzone:hover {
    border-color: #34d399;
    background: #ecfdf5;
    color: #047857;
  }

  .upload-preview-frame {
    position: relative;
    min-height: 120px;
    overflow: hidden;
    border-radius: 1rem;
    background: #f1f5f9;
  }

  .upload-preview {
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: cover;
  }

  .upload-remove {
    position: absolute;
    right: 8px;
    bottom: 8px;
    padding: 5px 9px;
    border: 0;
    border-radius: 999px;
    background: rgba(127, 29, 29, 0.9);
    color: #ffffff;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
  }

  @keyframes galleryFadeIn {
    from {
      opacity: 0;
    }

    to {
      opacity: 1;
    }
  }

  .form-stack {
    display: grid;
    gap: 14px;
    margin-top: 18px;
  }

  .form-stack label {
    display: grid;
    gap: 8px;
    color: var(--stoneDeep);
  }

  .form-stack span {
    color: var(--stoneDeep);
    font-size: 0.92rem;
    font-weight: 500;
  }

  .form-stack input,
  .form-stack textarea,
  .form-stack select {
    width: 100%;
    padding: 13px 14px;
    border-radius: 16px;
    border: 1px solid #e5e7eb;
    background: #f8fafc;
    color: #1f2937;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  }

  .form-stack input::placeholder,
  .form-stack textarea::placeholder {
    color: #94a3b8;
  }

  .form-stack input:focus,
  .form-stack textarea:focus,
  .form-stack select:focus {
    border-color: #16a34a;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.1);
    background: #ffffff;
  }

  #searchInput {
    color: #1f2937;
  }

  html[dir='rtl'] #searchInput {
    text-align: right;
  }

  html[dir='rtl'] .section-label,
  html[dir='rtl'] .eyebrow {
    letter-spacing: 0.05em;
  }

  html[dir='rtl'] .book-card .btn {
    margin-inline: auto;
  }

  #searchInput:focus {
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.1);
  }

  #bookForm button[type='submit'] {
    font-weight: 800;
    letter-spacing: 0.03em;
  }

  .status-box {
    min-height: 64px;
    padding: 16px;
    border-radius: 18px;
    color: var(--muted);
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
  }

  .text-emeraldDeep {
    color: var(--emeraldDeep);
  }

  .w-full {
    width: 100%;
  }

  .mt-6 {
    margin-top: 24px;
  }

  @media (max-width: 900px) {
    .hero-card,
    .dashboard-layout,
    .auth-grid {
      grid-template-columns: 1fr;
    }

    .topbar {
      align-items: flex-start;
      flex-direction: column;
    }
  }

  @media (max-width: 640px) {
    .page-shell,
    .auth-shell {
      width: min(100% - 20px, 1180px);
      padding-top: 14px;
    }

    .topbar,
    .hero-card,
    .panel {
      padding: 18px;
      border-radius: 1.25rem;
    }

    .books-grid {
      gap: 18px;
    }
  }

  .hidden {
    display: none !important;
  }
