*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2a2e45;
  --text: #e8eaf0;
  --muted: #7c82a0;
  --accent: #6c63ff;
  --accent-dim: rgba(108,99,255,0.12);
  --green: #22d3a0;
  --yellow: #f5a623;
  --red: #ff4f6d;
  --shadow: 0 4px 24px rgba(0,0,0,0.35);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.25);
  --radius: 12px;
  --sidebar-w: 230px;
  --header-h: 56px;
  --transition: 0.2s ease;
}

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── LAYOUT ─────────────────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

/* ── SIDEBAR ────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform var(--transition);
}

.sidebar-top {
  display: flex;
  align-items: center;
  padding: 0 20px;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
}

.logo {
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.5px;
}
.logo span { color: var(--text); }

.sidebar nav { padding: 12px 0; flex: 1; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  transition: all var(--transition);
  border-left: 3px solid transparent;
  border-radius: 0;
}
.nav-item:hover { color: var(--text); background: var(--surface2); }
.nav-item.active { color: var(--accent); border-left-color: var(--accent); background: var(--accent-dim); }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
}

/* ── OVERLAY (mobile) ────────────────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 199;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

/* ── TOP BAR (mobile) ────────────────────────────────────────────────────────── */
.topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 100;
}

.topbar-logo {
  font-size: 16px;
  font-weight: 800;
  color: var(--accent);
  flex: 1;
}
.topbar-logo span { color: var(--text); }

.hamburger {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 4px;
}
.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all var(--transition);
}

/* ── MAIN ────────────────────────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px 28px;
  min-width: 0;
}

/* ── PAGE HEADER ─────────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  gap: 12px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
}

.subtitle { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ── BUTTONS ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:hover { opacity: 0.85; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 2px 12px rgba(108,99,255,0.4); }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }

/* ── FILTER BAR ──────────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
}

.filter-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.filter-btn:hover { border-color: var(--accent); color: var(--text); }
.filter-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 2px 10px rgba(108,99,255,0.35); }

/* ── CARDS ───────────────────────────────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.cards-grid-mp {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: box-shadow var(--transition), transform var(--transition);
}
.card:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }

.card-label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.card-value { font-size: 26px; font-weight: 800; margin: 10px 0 4px; line-height: 1; }
.card-sub { font-size: 12px; color: var(--muted); }

/* ── MP TOGGLE ───────────────────────────────────────────────────────────────── */
.mp-toggle-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  margin-bottom: 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  cursor: pointer;
  user-select: none;
  transition: color var(--transition);
}
.mp-toggle-header:hover { color: var(--text); }

/* ── CHART ───────────────────────────────────────────────────────────────────── */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}
.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.chart-title { font-size: 15px; font-weight: 700; }

/* ── TABLE ───────────────────────────────────────────────────────────────────── */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 10px;
}
.table-title { font-size: 15px; font-weight: 700; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }

.filter-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
}

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 540px; }

thead th {
  text-align: left;
  padding: 11px 16px;
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }

/* ── BADGES ──────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-paid { background: rgba(34,211,160,0.15); color: var(--green); }
.badge-pending { background: rgba(245,166,35,0.15); color: var(--yellow); }
.badge-cancelled { background: rgba(255,79,109,0.15); color: var(--red); }
.badge-default { background: var(--surface2); color: var(--muted); }

.mp-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.mp-mercadolivre { background: rgba(255,230,0,0.12); color: #ffe600; }
.mp-shopee { background: rgba(255,87,34,0.12); color: #ff5722; }
.mp-amazon { background: rgba(255,153,0,0.12); color: #ff9900; }
.mp-tiktok { background: rgba(105,201,208,0.12); color: #69c9d0; }
.mp-shopify { background: rgba(150,191,72,0.12); color: #96bf48; }
.mp-lojaintegrada { background: rgba(0,120,212,0.12); color: #0078d4; }

/* ── ORDER CARDS ─────────────────────────────────────────────────────────────── */
.order-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
  transition: box-shadow var(--transition);
}
.order-card:hover { box-shadow: var(--shadow-sm); }

.order-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.order-id { font-family: monospace; font-size: 12px; color: var(--muted); }
.order-date { font-size: 12px; color: var(--muted); margin-left: auto; }

.order-card-body {
  display: grid;
  grid-template-columns: 170px 1fr 210px;
  gap: 0;
}

.order-col {
  padding: 14px 16px;
  border-right: 1px solid var(--border);
}
.order-col:last-child { border-right: none; }
.order-col-fin { padding: 10px 14px; }

