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

:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #f6f7f9;
  color: #1b1f24;
  font-size: 14px;
}

body { margin: 0; }

/* ── App shell ── */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
  border-bottom: 1px solid #e4e7ec;
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 28px;
}
.app-logo {
  font-size: 15px;
  font-weight: 800;
  color: #1b1f24;
  letter-spacing: -.3px;
  padding: 16px 0;
  margin-right: 28px;
  white-space: nowrap;
}
.app-logo span { color: #16a34a; }

/* ── Tabs (top-bar style) ── */
.tab-nav {
  display: flex;
  gap: 0;
  flex: 1;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2.5px solid transparent;
  padding: 16px 18px;
  font-size: 13px;
  font-weight: 600;
  color: #667085;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tab-btn.active  { color: #16a34a; border-bottom-color: #16a34a; }
.tab-btn:hover:not(.active) { color: #344054; }

/* ── Page content ── */
.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 28px 48px;
}

/* ── Page header ── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.page-title  { font-size: 20px; font-weight: 700; margin: 0 0 3px; }
.page-subtitle { color: #667085; margin: 0; font-size: 13px; }
.header-actions { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
  transition: background .12s, border-color .12s;
}
.btn-outline  { background: #fff; border-color: #d0d5dd; color: #344054; }
.btn-outline:hover { background: #f9fafb; }
.btn-primary  { background: #16a34a; color: #fff; border-color: #16a34a; }
.btn-primary:hover { background: #15803d; }
.btn-excel    { background: #16a34a; color: #fff; border-color: #16a34a; }
.btn-excel:hover { background: #15803d; }
.btn-danger   { background: #fff; border-color: #fca5a5; color: #b42318; }
.btn-danger:hover { background: #fef2f2; }
.btn:disabled { opacity: 0.55; cursor: wait; }

/* ── Stat cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: #fff;
  border: 1.5px solid #e4e7ec;
  border-radius: 10px;
  padding: 16px 18px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
  user-select: none;
}
.stat-card:hover  { border-color: #b0b8c4; box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.stat-card.active { border-color: #16a34a; border-width: 2px; box-shadow: 0 0 0 3px #dcfce7; }
.stat-label {
  font-size: 11px; font-weight: 600; color: #667085;
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px;
}
.stat-row { display: flex; align-items: center; justify-content: space-between; }
.stat-value { font-size: 28px; font-weight: 700; }
.stat-icon  { color: #98a2b3; }
.c-default  { color: #1b1f24; }
.c-green    { color: #027a48; }
.c-red      { color: #b42318; }
.c-orange   { color: #b45309; }

/* ── Filters bar ── */
.filters-bar {
  background: #fff;
  border: 1px solid #e4e7ec;
  border-radius: 10px;
  padding: 12px 16px;
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.search-wrap { position: relative; flex: 1; min-width: 200px; }
.search-input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
  color: #1b1f24;
  outline: none;
}
.search-input:focus { border-color: #86efac; box-shadow: 0 0 0 3px #dcfce7; }
.search-icon {
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%); color: #98a2b3; pointer-events: none;
}
.filter-pill {
  padding: 7px 12px;
  border: 1px solid #d0d5dd; border-radius: 8px;
  background: #fff; color: #344054; font-size: 13px;
  cursor: pointer; outline: none; appearance: none; -webkit-appearance: none;
  white-space: nowrap;
}
.filter-pill:focus { border-color: #86efac; box-shadow: 0 0 0 3px #dcfce7; }
.check-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: #344054; cursor: pointer; white-space: nowrap; user-select: none;
}
.check-label input[type="checkbox"] { width: 15px; height: 15px; accent-color: #16a34a; cursor: pointer; }

/* ── Table ── */
.table-wrap {
  background: #fff; border: 1px solid #e4e7ec;
  border-radius: 10px; overflow: hidden;
}
.table-topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid #e4e7ec;
}
.table-count { color: #667085; font-size: 13px; }
table { width: 100%; border-collapse: collapse; }
thead tr { border-bottom: 1px solid #e4e7ec; }
th {
  padding: 10px 14px; font-size: 11px; font-weight: 600;
  color: #667085; text-transform: uppercase; letter-spacing: .4px;
  text-align: left; background: #fafafa; white-space: nowrap;
}
td { padding: 13px 14px; vertical-align: middle; border-bottom: 1px solid #f2f4f7; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafafa; }
th.num, td.num { text-align: right; }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 12px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-green   { background: #dcfce7; color: #15803d; }
.badge-blue    { background: #dbeafe; color: #1d4ed8; }
.badge-orange  { background: #ffedd5; color: #c2410c; }
.badge-purple  { background: #ede9fe; color: #6d28d9; }
.badge-teal    { background: #ccfbf1; color: #0f766e; }
.badge-red     { background: #fee2e2; color: #b91c1c; }
.badge-gray    { background: #f2f4f7; color: #475467; }
.badge-yellow  { background: #fef9c3; color: #a16207; }

.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; flex-shrink: 0; }

.cell-title { font-weight: 600; color: #1b1f24; }
.cell-sub   { font-size: 12px; color: #667085; margin-top: 2px; }
.tag-linked {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; color: #344054; background: #f2f4f7;
  border: 1px solid #d0d5dd; border-radius: 4px; padding: 2px 7px; margin-top: 4px;
}
.sla-ok   { color: #027a48; font-size: 13px; font-weight: 500; }
.sla-warn { color: #b45309; font-size: 13px; font-weight: 500; }

.actions { display: flex; gap: 4px; justify-content: flex-end; }
.action-btn {
  border: none; background: transparent; cursor: pointer;
  color: #98a2b3; padding: 5px; border-radius: 5px;
  display: inline-flex; align-items: center;
  transition: background .12s, color .12s;
}
.action-btn:hover { background: #f2f4f7; color: #344054; }
td.cb, th.cb { width: 38px; }
input[type="checkbox"] { accent-color: #16a34a; cursor: pointer; }
.empty-state { text-align: center; padding: 56px 24px; color: #667085; }
.empty-state svg { margin-bottom: 12px; opacity: .4; }
.empty-state p { margin: 0; font-size: 14px; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: #1d2939; color: #fff; border-radius: 8px;
  padding: 14px 18px; font-size: 13px; max-width: 380px;
  z-index: 500; box-shadow: 0 8px 24px rgba(0,0,0,.18);
  display: none; line-height: 1.5;
}
.toast.show    { display: block; }
.toast.error   { background: #b42318; }
.toast.success { background: #027a48; }

/* ── Drawer ── */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35); z-index: 200; display: none;
}
.drawer-backdrop.open { display: block; }
.drawer {
  position: fixed; top: 0; right: 0;
  width: 500px; max-width: 100vw; height: 100vh;
  background: #fff; z-index: 210;
  box-shadow: -4px 0 32px rgba(0,0,0,.14);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .25s ease;
}
.drawer.open { transform: translateX(0); }
.drawer-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid #e4e7ec; flex-shrink: 0;
}
.drawer-title  { font-weight: 700; font-size: 15px; }
.drawer-close  {
  border: none; background: transparent; cursor: pointer;
  color: #667085; font-size: 22px; line-height: 1; padding: 2px 6px; border-radius: 4px;
}
.drawer-close:hover { background: #f2f4f7; }
.drawer-body   { overflow-y: auto; padding: 20px; flex: 1; }
.detail-section { margin-bottom: 20px; }
.detail-section-title {
  font-size: 12px; font-weight: 600; color: #667085;
  text-transform: uppercase; letter-spacing: .5px;
  margin: 0 0 10px; padding-bottom: 6px; border-bottom: 1px solid #f2f4f7;
}
.detail-grid { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; font-size: 13px; }
.detail-grid dt { color: #667085; }
.detail-grid dd { margin: 0; word-break: break-word; font-weight: 500; }
.items-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.items-table th { padding: 7px 10px; font-size: 11px; text-transform: uppercase; color: #667085; border-bottom: 1px solid #e4e7ec; text-align: left; }
.items-table td { padding: 9px 10px; border-bottom: 1px solid #f2f4f7; }
.items-table tbody tr:last-child td { border-bottom: none; }
.raw-text {
  max-height: 220px; overflow-y: auto;
  background: #f6f7f9; border: 1px solid #e4e7ec; border-radius: 6px;
  padding: 10px; font-size: 12px; white-space: pre-wrap;
  font-family: "Cascadia Code","Fira Mono",Consolas,monospace; margin: 0; color: #344054;
}
.drawer-action-bar {
  padding: 14px 20px; border-top: 1px solid #e4e7ec;
  display: flex; gap: 10px; flex-shrink: 0;
}
#pdf-file { display: none; }
#excel-import-file { display: none; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 400;
  display: none; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff; border-radius: 12px;
  width: 520px; max-width: calc(100vw - 32px);
  box-shadow: 0 24px 48px rgba(0,0,0,.22);
  display: flex; flex-direction: column; max-height: 90vh;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 20px; border-bottom: 1px solid #e4e7ec;
}
.modal-title { font-weight: 700; font-size: 15px; }
.modal-body  { padding: 20px; overflow-y: auto; }
.modal-footer {
  padding: 14px 20px; border-top: 1px solid #e4e7ec;
  display: flex; gap: 10px; justify-content: flex-end;
}

/* ── Form fields ── */
.form-group  { margin-bottom: 16px; }
.form-label  { display: block; font-size: 12px; font-weight: 600; color: #344054; margin-bottom: 6px; }
.form-input, .form-select {
  width: 100%; padding: 9px 12px;
  border: 1px solid #d0d5dd; border-radius: 7px;
  font-size: 13px; color: #1b1f24; background: #fff; outline: none;
  transition: border-color .12s;
}
.form-input:focus, .form-select:focus { border-color: #86efac; box-shadow: 0 0 0 3px #dcfce7; }
.form-row    { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Analytics ── */
.an-filters {
  background: #fff; border: 1px solid #e4e7ec; border-radius: 10px;
  padding: 14px 16px; display: flex; gap: 16px; align-items: flex-end;
  flex-wrap: wrap; margin-bottom: 20px;
}
.an-filter-group { display: flex; flex-direction: column; gap: 4px; }
.an-label { font-size: 11px; font-weight: 600; color: #667085; text-transform: uppercase; letter-spacing: .04em; }
.an-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.an-card  {
  background: #fff; border: 1px solid #e4e7ec; border-radius: 10px; padding: 18px;
}
.an-card-title {
  font-size: 12px; font-weight: 700; color: #667085;
  text-transform: uppercase; letter-spacing: .4px; margin-bottom: 14px;
}
.an-stats-grid {
  display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; margin-bottom: 20px;
}
.an-kpi {
  background: #fff; border: 1px solid #e4e7ec; border-radius: 10px;
  padding: 18px 20px;
}
.an-kpi-label { font-size: 11px; font-weight: 600; color: #667085; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 8px; }
.an-kpi-value { font-size: 26px; font-weight: 700; color: #1b1f24; line-height: 1; }
.an-kpi-value.green { color: #15803d; }

/* Config tabs (vendedores/clientes) */
.config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.config-card {
  background: #fff; border: 1px solid #e4e7ec; border-radius: 10px; overflow: hidden;
}
.config-card-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid #e4e7ec; background: #fafafa;
}
.config-card-title { font-size: 13px; font-weight: 700; color: #344054; }

@media (max-width: 1100px) { .stats-grid { grid-template-columns: repeat(3,1fr); } .an-stats-grid { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 900px)  { .an-grid { grid-template-columns: 1fr; } .config-grid { grid-template-columns: 1fr; } }
@media (max-width: 720px)  { .stats-grid { grid-template-columns: repeat(2,1fr); } .page-header { flex-direction: column; } .drawer { width: 100vw; } }
