/* =============================================
   IFC Tools — Dashboard Styles
   ============================================= */

/* ── Layout ── */
.dashboard-body {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-subtle);
}

/* ── Sidebar ── */
.sidebar {
  width: 256px;
  flex-shrink: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  transition: transform 0.25s ease;
}

.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 8px 10px 4px;
  margin-top: 4px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
  text-decoration: none;
}
.sidebar-item:hover { background: var(--bg-subtle); color: var(--text-primary); }
.sidebar-item.active { background: var(--accent-light); color: var(--accent); font-weight: 600; }
.sidebar-item.active svg { stroke: var(--accent); }

.sidebar-item-soon { opacity: 0.6; cursor: default; pointer-events: none; }

.sidebar-badge {
  margin-left: auto;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}

.sidebar-soon-badge {
  margin-left: auto;
  font-size: 0.68rem !important;
  padding: 2px 6px !important;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.sidebar-plan-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
}

.plan-info { display: flex; flex-direction: column; gap: 10px; }

.plan-usage {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.plan-usage-bar {
  height: 5px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.plan-usage-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.6s ease;
}

.plan-usage-text {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ── Dashboard Main ── */
.dashboard-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Top Bar ── */
.topbar {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
}
.breadcrumb-home { color: var(--text-muted); }
.breadcrumb-sep  { color: var(--border); }
.breadcrumb-current { font-weight: 600; color: var(--text-primary); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  transition: border-color var(--transition);
}
.topbar-search:focus-within { border-color: var(--accent); background: var(--bg); }
.topbar-search svg { color: var(--text-muted); flex-shrink: 0; }
.topbar-search input {
  background: none;
  border: none;
  outline: none;
  font-family: var(--font);
  font-size: 0.88rem;
  color: var(--text-primary);
  width: 180px;
}
.topbar-search input::placeholder { color: var(--text-muted); }

.topbar-icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}

.topbar-menu-btn { display: none; }

/* User Menu */
.user-menu { position: relative; }

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color var(--transition);
  overflow: hidden;
  /* If avatar is an image: */
  object-fit: cover;
}
.user-avatar:hover { border-color: var(--accent); }
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }

.user-avatar-lg {
  width: 48px;
  height: 48px;
  font-size: 1rem;
  flex-shrink: 0;
}

.user-menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 240px;
  z-index: 200;
  animation: scaleIn 0.15s ease;
}
.user-menu-dropdown.hidden { display: none; }

.user-menu-header {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-name  { font-weight: 600; font-size: 0.92rem; }
.user-email { color: var(--text-muted); font-size: 0.8rem; }

.dropdown-divider { height: 1px; background: var(--border); }

.dropdown-item {
  display: block;
  width: 100%;
  padding: 10px 16px;
  font-size: 0.88rem;
  color: var(--text-secondary);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition);
}
.dropdown-item:hover { background: var(--bg-subtle); color: var(--text-primary); }
.dropdown-item-danger { color: var(--danger) !important; }
.dropdown-item-danger:hover { background: #FEF2F2 !important; }

/* ── Dashboard Content ── */
.dashboard-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

/* ── Upload Zone ── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-xl);
  background: var(--bg);
  padding: 48px 32px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

/* Compact mode: usuário já tem ao menos 1 modelo. Encolhe pra uma faixa
   horizontal e libera ~40% de altura na fold pros cards.
   `transition` precisa ser sobrescrito porque o `transition: all` do
   .upload-zone base interfere com a mudança de padding em alguns browsers. */
body.has-models .upload-zone {
  padding: 12px 20px;
  transition: border-color var(--transition), background var(--transition);
}
body.has-models .upload-zone-inner {
  flex-direction: row;
  gap: 14px;
  align-items: center;
  justify-content: center;
}
body.has-models .upload-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
}
body.has-models .upload-icon svg { width: 20px; height: 20px; }
body.has-models .upload-text { text-align: left; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; justify-content: center; }
body.has-models .upload-text h3 { font-size: 0.95rem; margin-bottom: 0; }
body.has-models .upload-text p  { font-size: 0.85rem; margin: 0; }
body.has-models .upload-meta    { display: none; }

.upload-zone:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}
.upload-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}

.upload-zone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  pointer-events: none;
}

.upload-icon {
  width: 72px;
  height: 72px;
  background: var(--accent-light);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  transition: transform var(--transition);
}
.upload-zone:hover .upload-icon { transform: translateY(-3px); }

.upload-text h3 { font-size: 1.1rem; margin-bottom: 6px; }
.upload-text p  { color: var(--text-secondary); font-size: 0.92rem; }

.upload-link {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  font-size: inherit;
  cursor: pointer;
  text-decoration: underline;
  pointer-events: all;
}

