@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@400;500;600;700&display=swap");

:root {
  --background: 210 40% 98%;
  --foreground: 222.2 84% 4.9%;
  --card: 0 0% 100%;
  --card-foreground: 222.2 84% 4.9%;
  --primary: 222.2 47.4% 11.2%;
  --primary-foreground: 210 40% 98%;
  --secondary: 210 40% 96.1%;
  --secondary-foreground: 222.2 47.4% 11.2%;
  --muted: 210 40% 96.1%;
  --muted-foreground: 215.4 16.3% 46.9%;
  --accent: 221.2 83.2% 53.3%;
  --accent-foreground: 210 40% 98%;
  --destructive: 0 72.2% 50.6%;
  --destructive-foreground: 210 40% 98%;
  --border: 214.3 31.8% 91.4%;
  --input: 214.3 31.8% 91.4%;
  --ring: 221.2 83.2% 53.3%;
  --radius: 0.85rem;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 10px 24px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  position: relative;
  overflow-x: hidden;
  margin: 0;
  min-height: 100dvh;
  font-family: "IBM Plex Sans Arabic", "Noto Sans Arabic", Tahoma, sans-serif;
  color: hsl(var(--foreground));
  background:
    radial-gradient(circle at 5% 0%, rgba(59, 130, 246, 0.09) 0%, transparent 40%),
    radial-gradient(circle at 95% 100%, rgba(148, 163, 184, 0.22) 0%, transparent 38%),
    hsl(var(--background));
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto;
  z-index: -1;
  width: clamp(180px, 28vw, 320px);
  height: clamp(180px, 28vw, 320px);
  border-radius: 999px;
  filter: blur(42px);
  pointer-events: none;
}

body::before {
  top: -88px;
  right: -72px;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.26) 0%, rgba(59, 130, 246, 0) 70%);
}

body::after {
  bottom: -96px;
  left: -72px;
  background: radial-gradient(circle, rgba(15, 23, 42, 0.14) 0%, rgba(15, 23, 42, 0) 70%);
}

a {
  color: inherit;
}

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

.app-shell {
  position: relative;
  width: min(1220px, 100%);
  margin-inline: auto;
  padding: clamp(12px, 2.5vw, 28px);
}

.top-bar {
  position: sticky;
  top: 10px;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: clamp(14px, 2vw, 20px);
  background: hsla(0, 0%, 100%, 0.8);
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) + 0.1rem);
  box-shadow: var(--shadow);
  overflow: hidden;
  backdrop-filter: blur(6px);
}

.top-bar::before {
  content: "";
  position: absolute;
  inset-inline: 0;
  top: 0;
  height: 2px;
  background: linear-gradient(90deg, rgba(59, 130, 246, 0), rgba(59, 130, 246, 0.78), rgba(59, 130, 246, 0));
}

.top-bar > div:first-child {
  min-width: 0;
}

.header-actions {
  display: flex;
  gap: 0.625rem;
  flex-wrap: wrap;
}

.header-actions .btn {
  min-width: 130px;
}

.eyebrow {
  margin: 0;
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  color: hsl(var(--muted-foreground));
}

h1 {
  margin: 0.35rem 0;
  font-size: clamp(1.3rem, 2.5vw, 2rem);
  line-height: 1.25;
}

.sub-text {
  margin: 0;
  max-width: 64ch;
  color: hsl(var(--muted-foreground));
  line-height: 1.7;
  font-size: 0.94rem;
}

.panel,
.stat-card,
.login-card {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.stat-card {
  position: relative;
  overflow: hidden;
  padding: 1rem;
  transition: transform 0.24s ease, box-shadow 0.24s ease, border-color 0.24s ease;
}

.stat-card::before {
  content: "";
  position: absolute;
  inset-inline: 0;
  top: 0;
  height: 3px;
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.9), rgba(148, 163, 184, 0.85));
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: hsl(221.2 83.2% 89%);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08), 0 16px 28px rgba(15, 23, 42, 0.08);
}

.stat-card p {
  margin: 0 0 0.5rem;
  font-size: 0.83rem;
  color: hsl(var(--muted-foreground));
}

.stat-card h2 {
  margin: 0;
  font-size: clamp(1.4rem, 4.8vw, 1.9rem);
  line-height: 1.1;
}

.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.35fr);
  gap: 0.75rem;
  align-items: start;
}

.panel {
  position: relative;
  padding: clamp(0.85rem, 2vw, 1.1rem);
  overflow: hidden;
}

.panel::before {
  content: "";
  position: absolute;
  inset-inline: 1rem;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, rgba(15, 23, 42, 0), rgba(15, 23, 42, 0.12), rgba(15, 23, 42, 0));
}

.form-panel {
  position: sticky;
  top: 102px;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}

.panel-title-row h3 {
  margin: 0;
  font-size: 1.08rem;
}

#searchInput {
  inline-size: min(360px, 100%);
  border-radius: 999px;
  background-color: hsl(var(--secondary));
  padding-inline: 0.95rem;
}

