/* ============================================================
   Tokens
   ============================================================ */
:root {
  --c-bg:            #f5f6f8;
  --c-surface:       #ffffff;
  --c-surface-alt:   #f8fafc;
  --c-border:        #e2e6ec;
  --c-border-strong: #d1d7e0;

  --c-text:          #1f2937;
  --c-text-muted:    #6b7280;
  --c-text-subtle:   #9ca3af;

  --c-primary:       #334155;
  --c-primary-hover: #1e293b;

  --c-accent:        #113179;
  --c-accent-soft:   #eff6ff;

  --c-success:       #16a34a;
  --c-warn:          #d97706;
  --c-error:         #dc2626;
  --c-info:          #2563eb;

  --c-success-bg:    #f0fdf4;
  --c-warn-bg:       #fffbeb;
  --c-error-bg:      #fef2f2;
  --c-info-bg:       #eff6ff;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;

  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 8px;

  --fs-xs:   11px;
  --fs-sm:   12px;
  --fs-base: 13px;
  --fs-md:   14px;
  --fs-lg:   16px;
  --fs-xl:   18px;

  --fw-normal:   500;
  --fw-semibold: 600;
  --fw-bold:     700;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, .08);

  --t-fast: .15s ease;
  --t-base: .2s ease;
}

/* ============================================================
   Reset / base
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  font-size: var(--fs-base);
  color: var(--c-text);
  background: var(--c-bg);
}

.container {
  height: 100%;
  display: flex;
  flex-direction: column;
  width: 95%;
  max-width: 1800px;
  margin: 0 auto;
  padding: var(--sp-5);
  background: var(--c-surface);
  min-height: 0;
}

/* ============================================================
   Header
   ============================================================ */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-5);
  margin-bottom: var(--sp-4);
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--c-border);
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.page-header-title {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  flex: 0 1 auto;
  min-width: 0;
}

h1 {
  font-size: var(--fs-xl);
  font-weight: var(--fw-semibold);
  color: var(--c-text);
  line-height: 1.2;
}

.project-params-wrapper { flex: 0 1 auto; min-width: 0; max-width: 100%; }

.project-info {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  align-items: flex-start;
}

.project-info-field {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--c-text);
}

.project-info-field > span {
  font-weight: var(--fw-semibold);
  white-space: nowrap;
  min-width: 110px;
}

.project-info-input {
  width: 400px;
  padding: var(--sp-1) var(--sp-2);
  font-size: var(--fs-sm);
  font-family: inherit;
  color: var(--c-text);
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-sm);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.project-info-input:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px var(--c-accent-soft);
}

.project-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
}

.project-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: #fff;
  background: var(--c-primary);
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-base);
}

.project-btn:hover { background: var(--c-primary-hover); }
.project-btn:disabled { background: var(--c-text-subtle); cursor: not-allowed; }

.project-btn .btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.project-btn .btn-icon svg { width: 100%; height: 100%; display: block; }
.project-btn .btn-label { white-space: nowrap; }
.project-btn .btn-caret { font-size: 10px; opacity: .85; margin-left: 2px; }
.project-btn .dirty-dot { color: #fecaca; }

/* ============================================================
   App body
   ============================================================ */
.app-body {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  gap: var(--sp-4);
}

/* ---------- Sidebar ---------- */
.sidebar {
  flex: 0 0 220px;
  background: var(--c-surface-alt);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav { padding: var(--sp-2) var(--sp-1); }

.nav-category { margin-bottom: 2px; }

.nav-category-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  font-family: inherit;
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: .7px;
  background: transparent;
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}

.nav-category-toggle:hover {
  background: var(--c-border);
  color: var(--c-text);
}

.nav-category-toggle::after {
  content: '▾';
  font-size: 11px;
  transition: transform var(--t-base);
}

.nav-category.collapsed .nav-category-toggle::after { transform: rotate(-90deg); }

.nav-category-items {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 2px 0 var(--sp-1);
}

.nav-category.collapsed .nav-category-items { display: none; }

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  padding: var(--sp-2) var(--sp-3) var(--sp-2) var(--sp-3);
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: var(--fw-normal);
  color: var(--c-text-muted);
  text-align: left;
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-item:hover {
  background: var(--c-border);
  color: var(--c-text);
}

.nav-item.active {
  background: var(--c-accent-soft);
  color: var(--c-accent);
  font-weight: var(--fw-semibold);
  border-left-color: var(--c-accent);
}

.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--c-text-subtle);
  transition: color var(--t-fast);
}

