/* ================================
   PDF Organize Tool
================================ */

/* ================================
   Navigation
================================ */

.desktop-nav,
.mobile-nav{
    display:none;
}

.tool-wrapper.processing .desktop-nav,
.tool-wrapper.processing .mobile-nav{
    display:flex;
}

@media (min-width:769px){

    .tool-wrapper.processing .desktop-nav{
        display:flex;
        justify-content:center;
        align-items:center;
        gap:10px;
        margin:15px auto;
    }

    .mobile-nav{
        display:none !important;
    }
}

@media (max-width:768px){

    .desktop-nav{
        display:none !important;
    }

    .mobile-nav{
        display:none !important;
    }
}

/* ================================
   RTL Fix
================================ */

.pages-list{
    direction:ltr;
}

[dir="rtl"] .page-card{
    direction:rtl;
}

/* ================================
   Hide By Default
================================ */

.tool-wrapper [data-role="toolbar"],
.tool-wrapper [data-role="pages-container"],
.tool-wrapper [data-role="actions"]{
    display:none;
}

/* ================================
   Main Container
================================ */

.tool-wrapper{
    max-width:1400px;
    margin:0 auto;
}

/* ================================
   Toolbar
================================ */

.toolbar{
    display:flex;
    align-items:center;
    justify-content:center;
    gap:12px;
    flex-wrap:wrap;
    margin:20px auto;
    max-width:1200px;
}

.toolbar-left,
.toolbar-center,
.toolbar-right{
    display:flex;
    align-items:center;
    justify-content:center;
    gap:8px;
    flex-wrap:wrap;
}

.toolbar-right{
    margin-left:0;
}

.toolbar-group{
    display:flex;
    align-items:center;
    justify-content:center;
    gap:8px;
    flex-wrap:wrap;
}

.toolbar *{
    flex-shrink:0;
}

.toolbar-left label{
    display:flex;
    align-items:center;
    gap:6px;
}

.btn-toolbar{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    gap:6px;

    min-height:40px;
    padding:8px 14px;

    border:none;
    border-radius:10px;

    background:#f1f5f9;

    cursor:pointer;

    font-size:14px;
    font-weight:500;

    transition:.2s;
}

.btn-toolbar:hover{
    transform:translateY(-1px);
}

.btn-toolbar.primary{
    background:#0C7CA8;
    color:#fff;
}

.btn-toolbar.danger{
    background:#ef4444;
    color:#fff;
}

/* ================================
   Counter
================================ */

.selection-counter{
    background:#0C7CA8;
    color:#fff;

    padding:6px 14px;

    border-radius:999px;

    font-size:13px;
    font-weight:600;
}

/* ================================
   Pages Grid
================================ */

.tool-wrapper .pages-list{
    display:grid;
    grid-template-columns:repeat(auto-fit,minmax(220px,220px));
    justify-content:center;
    gap:18px;

    width:100%;

    margin:20px auto;
}

/* ================================
   Page Card
================================ */

.tool-wrapper .page-card{
    width:220px;

    background:#fff;

    border:1px solid #e5e7eb;
    border-radius:12px;

    overflow:hidden;

    position:relative;

    box-shadow:0 2px 8px rgba(0,0,0,.05);

    transition:.2s;
}

.tool-wrapper .page-card:hover{
    transform:translateY(-3px);
    box-shadow:0 10px 25px rgba(0,0,0,.1);
}

.tool-wrapper .page-card.dragging{
    opacity:.6;
    transform:rotate(1deg) scale(.98);
}

.tool-wrapper .page-card.selected{
    border:2px solid #0C7CA8;
}

.page-card::after{
    content:"🔍";
    position:absolute;
    top:8px;
    right:8px;
    opacity:.65;
    font-size:14px;
}

/* ================================
   Page Number
================================ */

.page-number{
    position:absolute;
    top:8px;
    left:8px;

    width:28px;
    height:28px;

    display:flex;
    align-items:center;
    justify-content:center;

    background:#0C7CA8;
    color:#fff;

    border-radius:50%;

    font-size:12px;
    font-weight:700;

    z-index:2;
}

