/* ═══════════════════════════════════════════════════════════════
   BC3 Editor – Dark Theme Stylesheet
   ═══════════════════════════════════════════════════════════════ */

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base:      #0f1117;
  --bg-surface:   #1a1d27;
  --bg-elevated:  #22263a;
  --bg-hover:     #2a2f47;
  --border:       #2e3350;
  --border-light: #3a4060;

  --text-primary:   #e8eaf6;
  --text-secondary: #8892b0;
  --text-muted:     #4a5280;

  --accent-blue:   #4f8ef7;
  --accent-green:  #43d9a2;
  --accent-orange: #f7a94f;
  --accent-purple: #b57bee;
  --accent-red:    #f76f6f;
  --accent-yellow: #f7d94f;

  --sidebar-w: 240px;
  --topbar-h:  60px;
  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 4px 24px rgba(0,0,0,.45);
  --transition: .18s ease;
}

html, body { height: 100%; font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg-base); color: var(--text-primary); font-size: 14px; }

a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font-family: inherit; font-size: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* ── Layout ── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: width var(--transition);
  z-index: 100;
}
.sidebar.collapsed { width: 60px; }
.sidebar.collapsed .sidebar-header span,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .sidebar-footer { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 12px 0; }

.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
  transition: margin-left var(--transition);
}
.sidebar.collapsed ~ .main-content { margin-left: 60px; }

/* ── Sidebar Header ── */
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 700; color: var(--accent-blue); }
.logo i { font-size: 20px; }
.sidebar-toggle { color: var(--text-secondary); padding: 6px; border-radius: var(--radius-sm); transition: background var(--transition); }
.sidebar-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ── Sidebar Nav ── */
.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 13.5px;
  transition: background var(--transition), color var(--transition);
}
.nav-item i { width: 18px; text-align: center; font-size: 15px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: rgba(79,142,247,.15); color: var(--accent-blue); font-weight: 600; }
.nav-divider { border: none; border-top: 1px solid var(--border); margin: 8px 0; }

