/* =============================================
   SYNDIC APP - Mobile First CSS
   ============================================= */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Segoe UI', Tahoma, Arial, 'Helvetica Neue', sans-serif;
  background: #f0f4f8;
  color: #1e2d45;
  direction: rtl;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

/* ============ HEADER ============ */
.app-header {
  background: linear-gradient(135deg, #1e3a5f 0%, #2563a8 60%, #1d4ed8 100%);
  color: #fff;
  padding: 20px 16px 18px;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 3px 16px rgba(30,58,95,0.35);
}
.header-inner h1 {
  font-size: clamp(1.1rem, 4vw, 1.6rem);
  font-weight: 900;
  letter-spacing: 0.02em;
}
.header-sub {
  font-size: 0.82rem;
  opacity: 0.8;
  margin-top: 4px;
}
.header-sub strong { color: #ffd700; }

/* ============ CONTAINER ============ */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 12px 40px;
}

/* ============ SUMMARY CARDS ============ */
.summary-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

@media (min-width: 640px) {
  .summary-bar { grid-template-columns: repeat(4, 1fr); }
}

.card-stat {
  background: #fff;
  border-radius: 12px;
  padding: 14px 10px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  border-top: 4px solid #ccc;
}
.card-stat.blue  { border-top-color: #3498db; }
.card-stat.green { border-top-color: #27ae60; }
.card-stat.orange{ border-top-color: #e67e22; }
.card-stat.purple{ border-top-color: #9b59b6; }

.stat-label { display: block; font-size: 0.72rem; color: #888; margin-bottom: 4px; font-weight: 600; }
.stat-val   { display: block; font-size: 1.35rem; font-weight: 900; color: #1a1a2e; }

/* ============ PROGRESS ============ */
.progress-wrap { margin-bottom: 16px; }
.progress-bar-bg {
  background: #dce3ed;
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #27ae60, #2ecc71);
  border-radius: 999px;
  transition: width 0.5s ease;
  width: 0%;
}

/* ============ TOOLBAR ============ */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
  align-items: center;
}
.toolbar-left  { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; }
.toolbar-right { flex: 1; min-width: 180px; }

.toolbar-right input[type="search"] {
  width: 100%;
  padding: 9px 14px;
  border: 1.5px solid #c8d6e5;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.9rem;
  direction: rtl;
  background: #fff;
}
.toolbar-right input:focus { outline: none; border-color: #3498db; }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 9px 16px;
  border: none;
  border-radius: 10px;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s, opacity 0.15s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover   { opacity: 0.88; transform: translateY(-1px); }
.btn:active  { transform: scale(0.96); }

.btn-add    { background: #27ae60; color: #fff; }
.btn-import { background: #8e44ad; color: #fff; }
.btn-export { background: #2980b9; color: #fff; }
.btn-print  { background: #7f8c8d; color: #fff; }
.btn-cancel { background: #e0e0e0; color: #333; }
.btn-delete { background: #e74c3c; color: #fff; }

.btn-edit-sm { background: #f39c12; color: #fff; padding: 6px 12px; font-size: 0.78rem; border-radius: 8px; border: none; cursor: pointer; font-family: inherit; font-weight: 700; }
.btn-del-sm  { background: #e74c3c; color: #fff; padding: 6px 12px; font-size: 0.78rem; border-radius: 8px; border: none; cursor: pointer; font-family: inherit; font-weight: 700; }

.btn-add-owner {
  background: #ecf0f1;
  color: #2c3e50;
  border: 2px dashed #bdc3c7;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 0.82rem;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
  width: 100%;
}
.btn-add-owner:hover { background: #dfe6e9; }

/* ============ DESKTOP TABLE ============ */
.desktop-only { display: none; }

@media (min-width: 900px) {
  .desktop-only { display: block; }
}

.table-wrapper {
  overflow-x: auto;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.09);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
  min-width: 1000px;
}

thead tr {
  background: linear-gradient(135deg, #1e3a5f 0%, #2563a8 100%);
  color: #fff;
}

thead th {
  padding: 13px 8px;
  text-align: center;
  font-weight: 700;
  border: 1px solid #1a3460;
  font-size: 0.78rem;
  line-height: 1.4;
  letter-spacing: 0.01em;
}

/* Row color logic - modern palette */
tbody tr.row-main { background: #f0f5ff; }
tbody tr.row-sub  { background: #dde8f7; }
tbody tr.row-main:hover { background: #e2ecff; }
tbody tr.row-sub:hover  { background: #cfdff5; }

tbody td {
  padding: 8px 8px;
  text-align: center;
  border: 1px solid #d0dae8;
  vertical-align: middle;
  font-size: 0.83rem;
}

td.parts-cell { font-weight: 800; color: #1e3a8a; }

.action-btns { display: flex; gap: 5px; justify-content: center; flex-wrap: wrap; }

/* ============ MOBILE CARDS ============ */
.mobile-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.unit-card {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  overflow: hidden;
}

.unit-card-header {
  background: #1a1a2e;
  color: #fff;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.unit-card-header .rank-badge {
  background: #ffd700;
  color: #1a1a2e;
  font-weight: 900;
  border-radius: 8px;
  padding: 3px 10px;
  font-size: 0.9rem;
}
.unit-card-header .parts-badge {
  background: #e74c3c;
  color: #fff;
  font-weight: 700;
  border-radius: 8px;
  padding: 3px 10px;
  font-size: 0.85rem;
}
.unit-card-header .card-actions { display: flex; gap: 6px; }

.unit-card-body { padding: 12px 14px; }

.owners-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.owner-chip {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 700;
}
.owner-chip.main { background: #fff176; color: #7b6000; border: 1px solid #f9a825; }
.owner-chip.sub  { background: #b8cce4; color: #1a237e; border: 1px solid #7986cb; }

.card-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  font-size: 0.8rem;
}

.card-field { display: flex; flex-direction: column; gap: 1px; }
.card-field .cf-label { color: #888; font-size: 0.7rem; font-weight: 600; }
.card-field .cf-val   { color: #1a1a2e; font-weight: 600; word-break: break-all; }
.card-field.full { grid-column: 1/-1; }

/* ============ MODAL ============ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

@media (min-width: 600px) {
  .modal-overlay { align-items: center; padding: 16px; }
}

.modal-overlay.active { display: flex; }

.modal-box {
  background: #fff;
  width: 100%;
  max-width: 600px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 30px rgba(0,0,0,0.2);
  direction: rtl;
  animation: slideUp 0.25s ease;
}

@media (min-width: 600px) {
  .modal-box { border-radius: 16px; animation: fadeIn 0.2s ease; }
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
@keyframes fadeIn {
  from { transform: scale(0.95); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.modal-sm { max-width: 380px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid #eee;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}
.modal-header h2 { font-size: 1.05rem; font-weight: 800; color: #1a1a2e; }
.modal-close {
  background: #f0f0f0;
  border: none;
  border-radius: 50%;
  width: 32px; height: 32px;
  font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-family: inherit;
}
.modal-close:hover { background: #e0e0e0; }

form { padding: 16px 18px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}
.form-group.full { grid-column: 1/-1; }

.form-group label {
  font-size: 0.8rem;
  font-weight: 700;
  color: #555;
}
.form-group label .hint { font-weight: 400; color: #999; font-size: 0.72rem; }

.form-group input,
.form-group textarea,
.form-group select {
  padding: 10px 12px;
  border: 1.5px solid #d0dae8;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.88rem;
  direction: rtl;
  transition: border-color 0.15s;
  background: #fff;
  -webkit-appearance: none;
}
.form-group input:focus,
.form-group textarea:focus { outline: none; border-color: #3498db; box-shadow: 0 0 0 3px rgba(52,152,219,0.1); }

/* Owner fields */
.owner-field-row {
  background: #f8faff;
  border: 1px solid #dde8f7;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.owner-fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: center;
}
.owner-fields-grid .owner-name { grid-column: 1 / 2; }
.owner-fields-grid .owner-cin  { grid-column: 2 / 3; }
.owner-fields-grid .owner-address { grid-column: 1 / 3; }
.owner-fields-grid .owner-email   { grid-column: 1 / 2; }
.owner-fields-grid .owner-phone   { grid-column: 2 / 3; }
.owner-fields-grid .remove-owner-btn { grid-column: 2 / 3; justify-self: end; margin-top: 2px; }
.remove-owner-btn {
  background: #fde8e8;
  color: #e74c3c;
  border: none;
  border-radius: 8px;
  width: 34px; height: 34px;
  font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.remove-owner-btn:hover { background: #fcc; }

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 18px;
  border-top: 1px solid #eee;
  position: sticky;
  bottom: 0;
  background: #fff;
}

.confirm-msg { padding: 16px 18px; color: #555; line-height: 1.6; font-size: 0.9rem; }

/* ============ HINT TEXT ============ */
.hint-text {
  text-align: center;
  font-size: 0.75rem;
  color: #999;
  margin-top: 12px;
}

/* ============ DRAG & DROP ============ */
.col-drag {
  width: 32px;
  padding: 8px 6px !important;
  color: rgba(255,255,255,0.6);
  font-size: 1.1rem;
  letter-spacing: 1px;
  user-select: none;
}

td.drag-handle {
  width: 32px;
  padding: 6px !important;
  text-align: center;
  cursor: grab;
  color: #b0bec5;
  font-size: 1.2rem;
  vertical-align: middle;
  transition: color 0.15s;
}
td.drag-handle:hover { color: #2563a8; }
td.drag-handle:active { cursor: grabbing; }

.drag-icon {
  display: inline-block;
  line-height: 1;
  user-select: none;
  pointer-events: none;
}

tbody tr.dragging {
  opacity: 0.4;
  background: #d1e3ff !important;
}

tbody tr.drag-over td {
  background: #bfdbfe !important;
  border-top: 2px solid #2563a8 !important;
}
tfoot .tfoot-empty {
  background: #f8faff;
  border: 1px solid #d0dae8;
}
tfoot tr td {
  border: 1px solid #c5d5ea;
  padding: 10px 16px;
}
tfoot .tfoot-total {
  background: linear-gradient(90deg, #f8faff, #e8f0fb);
}
tfoot .tfoot-remaining {
  background: linear-gradient(90deg, #f8faff, #eef6ff);
}
tfoot .tfoot-label {
  font-weight: 800;
  font-size: 0.9rem;
  color: #1e3a5f;
  white-space: nowrap;
  text-align: right;
}
tfoot .tfoot-val {
  font-weight: 900;
  font-size: 1rem;
  color: #c0392b;
  white-space: nowrap;
  text-align: right;
  min-width: 110px;
}

/* ============ LIMIT BANNER ============ */
.limit-banner {
  background: #fff3cd;
  color: #856404;
  border: 1.5px solid #ffc107;
  border-radius: 10px;
  padding: 11px 16px;
  margin-bottom: 14px;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
}

/* ============ PAGINATION ============ */
.pagination-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 18px;
  padding-bottom: 20px;
}

.page-info {
  font-size: 0.82rem;
  color: #666;
  font-weight: 600;
  margin: 0 8px;
  white-space: nowrap;
  width: 100%;
  text-align: center;
  margin-bottom: 4px;
}

.btn-page {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border: 1.5px solid #d0dae8;
  background: #fff;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  color: #1a1a2e;
  transition: background 0.12s, border-color 0.12s;
}
.btn-page:hover:not(:disabled) { background: #eef2f7; border-color: #3498db; }
.btn-page.active { background: #1a1a2e; color: #fff; border-color: #1a1a2e; }
.btn-page:disabled { opacity: 0.35; cursor: not-allowed; }

.page-dots {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 4px;
  font-size: 1rem;
  color: #999;
}

/* ============ PRINT ============ */
@media print {
  .toolbar, .summary-bar, .progress-wrap,
  .action-btns, .btn, .modal-overlay,
  .limit-banner, .pagination-wrap, .app-header { display: none !important; }
  body { background: #fff; font-size: 11px; }
  .table-wrapper { box-shadow: none; }
  .desktop-only { display: block !important; }
}

/* ============ PRINT MODAL CHECKLIST ============ */
.print-cols-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 20px;
  padding: 16px 8px;
}
.print-col-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 6px;
  transition: background 0.1s;
}
.print-col-check:hover { background: #f0f4f8; }
.print-col-check input[type=checkbox] {
  width: 16px;
  height: 16px;
  accent-color: #1e3a5f;
  cursor: pointer;
}
.print-col-check input[disabled] { opacity: 0.4; cursor: not-allowed; }

/* ============ CONTRIB COLUMN ============ */
.col-contrib { min-width: 120px; }
#mainTable td.col-contrib { white-space: pre-wrap; word-break: break-word; }