.list-controls {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) repeat(3, minmax(108px, 1fr));
  gap: 0.5rem;
  align-items: center;
  inline-size: min(100%, 780px);
}

.pagination-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.82rem;
  padding-top: 0.78rem;
  border-top: 1px solid hsl(var(--border));
}

.pagination-wrap .btn {
  min-width: 108px;
}

.page-info {
  margin: 0;
  flex: 1;
  text-align: center;
  font-size: 0.82rem;
  color: hsl(var(--muted-foreground));
}

label {
  display: block;
  margin-top: 0.7rem;
  margin-bottom: 0.35rem;
  font-size: 0.86rem;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 0.2rem);
  background: #fff;
  padding: 0.64rem 0.74rem;
  font-size: 0.93rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

input::placeholder,
textarea::placeholder {
  color: hsl(var(--muted-foreground));
  opacity: 0.82;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 3px hsla(221, 83%, 53%, 0.18);
}

textarea {
  resize: vertical;
  min-height: 100px;
}

input[type="file"] {
  padding: 0.54rem 0.64rem;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.inline-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.5rem;
}

.source-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  margin-top: 0.2rem;
}

.dropzone {
  margin-top: 0.25rem;
  border: 1px dashed hsl(var(--border));
  border-radius: calc(var(--radius) - 0.2rem);
  background: hsl(var(--secondary));
  padding: 0.78rem 0.75rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.dropzone p {
  margin: 0;
}

.dropzone.is-dragover {
  border-color: hsl(var(--ring));
  background: hsl(210 100% 98%);
  box-shadow: 0 0 0 3px hsla(221, 83%, 53%, 0.16);
}

.cover-upload-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.5rem;
}

.cover-preview {
  margin-top: 0.55rem;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 0.2rem);
  background: hsl(var(--secondary));
  padding: 0.55rem;
  display: grid;
  justify-items: center;
  gap: 0.4rem;
}

.cover-preview img {
  width: min(160px, 100%);
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 0.55rem;
  border: 1px solid hsl(var(--border));
  background: #fff;
}

.upload-status {
  margin-top: 0.75rem;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 0.2rem);
  background: hsl(var(--secondary));
  padding: 0.56rem 0.65rem;
}

.upload-status-text {
  margin: 0 0 0.4rem;
  font-size: 0.82rem;
  color: hsl(var(--muted-foreground));
}

.progress-track {
  height: 9px;
  border-radius: 999px;
  background: hsl(214.3 31.8% 88%);
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, hsl(221.2 83.2% 53.3%), hsl(200 85% 52%));
  transition: width 0.2s ease;
}

.upload-status.is-success {
  border-color: hsl(141 60% 82%);
  background: hsl(138 76% 96%);
}

.upload-status.is-success .upload-status-text {
  color: hsl(142 76% 22%);
}

.upload-status.is-error {
  border-color: hsl(0 84% 89%);
  background: hsl(0 86% 97%);
}

.upload-status.is-error .upload-status-text {
  color: hsl(var(--destructive));
}

.source-option {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  padding: 0.48rem 0.72rem;
  font-size: 0.82rem;
  cursor: pointer;
}

.source-option input {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: hsl(var(--accent));
}

.sub-note {
  margin: 0.55rem 0 0;
  font-size: 0.82rem;
  line-height: 1.5;
  color: hsl(var(--muted-foreground));
}

.form-actions {
  margin-top: 0.95rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 0.2rem);
  min-height: 2.45rem;
  padding: 0.56rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  user-select: none;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

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

.btn:active {
  transform: translateY(0);
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px hsla(221, 83%, 53%, 0.26);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border-color: hsl(var(--primary));
}

.btn-small {
  min-height: 2.1rem;
  padding: 0.44rem 0.72rem;
  font-size: 0.8rem;
}

.btn-ghost {
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  border-color: hsl(var(--border));
}

.btn-neutral {
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  border-color: hsl(var(--border));
}

.btn-danger {
  background: hsl(0 100% 99%);
  color: hsl(var(--destructive));
  border-color: hsl(0 85% 90%);
}

.btn-danger:hover {
  background: hsl(0 90% 97%);
}

.state {
  margin-bottom: 0.7rem;
  padding: 0.74rem 0.84rem;
  border: 1px dashed hsl(var(--border));
  border-radius: calc(var(--radius) - 0.2rem);
  background: hsl(var(--secondary));
  color: hsl(var(--muted-foreground));
  font-size: 0.9rem;
}

.state-error {
  border-color: hsl(0 84% 89%);
  background: hsl(0 86% 97%);
  color: hsl(var(--destructive));
}

.books-list {
  display: grid;
  gap: 0.65rem;
}

.book-card {
  background: #fff;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 0.05rem);
  padding: 0.85rem;
  animation: fade-in-up 0.24s ease both;
  transition: transform 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
}

.book-card:hover {
  transform: translateY(-2px);
  border-color: hsl(221.2 83.2% 88%);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 20px rgba(15, 23, 42, 0.08);
}

