/* ============================================================================
   Repository Module — Tenant View (tab in DeskControl portal)
   ============================================================================ */

/* ---- Layout a due colonne (sidebar + main file manager) ---- */
.portal-panel.active.repo-layout {
  display: flex !important;
  flex-direction: row !important;
  height: 100%;
  overflow: hidden;
}
.repo-sidebar {
  width: 340px;
  min-width: 340px;
  max-width: 340px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 14px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  height: 100%;
  box-sizing: border-box;
}
.repo-main {
  flex: 1 1 auto;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #f8fafc;
  min-height: 0;
  min-width: 0;
  height: 100%;
}

/* ---- Filtri ---- */
.repo-filters {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.repo-filters label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.repo-filters select,
.repo-filters input[type="date"] {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-main);
  background: #fff;
}
.repo-filters select:disabled {
  background: #f1f5f9;
  color: #94a3b8;
  cursor: not-allowed;
}
.repo-filters-row {
  display: flex;
  gap: 8px;
}
.repo-filter-reset {
  padding: 6px 10px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  align-self: flex-end;
}
.repo-filter-reset:hover {
  background: #e2e8f0;
}

/* ---- Target cartella corrente (dopo click nel tree) ---- */
.repo-current-target {
  padding: 10px 12px;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 6px;
  font-size: 12px;
  margin-bottom: 10px;
}
.repo-target-label {
  color: #92400e;
  font-weight: 500;
}
.repo-target-active {
  background: #dcfce7;
  border-color: #86efac;
}
.repo-target-active .repo-target-label {
  color: #166534;
  font-weight: 600;
}

/* ---- File manager: tree + list ---- */
.repo-fm-container {
  display: grid;
  grid-template-columns: 300px 1fr;
  flex: 1;
  min-height: 0;
  height: 100%;
}
.repo-fm-tree {
  background: #fff;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px;
  font-size: 13px;
}
.repo-fm-loading {
  color: #94a3b8;
  padding: 20px;
  text-align: center;
}
.repo-tree-node {
  display: block;
  padding: 4px 8px 4px 0;
  cursor: pointer;
  user-select: none;
  line-height: 1.5;
  color: #1e293b;
}
.repo-tree-node:hover {
  background: #f1f5f9;
}
.repo-tree-node.selected {
  background: #890103;
  color: #fff;
  border-radius: 4px;
}
.repo-tree-node.selected:hover {
  background: #730102;
}
.repo-tree-indent {
  display: inline-block;
  width: 14px;
  text-align: center;
  font-size: 10px;
  color: #94a3b8;
}
.repo-tree-icon {
  margin-right: 4px;
  font-size: 13px;
}
.repo-tree-children {
  margin-left: 16px;
  border-left: 1px dotted #e2e8f0;
  padding-left: 4px;
}

/* ---- File list (right pane) ---- */
.repo-fm-list {
  overflow-y: auto;
  background: #fff;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.repo-fm-breadcrumb {
  padding: 10px 16px;
  background: #f1f5f9;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: #475569;
  flex-shrink: 0;
}
.repo-fm-breadcrumb strong {
  color: #1e293b;
}
.repo-fm-toolbar {
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: #fff;
  flex-shrink: 0;
}
.repo-fm-btn {
  padding: 4px 12px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}
.repo-fm-btn:hover {
  background: #e2e8f0;
}
#repoFmFiles {
  padding: 8px 0;
  overflow-y: auto;
}

/* ---- Gallery (foto) ---- */
.repo-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  padding: 12px 16px;
}
.repo-gallery-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s;
}
.repo-gallery-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.repo-gallery-thumb {
  width: 100%;
  height: 160px;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
}
.repo-gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
}
.repo-thumb-loading, .repo-thumb-placeholder {
  font-size: 32px;
  color: #94a3b8;
}
.repo-gallery-name {
  padding: 6px 10px 2px;
  font-size: 12px;
  font-weight: 500;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.repo-gallery-meta {
  padding: 0 10px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: #64748b;
}
.repo-gallery-actions {
  display: flex;
  gap: 4px;
  padding: 6px 10px;
  border-top: 1px solid var(--border);
}
.repo-gallery-actions .repo-fm-btn {
  flex: 1;
  padding: 3px 6px;
  font-size: 12px;
}

/* ---- Preview modal ---- */
.repo-preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.repo-preview-modal {
  background: #fff;
  border-radius: 8px;
  max-width: 95vw;
  max-height: 95vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 400px;
  position: relative;
}
.repo-preview-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(15, 23, 42, 0.55);
  color: #fff;
  border: none;
  width: 48px;
  height: 64px;
  font-size: 36px;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  user-select: none;
  z-index: 2;
}
.repo-preview-nav:hover {
  background: rgba(15, 23, 42, 0.85);
}
.repo-preview-prev { left: 12px; }
.repo-preview-next { right: 12px; }
.repo-preview-counter {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.7);
  color: #fff;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  z-index: 2;
}
.repo-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}
.repo-preview-title {
  font-weight: 600;
  font-size: 14px;
  color: #1e293b;
  max-width: 70vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.repo-preview-close {
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #64748b;
  padding: 0 8px;
}
.repo-preview-close:hover {
  color: #dc2626;
}
.repo-preview-body {
  overflow: auto;
  background: #f1f5f9;
  padding: 12px;
  max-height: 85vh;
}
.repo-pdf-viewer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.repo-pdf-page {
  max-width: 100%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  border-radius: 4px;
}

/* ---- Body class override per tab Repository ---- */
body.portal-repository .portal-panel[data-portal="repository"] {
  padding: 0;
}

/* ---- Folder pills (legacy, nascoste in layout nuovo) ---- */
.repo-folder-pills {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.repo-folder-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 18px;
  font-size: 13px;
  font-weight: 500;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s;
}
.repo-folder-pill:hover {
  background: #e2e8f0;
  border-color: #94a3b8;
}
.repo-folder-pill.active {
  background: #890103;
  border-color: #890103;
  color: #fff;
}
.repo-folder-icon {
  font-size: 14px;
}

/* ---- Source badge (Cliente/Interno/Octopus/Tecnico) ---- */
.repo-source-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  margin-right: 8px;
}

