@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=Readex+Pro:wght@400;600;700&display=swap');

:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --surface-soft: #f4efe8;
  --ink: #18181b;
  --ink-soft: #52525b;
  --muted: #71717a;
  --line: #e6dfd3;
  --brand: #1b6b63;
  --brand-dark: #124b45;
  --brand-soft: #e6f4f1;
  --sun: #f2b705;
  --sun-soft: #fef6db;
  --emerald: #1b6b63;
  --emerald-soft: #e6f4f1;
  --dys: #4f46e5;
  --dys-soft: #eef2ff;
  --radius-lg: 20px;
  --radius-md: 14px;
  --shadow-sm: 0 2px 10px rgba(24, 24, 27, 0.04);
  --shadow-md: 0 12px 32px rgba(24, 24, 27, 0.07);
  --shadow-book: -4px 8px 20px rgba(24, 24, 27, 0.16), 0 2px 6px rgba(24, 24, 27, 0.08);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: 'Plus Jakarta Sans', 'Readex Pro', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  padding-bottom: calc(92px + env(safe-area-inset-bottom, 0px));
}

[dir="rtl"],
:lang(ar) {
  font-family: 'Readex Pro', 'Plus Jakarta Sans', sans-serif;
}

/* Header Bab Rayan — Vert Palmier apaisant */
.topbar {
  background: linear-gradient(125deg, #1f786f 0%, #165952 60%, #10423d 100%);
  color: #fff;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 20px 14px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 6px 24px rgba(18, 75, 69, 0.18);
}

.topbar-inner {
  max-width: 1220px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.brand-logo-wrap {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.26);
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-logo-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-text h1 {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--sun);
  display: inline-block;
}

.brand-text p {
  margin: 1px 0 0;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.85);
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-tabs-desktop {
  display: flex;
  gap: 4px;
  background: rgba(0, 0, 0, 0.18);
  padding: 5px;
  border-radius: 14px;
}

.tab-btn {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.9);
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.86rem;
  cursor: pointer;
  transition: all 0.18s ease;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: inherit;
}

.tab-btn svg {
  width: 17px;
  height: 17px;
  stroke-width: 2.1;
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.tab-btn.active {
  background: #fff;
  color: var(--brand-dark);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.14);
}

.badge-count {
  background: var(--sun);
  color: #18181b;
  font-size: 0.71rem;
  padding: 1px 7px;
  border-radius: 999px;
  font-weight: 800;
}

.btn-install-top {
  border: 1px solid rgba(255, 255, 255, 0.32);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  padding: 8px 13px;
  border-radius: 11px;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  backdrop-filter: blur(6px);
}

.btn-install-top:hover {
  background: rgba(255, 255, 255, 0.24);
}

/* Mobile Bottom Tab Bar (iOS / Android Native Feel) */
.bottom-nav-mobile {
  display: none;
}

@media (max-width: 860px) {
  .nav-tabs-desktop {
    display: none;
  }

  .bottom-nav-mobile {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
    padding: 6px 8px calc(8px + env(safe-area-inset-bottom, 0px));
    z-index: 70;
    box-shadow: 0 -6px 24px rgba(24, 24, 27, 0.08);
  }

  .m-tab-btn {
    border: none;
    background: transparent;
    color: var(--muted);
    padding: 6px 4px;
    border-radius: 12px;
    font-size: 0.71rem;
    font-weight: 700;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    font-family: inherit;
    position: relative;
  }

  .m-tab-btn svg {
    width: 21px;
    height: 21px;
    stroke-width: 2.1;
  }

  .m-tab-btn.active {
    color: var(--brand);
  }

  .m-tab-btn.active svg {
    transform: translateY(-1px);
  }

  .m-badge {
    position: absolute;
    top: 2px;
    right: 22%;
    background: var(--brand);
    color: #fff;
    font-size: 0.63rem;
    padding: 0 5px;
    border-radius: 999px;
    font-weight: 800;
  }
}

.container {
  max-width: 1220px;
  margin: 24px auto;
  padding: 0 18px;
}

.view-panel {
  display: none;
  animation: fadeUp 0.2s ease;
}

.view-panel.active {
  display: block;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.12fr 0.88fr;
  gap: 22px;
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.card-title {
  margin: 0 0 4px;
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: -0.015em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.card-sub {
  margin: 0 0 18px;
  color: var(--ink-soft);
  font-size: 0.86rem;
}

/* Context Shelf Bar */
.shelf-banner {
  background: linear-gradient(135deg, #fffdf9, #f8f2e8);
  border: 1px solid #e7dccb;
  border-left: 5px solid var(--brand);
  border-radius: 16px;
  padding: 15px 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: end;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 170px;
}

.field label {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid #dfd7ca;
  border-radius: 12px;
  font-size: 0.93rem;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(27, 107, 99, 0.14);
}

/* Buttons */
.btn {
  border: none;
  border-radius: 12px;
  padding: 11px 17px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  text-decoration: none;
  transition: transform 0.1s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 4px 12px rgba(27, 107, 99, 0.22);
}

.btn-primary:hover {
  background: var(--brand-dark);
}

.btn-emerald {
  background: var(--emerald);
  color: #fff;
}

.btn-soft {
  background: var(--surface-soft);
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-soft:hover {
  background: #ebe3d6;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 0.8rem;
  border-radius: 9px;
}

/* Mode Switcher */
.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.mode-card {
  border: 1.5px solid var(--line);
  background: var(--bg);
  border-radius: 14px;
  padding: 13px 14px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.16s ease;
}

.mode-card.active {
  border-color: var(--brand);
  background: var(--brand-soft);
  box-shadow: 0 4px 14px rgba(27, 107, 99, 0.08);
}

.mode-card strong {
  display: block;
  font-size: 0.92rem;
  color: var(--ink);
}

.mode-card span {
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.demo-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px dashed var(--line);
}

.pill-demo {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 0.77rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

.pill-demo:hover {
  background: #fef3c7;
}

#camera-box {
  display: none;
  margin: 14px 0;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid var(--brand);
  background: #09090b;
}

#camera-box.open {
  display: block;
}

#qr-reader {
  width: 100%;
  min-height: 250px;
}

/* Catalogue & 3D Hardcover Book Cards */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  align-items: center;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink-soft);
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 0.81rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.14s ease;
}