.book-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.6rem;
}

.book-title {
  margin: 0;
  font-size: 1.03rem;
  line-height: 1.45;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0.3rem 0.62rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: hsl(215 25% 27%);
  background: hsl(210 40% 94.5%);
  border: 1px solid hsl(214.3 31.8% 88%);
  white-space: nowrap;
}

.badge.badge-danger {
  color: hsl(var(--destructive));
  background: hsl(0 86% 97%);
  border-color: hsl(0 84% 89%);
}

.book-description {
  margin: 0.6rem 0;
  color: hsl(221 30% 18%);
  font-size: 0.9rem;
  line-height: 1.7;
}

.book-cover-link {
  display: inline-flex;
  margin-top: 0.6rem;
  border-radius: 0.7rem;
  border: 1px solid hsl(var(--border));
  overflow: hidden;
  background: hsl(var(--secondary));
}

.book-cover-thumb {
  width: 92px;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
}

.book-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.62rem;
  font-size: 0.78rem;
  color: hsl(var(--muted-foreground));
}

.book-meta span {
  padding: 0.2rem 0.52rem;
  border-radius: 999px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--secondary));
  max-width: 100%;
  overflow-wrap: anywhere;
}

.book-meta:last-of-type {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.book-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.book-actions .btn {
  width: 100%;
  min-height: 2.25rem;
  font-size: 0.82rem;
  padding: 0.46rem 0.55rem;
}

.list-panel {
  min-height: clamp(420px, 76vh, 760px);
}

.books-list {
  padding-inline-end: 3px;
  max-height: clamp(300px, 56vh, 640px);
  overflow: auto;
}

.books-list::-webkit-scrollbar {
  width: 8px;
}

.books-list::-webkit-scrollbar-track {
  background: transparent;
}

.books-list::-webkit-scrollbar-thumb {
  background: hsl(214.3 31.8% 84%);
  border-radius: 999px;
}

.toast {
  position: fixed;
  inset-inline: 0;
  bottom: max(14px, env(safe-area-inset-bottom));
  width: fit-content;
  max-width: calc(100% - 24px);
  margin-inline: auto;
  padding: 0.62rem 0.86rem;
  border-radius: calc(var(--radius) - 0.2rem);
  color: hsl(var(--primary-foreground));
  background: hsl(var(--primary));
  box-shadow: var(--shadow);
  font-size: 0.86rem;
  z-index: 999;
}

.hidden {
  display: none !important;
}

.login-body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: clamp(14px, 3vw, 30px);
}

.login-shell {
  width: min(520px, 100%);
}

.login-card {
  padding: clamp(16px, 2.8vw, 24px);
}

.login-form {
  display: grid;
  gap: 0.64rem;
  margin-top: 0.7rem;
}

.categories-grid {
  grid-template-columns: minmax(0, 0.88fr) minmax(0, 1.12fr);
}

.category-form {
  display: grid;
  gap: 0.2rem;
}

.categories-list {
  display: grid;
  gap: 0.6rem;
}

.category-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.6rem;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 0.15rem);
  background: #fff;
  padding: 0.72rem;
}

.category-info h4 {
  margin: 0;
  font-size: 0.95rem;
}

.category-info p {
  margin: 0.32rem 0 0;
  font-size: 0.78rem;
  color: hsl(var(--muted-foreground));
}

.category-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, auto));
  gap: 0.45rem;
}

@media (max-width: 1080px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .panel-grid {
    grid-template-columns: 1fr;
  }

  .form-panel {
    position: static;
  }

  .list-panel {
    order: 2;
  }

  .form-panel {
    order: 1;
  }
}

@media (max-width: 760px) {
  .top-bar {
    position: static;
  }

  .top-bar {
    padding: 0.82rem;
  }

  .top-bar,
  .header-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .header-actions .btn,
  .form-actions .btn {
    width: 100%;
  }

  .source-switch {
    grid-template-columns: 1fr;
  }

  .inline-field,
  .cover-upload-row {
    grid-template-columns: 1fr;
  }

  .panel-title-row {
    flex-direction: column;
    align-items: stretch;
  }

  .list-controls {
    inline-size: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #searchInput {
    inline-size: 100%;
  }

  .book-head {
    flex-direction: column;
  }

  .book-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .category-card {
    grid-template-columns: 1fr;
  }

  .category-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .list-panel {
    min-height: auto;
  }

  .books-list {
    max-height: none;
    overflow: visible;
  }

  .pagination-wrap {
    flex-wrap: wrap;
  }

  .page-info {
    width: 100%;
    order: -1;
  }

  .pagination-wrap .btn {
    flex: 1;
  }
}

@media (max-width: 520px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .app-shell {
    padding: 12px;
  }

  .panel {
    padding: 0.75rem;
  }

  .btn {
    min-height: 2.35rem;
  }

  .book-actions {
    grid-template-columns: 1fr;
  }

  .list-controls {
    grid-template-columns: 1fr;
  }

  .category-actions {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}