.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: #f8f9fa;
  border-radius: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

.top-nav-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-nav-group .nav-btn {
  padding: 6px 12px;
  border: 1px solid #dee2e6;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.top-nav-group .nav-btn:hover:not(:disabled) {
  background: #e9ecef;
}

.top-nav-group .nav-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.top-nav-group .nav-btn i {
  font-size: 14px;
}

.top-nav-go-to {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-nav-go-to input {
  width: 60px;
  padding: 6px 8px;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  text-align: center;
}

.top-nav-go-to .go-btn {
  padding: 6px 16px;
  background: #0d6efd;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

.top-nav-go-to .go-btn:hover {
  background: #0b5ed7;
}

.top-nav-go-to .total-pages {
  color: #6c757d;
  font-size: 14px;
}

@media (max-width: 768px) {
  .top-nav {
    display: none !important;
  }
}

.page-card.highlighted {
  border: 3px solid #0d6efd !important;
  box-shadow: 0 0 20px rgba(13, 110, 253, 0.5) !important;
  transform: scale(1.02);
  transition: all 0.3s ease;
  z-index: 10;
  position: relative;
}

.page-card.highlighted .page-number {
  background: #0d6efd;
  color: white;
  font-weight: bold;
}

@keyframes highlightPulse {
  0% { box-shadow: 0 0 0 0 rgba(13, 110, 253, 0.4); }
  70% { box-shadow: 0 0 0 15px rgba(13, 110, 253, 0); }
  100% { box-shadow: 0 0 0 0 rgba(13, 110, 253, 0); }
}

.page-card.highlighted {
  animation: highlightPulse 1.5s ease-out 3;
}


/* ============================================================ */
/* نافذة إضافة صفحات فارغة                                      */
/* ============================================================ */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 10000;
  display: none;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.3s ease-out;
}

.modal-overlay.active {
  display: flex;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translateY(30px) scale(0.95);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.modal-content {
  background: #ffffff;
  border-radius: 16px;
  padding: 0;
  max-width: 520px;
  width: 92%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.3s ease-out;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid #e9ecef;
  background: #f8f9fa;
  border-radius: 16px 16px 0 0;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.2rem;
  color: #1a1a2e;
  font-weight: 600;
}

.modal-header h3 i {
  color: #0d6efd;
  margin-right: 8px;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 28px;
  line-height: 1;
  color: #6c757d;
  cursor: pointer;
  padding: 0 4px;
  transition: color 0.2s;
}

.modal-close-btn:hover {
  color: #dc3545;
}

.modal-body {
  padding: 24px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  color: #333;
  font-size: 0.9rem;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: white;
}

.form-input:focus {
  outline: none;
  border-color: #0d6efd;
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.form-group small {
  display: block;
  margin-top: 4px;
  color: #6c757d;
  font-size: 0.8rem;
}

/* ===== ألوان الصفحات ===== */
.color-picker-wrapper {
  border: 2px solid #e9ecef;
  border-radius: 10px;
  padding: 16px;
  background: #fafbfc;
  transition: border-color 0.2s;
}

.color-picker-wrapper:focus-within {
  border-color: #0d6efd;
}

.color-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.color-option {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
  padding: 0;
  position: relative;
  flex-shrink: 0;
}

.color-option:hover {
  transform: scale(1.15);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  z-index: 2;
}

.color-option.selected {
  border-color: #0d6efd;
  transform: scale(1.1);
  box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px #0d6efd;
  z-index: 3;
}

.color-option.selected::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 14px;
  color: #0d6efd;
  font-weight: bold;
  text-shadow: 0 0 4px white;
}

.custom-color {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid #e9ecef;
}

.color-input {
  width: 44px;
  height: 44px;
  padding: 2px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  cursor: pointer;
  background: white;
  flex-shrink: 0;
}

.color-input:hover {
  border-color: #0d6efd;
}

.color-input::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.color-input::-webkit-color-swatch {
  border-radius: 4px;
  border: none;
}

.custom-color span {
  font-size: 0.85rem;
  color: #6c757d;
}

.color-preview-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid #e9ecef;
}

.color-preview-wrapper span {
  font-size: 0.85rem;
  color: #6c757d;
  font-weight: 500;
}

.color-preview {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  border: 2px solid #dee2e6;
  transition: background-color 0.3s, border-color 0.3s;
  flex-shrink: 0;
}

/* ===== أزرار النافذة ===== */
.modal-actions {
  display: flex;
  gap: 12px;
  padding: 16px 24px 24px;
  border-top: 1px solid #e9ecef;
  justify-content: flex-end;
  background: #f8f9fa;
  border-radius: 0 0 16px 16px;
}

.btn-secondary {
  padding: 10px 24px;
  background: #e9ecef;
  color: #495057;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-secondary:hover {
  background: #dee2e6;
  transform: translateY(-1px);
}

.btn-secondary:active {
  transform: translateY(0);
}

.btn-primary {
  padding: 10px 28px;
  background: #0d6efd;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-primary:hover {
  background: #0b5ed7;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(13, 110, 253, 0.3);
}

.btn-primary:active {
  transform: translateY(0);
}

/* ===== استجابة للشاشات الصغيرة ===== */
@media (max-width: 576px) {
  .modal-content {
    width: 95%;
    border-radius: 12px;
  }
  
  .modal-header {
    padding: 16px 20px;
  }
  
  .modal-header h3 {
    font-size: 1rem;
  }
  
  .modal-body {
    padding: 16px 20px;
  }
  
  .color-options {
    grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
    gap: 6px;
  }
  
  .color-option {
    width: 34px;
    height: 34px;
  }
  
  .modal-actions {
    flex-direction: column-reverse;
    padding: 12px 20px 20px;
  }
  
  .modal-actions button {
    width: 100%;
    justify-content: center;
    padding: 12px;
  }
  
  .color-preview {
    width: 40px;
    height: 40px;
  }
}
/* ================================
   Canvas
================================ */

.page-canvas{
    width:100%;
    display:block;
    background:#f8fafc;
}

/* ================================
   Zoom Preview
================================ */

.page-zoom-overlay{
    position:fixed;
    inset:0;

    background:rgba(0,0,0,.85);

    display:flex;
    align-items:center;
    justify-content:center;

    z-index:9999;

    cursor:zoom-out;
}

.page-zoom-overlay canvas{
    max-width:90vw;
    max-height:90vh;

    background:#fff;

    border-radius:10px;

    box-shadow:0 30px 80px rgba(0,0,0,.35);
}

/* ================================
   Loading
================================ */

.tool-wrapper [data-role="loading"]{
    display:none;
    text-align:center;
    margin:20px 0;
    color:#0C7CA8;
}

.tool-wrapper [data-role="loading"] i{
    animation:spin 1s linear infinite;
}

@keyframes spin{
    from{
        transform:rotate(0deg);
    }
    to{
        transform:rotate(360deg);
    }
}

/* ================================
   Mobile
================================ */

@media (max-width:768px){

    .tool-wrapper{
        padding:0 10px;
    }

    .toolbar{
        flex-direction:column;
        align-items:center;
        gap:10px;
    }

    .toolbar-left,
    .toolbar-center,
    .toolbar-right{
        width:100%;
        justify-content:center;
        flex-wrap:wrap;
    }

    .toolbar-group{
        justify-content:center;
    }

    .btn-toolbar{
        min-width:120px;
    }

    .selection-counter{
        width:auto;
    }

    .tool-wrapper .pages-list{
        display:grid;
        grid-template-columns:repeat(auto-fit,minmax(160px,160px));
        justify-content:center;
        gap:12px;
    }

    .tool-wrapper .page-card{
        width:160px;
    }
}