.upload-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.upload-drag-overlay {
  position: absolute;
  inset: 0;
  background: var(--accent);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: white;
  font-weight: 600;
  font-size: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.upload-zone.drag-over .upload-drag-overlay { opacity: 1; }

/* Upload Progress */
.upload-progress-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.upload-progress-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.upload-progress-icon {
  width: 36px;
  height: 36px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

.upload-progress-info { flex: 1; min-width: 0; }
.upload-progress-name {
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.upload-progress-status { font-size: 0.78rem; color: var(--text-muted); margin-top: 3px; }

.upload-progress-bar-wrap {
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}
.upload-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.upload-progress-bar.complete { background: var(--success); }

/* ── Models Section ── */
.models-section { flex: 1; }

.models-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}

.models-header h2 { font-size: 1.25rem; }

.models-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.view-btn {
  background: none;
  border: none;
  padding: 7px 9px;
  color: var(--text-muted);
  transition: all var(--transition);
  display: flex;
  align-items: center;
}
.view-btn:hover { background: var(--bg-subtle); color: var(--text-primary); }
.view-btn.active { background: var(--accent-light); color: var(--accent); }

/* Empty State */
.models-empty {
  text-align: center;
  padding: 64px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.models-empty.hidden { display: none; }
.models-empty h3 { margin-top: 8px; }
.models-empty p  { color: var(--text-secondary); font-size: 0.92rem; line-height: 1.7; }

.empty-illustration {
  width: 100px;
  height: 100px;
  background: var(--bg-subtle);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border);
}

/* Models Grid */
.models-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.models-grid.list-view {
  grid-template-columns: 1fr;
}

/* Model Card */
.model-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
}
.model-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.model-card-thumb {
  background: linear-gradient(135deg, var(--bg-subtle), var(--accent-light));
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.model-card-thumb::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(99,102,241,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(99,102,241,0.04) 1px, transparent 1px);
  background-size: 20px 20px;
}
.model-card-thumb svg { z-index: 1; }

.model-card-thumb-label {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  font-family: var(--font-mono);
  z-index: 2;
}

/* Thumbnail real (R2): cobre o slot inteiro por cima do placeholder
   SVG/.IFC. Se o load falhar (signed URL expirado, key 404), o onerror
   no <img> remove o elemento e o placeholder volta a ficar visível. */
.model-card-thumb-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
  display: block;
}

.model-card-body {
  padding: 14px 16px;
  flex: 1;
}

.model-card-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.model-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.model-card-actions {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}

.model-card-btn {
  flex: 1;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.model-card-btn:hover { background: var(--accent-light); color: var(--accent); border-color: var(--accent); }
.model-card-btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.model-card-btn-primary:hover { background: var(--accent-dark); color: white; }
.model-card-btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
/* Botão só-ícone (sem label) — largura fixa em vez de dividir o flex:1
   igualmente com o botão primário. Card de projeto tem 4 ações (Abrir +
   3 ícones); sem isso os 4 dividiam a linha igualmente e o texto dos
   botões sem ícone-only estourava a largura do card. */
.model-card-btn-icon { flex: 0 0 auto; width: 30px; padding: 6px; }

/* List View Card */
.models-grid.list-view .model-card { display: flex; flex-direction: row; align-items: center; }
.models-grid.list-view .model-card-thumb { height: 60px; width: 80px; flex-shrink: 0; border-radius: 0; }
.models-grid.list-view .model-card-body { flex: 1; padding: 10px 16px; min-width: 0; }
.models-grid.list-view .model-card-name { font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.models-grid.list-view .model-card-actions { border-top: none; border-left: 1px solid var(--border); padding: 10px 12px; flex-direction: row; flex-shrink: 0; }
.models-grid.list-view .model-card-btn { min-width: 80px; }

/* Overlay de conversão em list view: layout horizontal compacto para caber
   na altura natural da linha. Deixa nome/meta visíveis por baixo do vidro. */
.models-grid.list-view .model-card-overlay {
  flex-direction: row !important;
  justify-content: flex-start !important;
  gap: 12px !important;
  padding: 0 16px !important;
  text-align: left !important;
  background: rgba(255,255,255,0.72) !important;
}
.models-grid.list-view .model-card-overlay > button {
  margin-top: 0 !important;
  margin-left: auto !important;
  flex-shrink: 0;
}
.models-grid.list-view .model-card-overlay > div:first-child {
  width: 16px !important;
  height: 16px !important;
  border-width: 2px !important;
  flex-shrink: 0;
}

/* Model Action Modal */
.model-modal-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.model-modal-icon {
  width: 48px;
  height: 48px;
  background: var(--accent-light);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.model-actions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.model-action-btn {
  background: var(--bg-subtle);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
}
.model-action-btn:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  transform: translateY(-1px);
}
.model-action-btn:hover .model-action-icon { background: var(--accent); color: white; }

.model-action-icon {
  width: 44px;
  height: 44px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  transition: all var(--transition);
}
.model-action-icon-muted { background: var(--bg-subtle); color: var(--text-muted); border: 1px solid var(--border); }

.model-action-btn span { font-size: 0.9rem; font-weight: 600; }
.model-action-btn small { font-size: 0.78rem; color: var(--text-muted); }

.model-action-btn-soon { opacity: 0.55; cursor: not-allowed; }
.model-action-btn-soon .badge-warning { opacity: 1; filter: none; background: #F97316; color: #fff; font-weight: 700; }
.model-action-btn-soon:hover { transform: none; border-color: var(--border); background: var(--bg-subtle); }
.model-action-btn-soon:hover .model-action-icon { background: var(--bg-subtle); color: var(--text-muted); }

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 300;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }

  .topbar-menu-btn { display: flex !important; }
  .topbar-search input { width: 120px; }

  .dashboard-content { padding: 20px; gap: 24px; }

  .upload-zone { padding: 32px 16px; }

  .models-grid { grid-template-columns: 1fr; }

  .model-actions-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .topbar { padding: 0 16px; gap: 8px; }
  .topbar-search { display: none; }
  .breadcrumb-home { display: none; }
  .breadcrumb-sep  { display: none; }
}