.nav-icon svg { width: 100%; height: 100%; display: block; }

.nav-item:hover .nav-icon { color: var(--c-text-muted); }
.nav-item.active .nav-icon { color: var(--c-accent); }

.nav-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Content ---------- */
.content {
  flex: 1 1 auto;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

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

.tab-panel[data-tab="home"].active {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.tab-panel[data-tab="home"] .canvas-wrapper {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

.tab-panel[data-tab="home"] #networkCanvas {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: block;
}

/* ============================================================
   Status bar
   ============================================================ */
.status-bar {
  padding: var(--sp-2) var(--sp-3);
  margin-bottom: var(--sp-3);
  font-size: var(--fs-base);
  color: var(--c-text);
  background: var(--c-info-bg);
  border-left: 3px solid var(--c-info);
  border-radius: var(--r-sm);
}

.status-bar.erro    { background: var(--c-error-bg); border-left-color: var(--c-error); }
.status-bar.sucesso { background: var(--c-success-bg); border-left-color: var(--c-success); }

/* ============================================================
   Canvas
   ============================================================ */
.canvas-wrapper {
  display: flex;
  justify-content: center;
  margin-bottom: var(--sp-4);
}

canvas {
  max-width: 100%;
  background: var(--c-surface-alt);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
}

/* ============================================================
   Tabelas
   ============================================================ */
.tables-wrapper {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-6);
  margin-top: var(--sp-5);
}

.table-section { flex: 1 1 45%; min-width: 0; }

.table-section h2 {
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  color: var(--c-text);
  padding-bottom: var(--sp-2);
  margin-bottom: var(--sp-4);
  border-bottom: 1px solid var(--c-border);
}

.table-wrapper {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  overflow-x: auto;
  overflow-y: visible;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-sm);
  table-layout: auto;
}

table th {
  padding: var(--sp-2) var(--sp-3);
  font-weight: var(--fw-semibold);
  color: var(--c-text);
  text-align: left;
  white-space: nowrap;
  background: var(--c-surface-alt);
  border-bottom: 1px solid var(--c-border-strong);
}

table td {
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
}

table:not(.network-table):not(.dimensioning-table):not(.status-table) td {
  background: var(--c-surface);
}

table th:first-child,
table td:first-child { padding-left: var(--sp-3); }

.table-wrapper table:not(.dimensioning-table) thead th {
  position: sticky;
  top: 0;
  z-index: 3;
}

/* ============================================================
   Toolbar de status
   ============================================================ */
.status-toolbar {
  display: flex;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}

.status-btn {
  padding: var(--sp-2) var(--sp-4);
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: #fff;
  background: var(--c-primary);
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-base);
}

.status-btn:hover { background: var(--c-primary-hover); }

.cell-check { text-align: center; }
.cell-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--c-accent);
}

/* ============================================================
   Scrollbar
   ============================================================ */
.table-wrapper::-webkit-scrollbar,
.content::-webkit-scrollbar,
.sidebar::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.table-wrapper::-webkit-scrollbar-track,
.content::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.table-wrapper::-webkit-scrollbar-thumb,
.content::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb {
  background: var(--c-border-strong);
  border-radius: 999px;
}

.table-wrapper::-webkit-scrollbar-thumb:hover,
.content::-webkit-scrollbar-thumb:hover,
.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--c-text-subtle);
}

/* ============================================================
   Toast
   ============================================================ */