/* ── Sidebar Footer ── */
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); }
.file-info { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 12px; overflow: hidden; }
.file-info span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unsaved-badge { margin-top: 6px; color: var(--accent-orange); font-size: 12px; display: flex; align-items: center; gap: 6px; }

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.page-title { font-size: 18px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.search-bar { display: flex; align-items: center; gap: 8px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 12px; }
.search-bar i { color: var(--text-muted); }
.search-bar input { background: none; border: none; outline: none; color: var(--text-primary); width: 220px; }

/* ── Views ── */
.view { display: none; padding: 24px; flex: 1; }
.view.active { display: block; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 13px;
  transition: opacity var(--transition), transform var(--transition);
}
.btn:hover { opacity: .85; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary  { background: var(--accent-blue);   color: #fff; }
.btn-secondary{ background: var(--bg-elevated);   color: var(--text-primary); border: 1px solid var(--border); }
.btn-warning  { background: var(--accent-orange); color: #fff; }
.btn-danger   { background: var(--accent-red);    color: #fff; }
.btn-ghost    { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-sm       { padding: 5px 11px; font-size: 12px; }

/* ── Stats Grid ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  display: flex; align-items: center; gap: 16px;
  border-left: 4px solid transparent;
}
.stat-card.accent-blue   { border-left-color: var(--accent-blue); }
.stat-card.accent-green  { border-left-color: var(--accent-green); }
.stat-card.accent-orange { border-left-color: var(--accent-orange); }
.stat-card.accent-purple { border-left-color: var(--accent-purple); }
.stat-icon { font-size: 28px; opacity: .7; }
.accent-blue   .stat-icon { color: var(--accent-blue); }
.accent-green  .stat-icon { color: var(--accent-green); }
.accent-orange .stat-icon { color: var(--accent-orange); }
.accent-purple .stat-icon { color: var(--accent-purple); }
.stat-value { font-size: 28px; font-weight: 800; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

/* ── Dashboard Panels ── */
.dashboard-panels { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .dashboard-panels { grid-template-columns: 1fr; } }

/* ── Panel ── */
.panel { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.panel-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.panel-header h2 { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.panel-body { padding: 12px 0; max-height: 320px; overflow-y: auto; }

/* ── Toolbar ── */
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 10px; }
.count-label { color: var(--text-secondary); font-size: 12px; }

/* ── Inputs ── */
.input-field {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px;
  color: var(--text-primary); outline: none; width: 100%;
  transition: border-color var(--transition);
}
.input-field:focus { border-color: var(--accent-blue); }
.input-search {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 7px 12px;
  color: var(--text-primary); outline: none;
  transition: border-color var(--transition);
}
.input-search:focus { border-color: var(--accent-blue); }

/* ── Tables ── */
.table-wrapper { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead th {
  background: var(--bg-elevated); padding: 11px 14px;
  text-align: left; font-size: 12px; font-weight: 700;
  color: var(--text-secondary); text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
}
.data-table tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table td { padding: 10px 14px; font-size: 13px; }
.data-table.compact td { padding: 7px 12px; font-size: 12.5px; }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* ── Pagination ── */
.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.page-btn {
  padding: 5px 11px; border-radius: var(--radius-sm);
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text-secondary); font-size: 13px; cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.page-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.page-btn.active { background: var(--accent-blue); color: #fff; border-color: var(--accent-blue); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Action Buttons in Table ── */
.action-btn {
  padding: 4px 9px; border-radius: var(--radius-sm); font-size: 12px;
  display: inline-flex; align-items: center; gap: 5px;
  transition: opacity var(--transition);
}
.action-btn:hover { opacity: .8; }
.action-btn-view   { background: rgba(79,142,247,.15); color: var(--accent-blue); }
.action-btn-edit   { background: rgba(247,169,79,.15);  color: var(--accent-orange); }
.action-btn-delete { background: rgba(247,111,111,.15); color: var(--accent-red); }

/* ── Search Hero ── */
.search-hero { padding: 40px 0 24px; }
.search-hero-inner { max-width: 640px; margin: 0 auto; text-align: center; }
.search-hero-icon { font-size: 40px; color: var(--accent-blue); margin-bottom: 16px; display: block; }
.search-hero-input {
  width: 100%; padding: 14px 20px; font-size: 16px;
  background: var(--bg-surface); border: 2px solid var(--border);
  border-radius: 50px; color: var(--text-primary); outline: none;
  transition: border-color var(--transition);
}
.search-hero-input:focus { border-color: var(--accent-blue); }
.search-filters { display: flex; justify-content: center; gap: 20px; margin-top: 14px; color: var(--text-secondary); }
.search-filters label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.search-results { max-width: 800px; margin: 0 auto; }

/* ── Reajuste ── */
.reajuste-container { max-width: 700px; }
.form-group { margin-bottom: 18px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--text-secondary); font-weight: 600; }
.form-row { display: flex; gap: 14px; }
.form-row .form-group { flex: 1; }
.flex-2 { flex: 2 !important; }
.flex-1 { flex: 1 !important; }
.radio-group { display: flex; gap: 20px; }
.radio-group label { display: flex; align-items: center; gap: 6px; cursor: pointer; color: var(--text-primary); }
.input-with-suffix { display: flex; align-items: center; gap: 8px; }
.suffix { color: var(--text-secondary); font-weight: 700; }
.hint { color: var(--text-muted); font-size: 12px; margin-top: 4px; display: block; }
.form-actions { display: flex; gap: 12px; margin-top: 24px; }
.reajuste-preview { margin-top: 20px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; max-height: 300px; overflow-y: auto; }
.section-divider { display: flex; align-items: center; gap: 12px; margin: 20px 0 14px; color: var(--text-muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.section-divider::before, .section-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 20px;
}
.modal {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); width: 100%; max-width: 680px;
  max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow);
}
.modal-lg { max-width: 860px; }
.modal-sm { max-width: 420px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 16px; font-weight: 700; }
.modal-close { color: var(--text-muted); padding: 4px 8px; border-radius: var(--radius-sm); transition: background var(--transition); }
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.modal-body { padding: 22px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ── Components ── */
.components-toolbar { display: flex; gap: 10px; margin-bottom: 12px; }
.comp-search-results {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm); max-height: 180px; overflow-y: auto;
  margin-bottom: 10px;
}
.comp-result-item { padding: 8px 12px; cursor: pointer; display: flex; align-items: center; gap: 10px; transition: background var(--transition); }
.comp-result-item:hover { background: var(--bg-hover); }
.comp-result-code { font-family: monospace; font-size: 12px; color: var(--accent-blue); min-width: 70px; }
.comp-result-desc { font-size: 13px; flex: 1; }
.comp-result-price { font-size: 12px; color: var(--accent-green); }

/* ── Toast ── */
.toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 999; }
.toast {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 18px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow); min-width: 260px; max-width: 380px;
  animation: slideIn .25s ease;
}
.toast.success { border-left: 4px solid var(--accent-green); }
.toast.error   { border-left: 4px solid var(--accent-red); }
.toast.warning { border-left: 4px solid var(--accent-orange); }
.toast.info    { border-left: 4px solid var(--accent-blue); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Loading ── */
.loading-spinner { display: flex; justify-content: center; align-items: center; padding: 40px; color: var(--text-muted); font-size: 22px; }

/* ── Code badge ── */
.code-badge { font-family: monospace; font-size: 12px; background: rgba(79,142,247,.12); color: var(--accent-blue); padding: 2px 7px; border-radius: 4px; }
.type-badge { font-size: 11px; padding: 2px 8px; border-radius: 20px; font-weight: 700; }
.type-I { background: rgba(67,217,162,.12); color: var(--accent-green); }
.type-C { background: rgba(181,123,238,.12); color: var(--accent-purple); }

/* ── Detail Modal ── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 20px; }
.detail-field label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; display: block; margin-bottom: 3px; }
.detail-field .value { font-size: 14px; font-weight: 600; }
.detail-price { font-size: 24px; font-weight: 800; color: var(--accent-green); }

/* ── Quick list (dashboard) ── */
.quick-list-item { display: flex; align-items: center; gap: 10px; padding: 8px 18px; border-bottom: 1px solid var(--border); transition: background var(--transition); cursor: pointer; }
.quick-list-item:last-child { border-bottom: none; }
.quick-list-item:hover { background: var(--bg-hover); }
.quick-list-item .ql-code { font-family: monospace; font-size: 12px; color: var(--accent-blue); min-width: 70px; }
.quick-list-item .ql-desc { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quick-list-item .ql-price { font-size: 12px; color: var(--accent-green); white-space: nowrap; }

/* ══════════════════════════════════════════════════════════════
   TREE VIEW
   ══════════════════════════════════════════════════════════════ */
.tree-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 0;
  height: calc(100vh - var(--topbar-h) - 48px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-surface);
}

/* ── Tree Panel (left) ── */
.tree-panel {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-surface);
}
.tree-toolbar {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.tree-container {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

/* ── Tree Nodes ── */
.tree-node { user-select: none; }

.tree-node-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  cursor: pointer;
  border-radius: 0;
  transition: background var(--transition);
  font-size: 13px;
}
.tree-node-header:hover { background: var(--bg-hover); }
.tree-node-header.selected { background: rgba(79,142,247,.18); color: var(--accent-blue); }

.tree-toggle {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 10px;
  flex-shrink: 0;
  transition: transform var(--transition);
}
.tree-toggle.open { transform: rotate(90deg); }
.tree-toggle.leaf { visibility: hidden; }

.tree-icon {
  font-size: 13px;
  flex-shrink: 0;
  width: 16px;
  text-align: center;
}
.tree-icon.root    { color: var(--accent-blue); }
.tree-icon.group   { color: var(--accent-orange); }
.tree-icon.sub     { color: var(--accent-yellow); }
.tree-icon.insumo  { color: var(--accent-green); }
.tree-icon.composicao { color: var(--accent-purple); }

.tree-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tree-label .tree-code {
  font-family: monospace;
  font-size: 11px;
  color: var(--accent-blue);
  margin-right: 6px;
}
.tree-count {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 1px 6px;
  border-radius: 10px;
  flex-shrink: 0;
}

.tree-children {
  display: none;
  padding-left: 18px;
  border-left: 1px dashed var(--border-light);
  margin-left: 18px;
}
.tree-children.open { display: block; }

/* ── Tree Detail Panel (right) ── */
.tree-detail-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-base);
}
.tree-detail-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 14px;
}
.tree-detail-placeholder i { font-size: 48px; opacity: .3; }
.tree-detail-placeholder p { font-size: 14px; }

.tree-detail-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* Group detail */
.tree-group-detail h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.tree-group-detail .group-meta {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 20px;
}
.tree-group-items-table { width: 100%; border-collapse: collapse; }
.tree-group-items-table th {
  background: var(--bg-elevated);
  padding: 9px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
}
.tree-group-items-table td {
  padding: 8px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.tree-group-items-table tr:hover td { background: var(--bg-hover); cursor: pointer; }

/* Item detail */
.tree-item-detail .item-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
}
.tree-item-detail .item-title { font-size: 16px; font-weight: 700; line-height: 1.4; }
.tree-item-detail .item-price-big {
  font-size: 28px;
  font-weight: 800;
  color: var(--accent-green);
  white-space: nowrap;
}
.tree-item-meta {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.tree-item-meta .meta-chip {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tree-item-actions { display: flex; gap: 10px; margin-bottom: 20px; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ── Misc ── */
.items-checklist { max-height: 200px; overflow-y: auto; margin-top: 8px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.items-checklist label { display: flex; align-items: center; gap: 8px; padding: 7px 12px; cursor: pointer; border-bottom: 1px solid var(--border); font-size: 13px; }
.items-checklist label:last-child { border-bottom: none; }
.items-checklist label:hover { background: var(--bg-hover); }