.chip:hover {
  border-color: #d1c7b8;
  color: var(--ink);
}

.chip.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.chip.dys-chip.active {
  background: var(--dys);
  border-color: var(--dys);
  color: #fff;
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(225px, 1fr));
  gap: 20px;
}

@media (max-width: 540px) {
  .books-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
}

.book-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  cursor: pointer;
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}

/* Realistic 3D Book Cover Frame */
.book-cover-stage {
  height: 235px;
  background: linear-gradient(180deg, #f6f2eb 0%, #ece5da 100%);
  border-radius: 12px;
  padding: 14px 18px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 540px) {
  .book-cover-stage {
    height: 188px;
    padding: 10px 12px;
  }
}

.book-3d {
  width: 100%;
  max-width: 148px;
  height: 100%;
  border-radius: 4px 10px 10px 4px;
  overflow: hidden;
  position: relative;
  box-shadow: var(--shadow-book);
  background: #fff;
}

/* Reliure de livre réaliste */
.book-3d::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 12px;
  background: linear-gradient(90deg, rgba(0,0,0,0.28) 0%, rgba(255,255,255,0.22) 45%, rgba(0,0,0,0.08) 80%, transparent 100%);
  z-index: 3;
  pointer-events: none;
}

.book-3d img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.generated-cover {
  width: 100%;
  height: 100%;
  padding: 16px 13px 14px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: #fff;
  position: relative;
}

.generated-cover .gen-cat {
  font-size: 0.64rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  opacity: 0.85;
}

.generated-cover .gen-title {
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1.26;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.generated-cover .gen-author {
  font-size: 0.72rem;
  opacity: 0.88;
  border-top: 1px solid rgba(255, 255, 255, 0.24);
  padding-top: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cover-badges {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-between;
  z-index: 4;
  pointer-events: none;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
}

.tag-lang {
  background: rgba(24, 24, 27, 0.76);
  color: #fff;
  backdrop-filter: blur(6px);
}

.tag-avail {
  background: #dcfce7;
  color: #166534;
}

.tag-out {
  background: #fee2e2;
  color: #991b1b;
}

.tag-dys {
  background: var(--dys-soft);
  color: var(--dys);
}

.tag-shelf {
  background: var(--surface-soft);
  color: var(--ink-soft);
}

.book-body {
  padding: 12px 4px 2px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.book-title {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 800;
  line-height: 1.32;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-author {
  margin: 0;
  font-size: 0.79rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-meta-row {
  margin-top: auto;
  padding-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: space-between;
}

/* Rows & KPIs */
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.list-row:last-child {
  border-bottom: none;
}

.code-pill {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.74rem;
  font-weight: 800;
  background: var(--surface-soft);
  border: 1px solid #e2d9cb;
  padding: 2px 7px;
  border-radius: 6px;
  color: var(--ink);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.kpi-val {
  font-size: 2rem;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.kpi-lbl {
  font-size: 0.82rem;
  color: var(--ink-soft);
  font-weight: 600;
  margin-top: 6px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24, 24, 27, 0.55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  background: var(--surface);
  border-radius: 22px;
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.26);
}

.install-step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  margin-bottom: 10px;
}

.step-num {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  font-size: 0.8rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

/* Toast */
#toast {
  position: fixed;
  bottom: calc(86px + env(safe-area-inset-bottom, 0px));
  right: 20px;
  left: 20px;
  margin: 0 auto;
  max-width: 420px;
  background: #18181b;
  color: #fff;
  padding: 13px 18px;
  border-radius: 14px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  opacity: 0;
  pointer-events: none;
  transform: translateY(24px);
  transition: opacity 0.2s ease, transform 0.24s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 130;
}

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

#print-area {
  display: none;
}

@media print {
  body > *:not(#print-area) {
    display: none !important;
  }
  #print-area {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 8mm;
    background: #fff;
  }
  .print-label {
    border: 1px dashed #999;
    border-radius: 6px;
    padding: 8px 10px;
    text-align: center;
    page-break-inside: avoid;
  }
  .print-label strong {
    display: block;
    font-size: 10pt;
    margin-bottom: 2px;
  }
  .print-label small {
    display: block;
    font-size: 8pt;
    color: #444;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
  }
}
