/* ── Reset / Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: 'Segoe UI', Tahoma, Arial, sans-serif; background: #eef2f7; color: #2d3748; }

/* ── Login ───────────────────────────────────────────────────────────────── */
#tela-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a365d 0%, #2b6cb0 100%);
}
.login-card {
  background: white;
  border-radius: 16px;
  padding: 40px 36px;
  width: 340px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .bi { font-size: 48px; color: #2b6cb0; }
.login-title { font-size: 22px; font-weight: 800; color: #1a365d; margin-top: 4px; }
.login-sub   { font-size: 13px; color: #718096; }

/* ── Layout do App ───────────────────────────────────────────────────────── */
#app { display: flex; min-height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: #1a365d;
  display: flex;
  flex-direction: column;
  padding: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-brand .bi { font-size: 28px; color: #63b3ed; }
.sidebar-title { font-size: 15px; font-weight: 800; color: white; line-height: 1.2; }
.sidebar-sub   { font-size: 11px; color: #90cdf4; }

.sidebar-nav { flex: 1; padding: 12px 0; }
.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: #a0c4e8;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: all 0.15s;
}
.sidebar-nav .nav-link:hover { color: white; background: rgba(255,255,255,0.08); }
.sidebar-nav .nav-link.active { color: white; background: rgba(255,255,255,0.12); border-left-color: #63b3ed; }
.sidebar-nav .nav-link .bi { font-size: 16px; }

.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,0.1); }
.sidebar-usuario { font-size: 12px; color: #90cdf4; }

/* ── Conteúdo principal ──────────────────────────────────────────────────── */
.main-content { flex: 1; padding: 24px; overflow-y: auto; min-width: 0; }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tabs-wrapper { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#tabs-list { display: flex; gap: 6px; flex-wrap: wrap; }

.tab-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: white;
  border: 2px solid #e2e8f0;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #718096;
  transition: all 0.15s;
  user-select: none;
  white-space: nowrap;
}
.tab-item:hover:not(.active) { border-color: #4299e1; color: #2b6cb0; background: #ebf8ff; }
.tab-item.active { background: #2b6cb0; border-color: #2b6cb0; color: white; box-shadow: 0 2px 8px rgba(43,108,176,.3); }
.tab-item.active .tab-name:hover { text-decoration: underline; }

.tab-badge {
  background: rgba(255,255,255,0.3);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  min-width: 20px;
  text-align: center;
}
.tab-item:not(.active) .tab-badge { background: #e2e8f0; color: #4a5568; }

.tab-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0;
  color: inherit;
  opacity: .65;
}
.tab-close:hover { opacity: 1; }

.tab-add-btn {
  padding: 8px 14px;
  background: #ebf8ff;
  border: 2px dashed #90cdf4;
  border-radius: 10px;
  color: #2b6cb0;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.tab-add-btn:hover { background: #bee3f8; border-color: #4299e1; }

/* ── Veículo ─────────────────────────────────────────────────────────────── */
.vehicle-section {
  background: white;
  border-radius: 12px;
  padding: 14px 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.bar-track { background: #e2e8f0; border-radius: 20px; height: 26px; overflow: hidden; }
.bar-fill {
  height: 100%;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 12px;
  min-width: 44px;
  transition: width .4s ease, background .4s;
}
.bar-fill span { font-size: 12px; font-weight: 800; color: white; text-shadow: 0 1px 2px rgba(0,0,0,.25); }
.bar-safe    { background: linear-gradient(90deg,#38a169,#48bb78); }
.bar-warning { background: linear-gradient(90deg,#c8872a,#f6ad55); }
.bar-danger  { background: linear-gradient(90deg,#c53030,#fc8181); }

/* ── Cards de resumo ─────────────────────────────────────────────────────── */
.summary-card {
  background: white;
  border-radius: 12px;
  padding: 14px 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
  text-align: center;
}
.summary-card .card-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: #a0aec0;
  margin-bottom: 4px;
}
.summary-card .card-value { font-size: 20px; font-weight: 800; }
.card-blue   .card-value { color: #2b6cb0; }
.card-green  .card-value { color: #276749; }
.card-orange .card-value { color: #7b341e; }

/* ── Tabela ──────────────────────────────────────────────────────────────── */
.table-wrapper {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
  overflow-x: auto;
}
.tabela-compras { width: 100%; border-collapse: collapse; min-width: 1020px; }

.tabela-compras thead th {
  background: #2b6cb0;
  color: white;
  padding: 10px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  text-align: center;
  white-space: nowrap;
}
.tabela-compras thead th:first-child { border-radius: 12px 0 0 0; }
.tabela-compras thead th:last-child  { border-radius: 0 12px 0 0; }
.tabela-compras thead th small { font-weight: 400; font-size: 10px; display: block; opacity: .8; }

.tabela-compras tbody tr { border-bottom: 1px solid #f0f4f8; transition: background .12s; }
.tabela-compras tbody tr:hover { background: #f0f7ff; }
.tabela-compras tbody tr:nth-child(even)       { background: #f8fafc; }
.tabela-compras tbody tr:nth-child(even):hover { background: #e8f4ff; }

.tabela-compras td { padding: 5px 5px; text-align: center; vertical-align: middle; }

/* Inputs da tabela */
.item-input {
  width: 100%;
  padding: 5px 5px;
  border: 2px solid #e2e8f0;
  border-radius: 7px;
  font-size: 13px;
  text-align: center;
  background: white;
  font-weight: 500;
  transition: border-color .2s;
  font-family: inherit;
}
.item-input[type="text"]:not(.num-field) { text-align: left; }
.item-input:focus { outline: none; border-color: #4299e1; background: #ebf8ff; }
.item-input.num-field { text-align: center; }

/* Campos calculados */
.calc-field {
  display: block;
  padding: 6px 6px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  border: 2px solid #bee3f8;
  background: #ebf8ff;
  color: #1a365d;
}
.calc-field.green  { background: #f0fff4; border-color: #c6f6d5; color: #276749; }
.calc-field.orange { background: #fffaf0; border-color: #feebc8; color: #7b341e; }

/* Select de pedido dentro da linha */
.tab-select { font-size: 11px; color: #4a5568; background: #f8fafc; font-weight: 600; }

/* Botão remover linha */
.btn-duplicate-item {
  background: #ebf8ff;
  color: #2b6cb0;
  border: none;
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s;
}
.btn-duplicate-item:hover { background: #bee3f8; color: #1a365d; }

.btn-remove-item {
  background: #fed7d7;
  color: #c53030;
  border: none;
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s;
}
.btn-remove-item:hover { background: #fc8181; color: white; }

.row-num { color: #a0aec0; font-weight: 700; font-size: 12px; }

.drag-handle {
  cursor: grab;
  color: #cbd5e0;
  font-size: 16px;
  padding: 5px 4px;
  text-align: center;
  user-select: none;
}
.drag-handle:hover { color: #718096; }
.drag-handle:active { cursor: grabbing; }

.tabela-compras tbody tr.sortable-ghost  { opacity: .35; background: #ebf8ff !important; }
.tabela-compras tbody tr.sortable-chosen { background: #f0f7ff !important; box-shadow: 0 3px 12px rgba(0,0,0,.12); }

/* ── Legenda ─────────────────────────────────────────────────────────────── */
.legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 11px; color: #718096; }
.legend span { display: flex; align-items: center; gap: 5px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.dot-blue   { background: #ebf8ff; border: 2px solid #bee3f8; }
.dot-green  { background: #f0fff4; border: 2px solid #c6f6d5; }
.dot-orange { background: #fffaf0; border: 2px solid #feebc8; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast-notif {
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: white;
  opacity: 0;
  transform: translateX(20px);
  transition: all .25s;
  pointer-events: none;
  max-width: 320px;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
}
.toast-notif.show { opacity: 1; transform: translateX(0); }
.toast-success { background: #38a169; }
.toast-error   { background: #e53e3e; }
.toast-info    { background: #3182ce; }
.toast-warning { background: #d69e2e; }

/* ── Spinner de carregamento ─────────────────────────────────────────────── */
.loading-page { display: flex; align-items: center; justify-content: center; height: 200px; color: #a0aec0; }

/* ── Print ───────────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .tabs-wrapper .tab-add-btn, .tab-close, .btn-remove-item,
  #btn-add-item, #btn-export-csv, label.btn, #btn-print, #btn-clear,
  #save-indicator, [data-campo="pedido"], .legend { display: none !important; }
  .main-content { padding: 0; }
  .sidebar { display: none; }
  #app { display: block !important; }
  .vehicle-section, .summary-card { box-shadow: none; border: 1px solid #ccc; }
  .table-wrapper { box-shadow: none; overflow: visible; }
  .tabela-compras { min-width: auto; }
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */
.topbar-mobile {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 54px;
  background: #1a365d;
  align-items: center;
  padding: 0 14px;
  gap: 12px;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.topbar-mobile .bi-cart3 { font-size: 22px; color: #63b3ed; }
.topbar-mobile-title { font-size: 15px; font-weight: 800; color: white; flex: 1; }
.btn-hamburger {
  background: none;
  border: none;
  color: white;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1099;
}
.sidebar-overlay.show { display: block; }

@media (max-width: 768px) {
  .topbar-mobile { display: flex; }

  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 1100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    width: 240px;
    min-width: 240px;
  }
  .sidebar.open { transform: translateX(0); }

  .main-content {
    padding: 14px 10px;
    padding-top: 68px;
  }

  /* Cards de resumo em grid 2 colunas */
  .summary-cards-row { grid-template-columns: 1fr 1fr !important; }

  /* Tabs menores */
  .tab-item { padding: 6px 10px; font-size: 12px; }
  .tab-add-btn { padding: 6px 10px; font-size: 12px; }

  /* Barra de peso mais compacta */
  .vehicle-section { padding: 10px 12px; }
}
