/* ==========================================================
   PHASE 3 — Portfolio Management
   ========================================================== */

/* ---------- Sub-nav (Projects / Page Content) ---------- */
.portfolio-subnav {
  display: flex;
  gap: 4px;
  border-bottom: 1.5px solid var(--border);
  margin-bottom: 24px;
}

.portfolio-subnav-item {
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1.5px;
  transition: color var(--transition), border-color var(--transition);
}

.portfolio-subnav-item:hover { color: var(--text); }

.portfolio-subnav-item.is-active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ---------- Toolbar ---------- */
.portfolio-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.search-field {
  position: relative;
  flex: 1;
  min-width: 240px;
  max-width: 420px;
}

.search-field svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search-field input {
  width: 100%;
  padding: 11px 14px 11px 40px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-light);
}

.filter-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-select {
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--transition);
}

.filter-select:hover { border-color: var(--primary); }
.filter-select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-light); }

/* ---------- Loading skeleton ---------- */
.portfolio-skeleton { display: none; flex-direction: column; gap: 10px; }
.portfolio-skeleton.visible { display: flex; }

.skeleton-row {
  height: 68px;
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, var(--border) 25%, #F3F0FA 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

/* ---------- Empty / no-results states ---------- */
.portfolio-empty {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 64px 20px;
  color: var(--muted);
  text-align: center;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.portfolio-empty.visible { display: flex; }
.portfolio-empty svg { color: var(--border); }
.portfolio-empty p { font-size: 15px; font-weight: 500; }

/* ---------- Table (desktop) ---------- */
.portfolio-table-wrap {
  display: none;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.portfolio-table-wrap.visible { display: block; }

.portfolio-table {
  width: 100%;
  border-collapse: collapse;
}

.portfolio-table thead th {
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  white-space: nowrap;
}

.portfolio-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.portfolio-table tbody tr:last-child { border-bottom: none; }
.portfolio-table tbody tr:hover { background: var(--surface); }

.portfolio-table td {
  padding: 14px 18px;
  font-size: 14px;
  vertical-align: middle;
}

.col-image { min-width: 260px; }
.col-actions { text-align: right; white-space: nowrap; }

.project-cell {
  display: flex;
  align-items: center;
  gap: 12px;
}

.project-thumb {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--surface);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.project-thumb-placeholder {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.project-title-text {
  font-weight: 700;
  color: var(--text);
}

.project-slug-text {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.cell-muted { color: var(--muted); }

/* ---------- Status / featured badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 999px;
}

.badge-published { background: #E9F8F1; color: var(--success); }
.badge-draft { background: var(--border); color: var(--muted); }

.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.featured-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
}

.featured-toggle:hover { background: var(--primary-light); }
.featured-toggle.is-featured { color: #B8860B; }
.featured-toggle svg { width: 16px; height: 16px; }

/* ---------- Order input ---------- */
.order-input {
  width: 56px;
  padding: 6px 8px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  text-align: center;
}

.order-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

/* ---------- Action buttons (table) ---------- */
.row-actions {
  display: inline-flex;
  gap: 6px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--muted);
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.icon-btn:hover { border-color: var(--primary); color: var(--primary-dark); background: var(--primary-light); }
.icon-btn.icon-btn-danger:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-light); }
.icon-btn svg { width: 16px; height: 16px; }

.status-toggle-btn {
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--text);
  transition: background var(--transition), border-color var(--transition);
}

.status-toggle-btn:hover { border-color: var(--primary); color: var(--primary-dark); }

/* ---------- Mobile cards ---------- */
.portfolio-cards {
  display: none;
  flex-direction: column;
  gap: 14px;
}

.portfolio-cards.visible { display: flex; }

.portfolio-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
  padding: 16px;
}

.portfolio-card-top {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.portfolio-card-thumb {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--surface);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.portfolio-card-thumb-placeholder {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.portfolio-card-body { flex: 1; min-width: 0; }
.portfolio-card-title { font-weight: 700; font-size: 15px; color: var(--text); }
.portfolio-card-meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }

.portfolio-card-badges {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.portfolio-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.portfolio-card-order {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------- Drawer (Add/Edit Project) ---------- */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(23, 21, 31, 0.45);
  z-index: 60;
}

.drawer-overlay.visible { display: block; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100vw;
  background: var(--white);
  z-index: 70;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition);
  box-shadow: -24px 0 70px rgba(70, 45, 120, 0.15);
}

.drawer.visible { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.drawer-header h2 { font-size: 18px; }

.drawer-close {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 6px;
  border-radius: 8px;
  transition: background var(--transition), color var(--transition);
}

.drawer-close:hover { background: var(--surface); color: var(--text); }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 22px 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.drawer-body .field textarea,
.drawer-body .field select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  font-family: inherit;
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
  resize: vertical;
}

.drawer-body .field input[type="text"],
.drawer-body .field input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.drawer-body .field input:focus,
.drawer-body .field textarea:focus,
.drawer-body .field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-light);
}

.drawer-body .field input[aria-invalid="true"],
.drawer-body .field textarea[aria-invalid="true"],
.drawer-body .field select[aria-invalid="true"] {
  border-color: var(--danger);
}