/* ---- Layout ---- */
.repo-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 16px 20px;
  overflow-y: auto;
}

.repo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-shrink: 0;
}

.repo-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
}

/* ---- Perizia selector ---- */
.repo-perizia-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.repo-perizia-bar select {
  font-size: 13px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 200px;
}

/* ---- Sub-tabs (File / Token / Consegne / Audit) ---- */
.repo-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid #e5e7eb;
  margin-bottom: 16px;
  flex-shrink: 0;
}

.repo-tab-btn {
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  border-bottom: 3px solid transparent;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color .15s, border-color .15s;
}

.repo-tab-btn:hover {
  color: var(--text-main);
}

.repo-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.repo-tab-panel {
  display: none;
  flex: 1;
  overflow-y: auto;
}

.repo-tab-panel.active {
  display: block;
}

/* ---- File tree ---- */
.repo-zone-group {
  margin-bottom: 16px;
}

.repo-zone-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}

.repo-zone-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.repo-zone-badge.confidential { background: #dc2626; }
.repo-zone-badge.delivery { background: #2563eb; }
.repo-zone-badge.shared { background: #16a34a; }

.repo-file-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.repo-file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: background .1s;
}

.repo-file-item:hover {
  background: #f1f5f9;
}

.repo-file-name {
  flex: 1;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.repo-file-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.repo-file-actions {
  display: flex;
  gap: 4px;
}

.repo-file-actions button {
  font-size: 11px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  color: var(--text-secondary);
}

.repo-file-actions button:hover {
  background: #f1f5f9;
}

.repo-file-actions button.danger:hover {
  background: #fef2f2;
  color: #dc2626;
  border-color: #fca5a5;
}

/* ---- Upload drag & drop ---- */
.repo-dropzone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 32px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  transition: border-color .2s, background .2s;
  cursor: pointer;
  margin-bottom: 16px;
}

.repo-dropzone.dragover {
  border-color: var(--primary);
  background: rgba(137, 1, 3, .04);
  color: var(--primary);
}

.repo-dropzone input[type="file"] {
  display: none;
}

/* ---- Token management ---- */
.repo-token-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 10px;
  background: #fff;
}

.repo-token-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.repo-token-email {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}

.repo-token-status {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 10px;
}

.repo-token-status.pending { background: #fef3c7; color: #92400e; }
.repo-token-status.submitted { background: #dbeafe; color: #1e40af; }
.repo-token-status.validated { background: #dcfce7; color: #166534; }
.repo-token-status.rejected { background: #fee2e2; color: #991b1b; }
.repo-token-status.burned { background: #f3f4f6; color: #6b7280; }

.repo-token-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 16px;
  margin-bottom: 8px;
}

.repo-token-actions {
  display: flex;
  gap: 6px;
}

.repo-token-actions button {
  font-size: 11px;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
}

.repo-token-actions button.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.repo-token-actions button.danger {
  color: #dc2626;
  border-color: #fca5a5;
}

/* ---- Create token form ---- */
.repo-token-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafbfc;
}

.repo-token-form label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.repo-token-form input {
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.repo-token-form .full-width {
  grid-column: 1 / -1;
}

/* ---- Audit log table ---- */
.repo-audit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.repo-audit-table th {
  text-align: left;
  padding: 6px 8px;
  background: #f8fafc;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  color: var(--text-secondary);
}

.repo-audit-table td {
  padding: 5px 8px;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text-main);
}

.repo-audit-table tr:hover td {
  background: #f8fafc;
}

/* ---- Empty state ---- */
.repo-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ---- Notifications ---- */
.repo-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1e293b;
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 99999;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
  animation: repoFadeIn .3s ease;
}

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