.toast-stack {
  position: fixed;
  top: var(--sp-4);
  right: var(--sp-4);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  max-width: 340px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-base);
  color: #fff;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateX(20px);
  transition: opacity var(--t-base), transform var(--t-base);
}

.toast.show { opacity: 1; transform: translateX(0); }

.toast-info    { background: var(--c-info); }
.toast-success { background: var(--c-success); }
.toast-warn    { background: var(--c-warn); }
.toast-error   { background: var(--c-error); }

/* ============================================================
   Dirty dot
   ============================================================ */
.dirty-dot {
  display: inline-block;
  margin-left: var(--sp-1);
  font-size: var(--fs-sm);
  color: var(--c-error);
  animation: pulse 1.6s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .35; }
}

/* ============================================================
   Dropdown
   ============================================================ */
.dropdown { position: relative; display: inline-block; }

.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: var(--sp-1);
  min-width: 200px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  z-index: 100;
  overflow: hidden;
}

.dropdown-menu button {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  font-family: inherit;
  font-size: var(--fs-base);
  color: var(--c-text);
  text-align: left;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background var(--t-fast);
}

.dropdown-menu button:hover { background: var(--c-surface-alt); }

.dropdown-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--c-text-muted);
  transition: color var(--t-fast);
}

.dropdown-icon svg { width: 100%; height: 100%; display: block; }

.dropdown-menu button:hover .dropdown-icon { color: var(--c-accent); }

.dropdown-label { flex: 1 1 auto; min-width: 0; }

.dropdown-menu .dropdown-check {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  font-family: inherit;
  font-size: var(--fs-base);
  color: var(--c-text);
  cursor: pointer;
  user-select: none;
  transition: background var(--t-fast);
}

.dropdown-menu .dropdown-check:hover { background: var(--c-surface-alt); }

.dropdown-menu .dropdown-check input[type="checkbox"] {
  margin: 0;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--c-accent);
}

.dropdown-check-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--c-text-muted);
  transition: color var(--t-fast);
}

.dropdown-check-icon svg { width: 100%; height: 100%; display: block; }

.dropdown-menu .dropdown-check:hover .dropdown-check-icon { color: var(--c-accent); }

/* ============================================================
   Responsivo
   ============================================================ */
@media (max-width: 900px) {
  html, body { height: auto; overflow: auto; }

  .container { height: auto; padding: var(--sp-4); width: 100%; }

  .page-header { justify-content: center; }

  .page-header-title {
    align-items: center;
    text-align: center;
    flex: 1 1 100%;
  }

  .project-info { align-items: center; }
  .project-info-input { width: 100%; max-width: 380px; }

  .project-actions { justify-content: center; }

  .project-params-wrapper {
    flex: 1 1 100%;
    display: flex;
    justify-content: center;
  }

  .app-body { flex-direction: column; gap: var(--sp-3); }

  .sidebar {
    flex: 0 0 220px;
    background: var(--c-surface-alt);
    border: 1px solid var(--c-border);
    border-radius: var(--r-md);
    overflow-y: auto;
    overflow-x: hidden;
    contain: paint;
  }

  .content { overflow-y: visible; }
}

@media (max-width: 768px) {
  .table-section { flex: 1 1 100%; }
  .table-wrapper { max-height: none; }

  .table-wrapper table:not(.dimensioning-table) thead th { position: static; }
}

.btn-icon svg,
.dropdown-icon svg,
.dropdown-check-icon svg,
.nav-icon svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-icon svg.icon-bold,
.dropdown-icon svg.icon-bold {
  stroke-width: 2.2;
}

.visually-hidden {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
}
/* ============================================================
   Link "voltar ao hub"
   ============================================================ */

.back-to-hub {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  align-self: flex-start;
  margin-bottom: var(--sp-1);
  padding: var(--sp-1) var(--sp-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--c-text-muted);
  text-decoration: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  transition: color var(--t-fast), background var(--t-fast), border-color var(--t-fast);
}

.back-to-hub svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.back-to-hub:hover {
  color: var(--c-accent);
  background: var(--c-accent-soft);
}

.back-to-hub:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
}