.required-mark { color: var(--danger); }

.char-count {
  font-size: 11.5px;
  color: var(--muted);
  text-align: right;
}

.field-hint {
  font-size: 12.5px;
  color: var(--muted);
}

.drawer-form-error {
  display: none;
  font-size: 13.5px;
  color: var(--danger);
  background: var(--danger-light);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
}

.drawer-form-error.visible { display: block; }

/* ---- Image upload ---- */
.image-upload {
  position: relative;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  background: var(--surface);
  overflow: hidden;
}

.image-upload:hover { border-color: var(--primary); }
.image-upload.drag-over { border-color: var(--primary); background: var(--primary-light); }

.image-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 20px;
}

.image-uploading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13.5px;
  padding: 20px;
}

.image-preview-wrap {
  position: relative;
  width: 100%;
}

.image-preview-wrap img,
.image-preview-wrap video {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  display: block;
  background: #000;
}

/* ---- Media source toggle (Upload file / Paste URL) ---- */
.media-source-toggle {
  display: inline-flex;
  gap: 6px;
  margin-bottom: 8px;
}

.media-source-btn {
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}

.media-source-btn:hover { border-color: var(--primary); color: var(--text); }

.media-source-btn.is-active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.image-remove-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(23, 21, 31, 0.65);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}

.image-remove-btn:hover { background: rgba(23, 21, 31, 0.85); }

/* ---- Services chip input ---- */
.chip-input {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.chip-input:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-light);
}

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

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 6px 5px 11px;
  border-radius: 999px;
}

.chip-remove {
  background: transparent;
  border: none;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
}

.chip-remove:hover { background: rgba(109, 61, 245, 0.18); }

.chip-input input {
  flex: 1;
  min-width: 120px;
  border: none;
  outline: none;
  font-size: 13.5px;
  padding: 4px;
  background: transparent;
}

/* ---- Form section dividers (Phase 6 admin fields: Primary Media,
   Case Study Content, Results, Media Gallery, Testimonial) ---- */
.form-section-divider {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 8px 0 -6px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.form-section-divider span:first-child {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text);
}

.form-section-hint {
  font-size: 12px;
  color: var(--muted);
}

/* ---- Repeaters (Results / Media Gallery) ---- */
.repeater {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.repeater-empty {
  font-size: 13px;
  color: var(--muted);
  padding: 10px 2px;
}

.repeater-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.repeater-row-fields {
  flex: 1;
  display: grid;
  gap: 8px;
}

.repeater-row-fields.results-fields {
  grid-template-columns: 1fr 1fr;
}

.repeater-row-fields.results-fields .repeater-field-full {
  grid-column: 1 / -1;
}

.repeater-row-fields.gallery-fields {
  grid-template-columns: 100px 1fr;
}

.repeater-row-fields.gallery-fields .repeater-field-full {
  grid-column: 1 / -1;
}

/* ---- Phase 11 — gallery image row: upload button + file name ---- */
.gallery-image-source {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
}

.gallery-image-source .btn-repeater-upload {
  flex-shrink: 0;
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
}

.gallery-image-source .btn-repeater-upload:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.gallery-file-name {
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.repeater-row input,
.repeater-row select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}

.repeater-row input:focus,
.repeater-row select:focus {
  outline: none;
  border-color: var(--primary);
}

.repeater-row-remove {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.repeater-row-remove:hover {
  color: #d9534f;
  border-color: #d9534f;
  background: rgba(217, 83, 79, 0.06);
}

.btn-repeater-add {
  align-self: flex-start;
}

/* ---- Toggles ---- */
.toggle-row {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius-md);
}

.toggle-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toggle-field label { display: flex; flex-direction: column; gap: 2px; cursor: default; }
.toggle-field label span:first-child { font-size: 14px; font-weight: 600; color: var(--text); }
.toggle-hint { font-size: 12px; color: var(--muted); }

.switch {
  position: relative;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  border: none;
  background: var(--border);
  flex-shrink: 0;
  transition: background var(--transition);
}

.switch[aria-checked="true"] { background: var(--primary); }

.switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform var(--transition);
}

.switch[aria-checked="true"] .switch-knob { transform: translateX(18px); }

.drawer-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 18px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ---------- Delete confirmation modal ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(23, 21, 31, 0.5);
  z-index: 80;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

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

.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-hover);
}

.modal h3 { font-size: 18px; margin-bottom: 10px; }
.modal p { font-size: 14px; color: var(--muted); line-height: 1.55; margin-bottom: 22px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-danger {
  background: var(--danger);
  color: var(--white);
  box-shadow: none;
}

.btn-danger:hover:not(:disabled) { background: #B82A4B; }
.btn-danger:disabled { opacity: 0.7; cursor: not-allowed; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .portfolio-table-wrap.visible { display: none; }
  .portfolio-cards.visible { display: flex; }
}

@media (min-width: 901px) {
  .portfolio-cards { display: none !important; }
}

@media (max-width: 620px) {
  .portfolio-toolbar { flex-direction: column; align-items: stretch; }
  .search-field { max-width: none; }
  .filter-group { justify-content: stretch; }
  .filter-select { flex: 1; }
  .drawer { width: 100vw; }
}