.order-col-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  margin-bottom: 10px;
}

.order-buyer-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  word-break: break-all;
}
.order-buyer-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.8;
}

.order-product-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.order-product-meta {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.9;
}
.order-product-meta span { color: var(--text); }
.order-item-id { font-family: monospace; color: var(--accent); font-size: 11px; }

/* ── FINANCIAL ROWS (MercadoTurbo style) ─────────────────────────────────── */
.fin-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  position: relative;
  cursor: default;
}

.fin-icon {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}

.fin-label {
  flex: 1;
  font-size: 12px;
  color: var(--muted);
  min-width: 0;
}

.fin-value {
  font-size: 12px;
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}

.fin-repasse { padding-top: 6px; }
.fin-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.fin-lucro-row { padding-top: 4px; }
.fin-lucro-val { text-align: right; }

/* Tooltip on hover */
.fin-row[data-tip] { cursor: help; }
.fin-row[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 4px);
  right: 0;
  background: #1a1d27;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text);
  white-space: pre-line;
  z-index: 200;
  min-width: 180px;
  max-width: 260px;
  pointer-events: none;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  line-height: 1.6;
}

/* Custo input */
.fin-cost-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  text-align: right;
  padding: 3px 6px;
  width: 72px;
  cursor: pointer;
  transition: border-color var(--transition);
}
.fin-cost-input:focus {
  outline: none;
  border-color: var(--accent);
}
.fin-cost-input::placeholder { color: var(--muted); }

/* Remove number input arrows */
.fin-cost-input::-webkit-outer-spin-button,
.fin-cost-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.fin-cost-input[type=number] { -moz-appearance: textfield; }

@media (max-width: 1024px) {
  .order-card-body { grid-template-columns: 160px 1fr 200px; }
}

@media (max-width: 768px) {
  .order-card-body { grid-template-columns: 1fr; }
  .order-col { border-right: none; border-bottom: 1px solid var(--border); }
  .order-col:last-child { border-bottom: none; }
  .order-date { margin-left: 0; width: 100%; }
  .fin-row[data-tip]:hover::after { right: auto; left: 0; }
}

/* ── PAGINATION ──────────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}

/* ── CONNECTIONS ─────────────────────────────────────────────────────────────── */
.connections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.connection-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: box-shadow var(--transition);
}
.connection-card:hover { box-shadow: var(--shadow-sm); }

/* ── SEARCH ──────────────────────────────────────────────────────────────────── */
.search-bar { display: flex; gap: 8px; margin-bottom: 20px; }
.search-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
}
.search-input:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* ── LOADING / EMPTY ─────────────────────────────────────────────────────────── */
.loading { color: var(--muted); font-size: 14px; padding: 48px; text-align: center; }
.empty { color: var(--muted); font-size: 14px; padding: 48px; text-align: center; }

/* ── TOAST ───────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 20px;
  font-size: 13px;
  z-index: 999;
  box-shadow: var(--shadow);
  animation: slideUp 0.2s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── TABLET ──────────────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── MOBILE ──────────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Sidebar slides in from left */
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }

  /* Top bar visible */
  .topbar { display: flex; }

  /* Main shifts for topbar */
  .main {
    margin-left: 0;
    padding: 76px 16px 24px;
  }

  /* Cards */
  .cards-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .cards-grid-mp { grid-template-columns: 1fr 1fr; gap: 12px; }
  .card { padding: 16px; }
  .card-value { font-size: 20px; }

  /* Page header */
  .page-header { margin-bottom: 16px; }
  .page-header h1 { font-size: 18px; }
  .btn { padding: 7px 12px; font-size: 12px; }

  /* Filter bar */
  .filter-bar { gap: 5px; margin-bottom: 14px; }
  .filter-btn { padding: 5px 10px; font-size: 11px; }

  /* Table */
  .table-header { padding: 12px 14px; }
  .filters { width: 100%; }
  .filter-select { flex: 1; font-size: 12px; }
  table { font-size: 12px; }
  thead th { padding: 10px 12px; }
  tbody td { padding: 10px 12px; }

  /* Chart */
  .chart-card { padding: 16px; }

  /* Search */
  .search-bar { flex-direction: column; }

  /* Toast */
  .toast { bottom: 16px; right: 16px; left: 16px; text-align: center; }

  /* Connections */
  .connections-grid { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .cards-grid { grid-template-columns: 1fr; }
  .cards-grid-mp { grid-template-columns: 1fr; }
}
