@import url("https://fonts.googleapis.com/css2?family=Lato:wght@300;400;700;900&display=swap");
@import url("./design-system.css");

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

body {
  font-family: var(--font-sans);
  background: radial-gradient(circle at top left, #f7f7f7 0%, var(--bg) 42%, #ececec 100%);
  color: var(--text);
  min-height: 100vh;
}

.dashboard {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, #222b37 0%, #1c2430 70%);
  color: var(--text-invert);
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: var(--gap-xl);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 900;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.brand-logo {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(14, 143, 154, 0.25);
}

.nav {
  display: grid;
  gap: var(--gap-sm);
}

.nav .nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: transparent;
  border: none;
  color: var(--text-invert);
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: background 0.2s ease;
  text-decoration: none;
}

.nav .nav-link.active,
.nav .nav-link:hover {
  background: rgba(255, 255, 255, 0.08);
}

.sidebar .divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
}

.sidebar small {
  color: rgba(255, 255, 255, 0.6);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.main {
  padding: 26px 34px 36px;
  display: grid;
  gap: var(--gap-lg);
}

.topbar {
  background: #d8d8d8;
  border-radius: var(--radius-md);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar .title {
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ink);
}

.filters {
  display: flex;
  gap: var(--gap-sm);
  align-items: center;
}

.filters select,
.filters input {
  border-radius: 999px;
  border: none;
  padding: 8px 14px;
  font-weight: 600;
  background: #f4f4f4;
  color: var(--text);
}

.ghost-btn {
  border: 1px solid #c2c2c2;
  background: transparent;
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.2s ease;
}

.ghost-btn:hover {
  background: #ececec;
}

.grid {
  display: grid;
  gap: var(--gap-md);
}

.grid.cards {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

body.page-dashboard #kpi-grid.grid.cards {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

body.page-dashboard #kpi-grid .card {
  min-height: 148px;
  padding: 18px;
}

body.page-dashboard #kpi-grid .card .value {
  font-size: clamp(2rem, 2.4vw, 3rem);
  line-height: 1.12;
}

body.page-dashboard #kpi-grid .card .trend {
  font-size: 1.05rem;
}

body.page-dashboard .grid.content {
  align-items: start;
}

body.page-accumulated #kpi-grid.grid.cards {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
}

body.page-accumulated #kpi-grid .card {
  min-height: 150px;
  padding: 20px;
}

body.page-accumulated #kpi-grid .card .value {
  font-size: clamp(1.6rem, 2.2vw, 2.6rem);
  line-height: 1.12;
}

body.page-dashboard #top-products {
  table-layout: fixed;
}

body.page-dashboard #top-products th {
  letter-spacing: 0.4px;
  font-size: 0.78rem;
  white-space: nowrap;
}

body.page-dashboard #top-products th:nth-child(1),
body.page-dashboard #top-products td:nth-child(1) {
  width: 48%;
}

body.page-dashboard #top-products th:nth-child(2),
body.page-dashboard #top-products td:nth-child(2) {
  width: 27%;
  white-space: nowrap;
}

body.page-dashboard #top-products th:nth-child(3),
body.page-dashboard #top-products td:nth-child(3) {
  width: 25%;
  min-width: 120px;
  white-space: nowrap;
}

body.page-dashboard #top-products td:nth-child(1) {
  word-break: break-word;
}

body.page-dashboard .dashboard-top-products-scroll {
  max-height: 360px;
  overflow: auto;
  border: 1px solid #eef1f5;
  border-radius: 10px;
}

body.page-dashboard .dashboard-top-products-scroll .table {
  margin: 0;
}

body.page-dashboard .dashboard-top-products-scroll .table th {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

body.page-dashboard .dashboard-top-products-row {
  margin-top: -4px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.card h4 {
  font-size: 0.9rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.card .value {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--ink);
}

.card .trend {
  font-size: 0.85rem;
  color: var(--accent-700);
  font-weight: 600;
}

.goal-details {
  display: grid;
  gap: 4px;
  margin-top: 8px;
}

.goal-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.goal-form input {
  flex: 1;
  border-radius: 10px;
  border: 1px solid #d7dde7;
  padding: 8px 10px;
}

.goal-form .primary-btn {
  width: auto;
  margin-top: 0;
  padding: 8px 12px;
  border-radius: 10px;
}

.card .badge {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--primary);
  color: #fff;
  font-size: 0.7rem;
  padding: 4px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.form-grid {
  display: grid;
  gap: 10px;
}

.form-grid label {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.form-grid select,
.form-grid input {
  border-radius: var(--radius-sm);
  border: 1px solid #d4d4d4;
  padding: 8px 12px;
  font-size: 0.95rem;
}

.checkbox-list {
  display: grid;
  gap: 8px;
  margin: 12px 0;
  max-height: 220px;
  overflow-y: auto;
}

.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--ink);
}

.grid.content {
  grid-template-columns: 2fr 1fr;
  align-items: stretch;
}

.grid.content.dashboard-single {
  grid-template-columns: 1fr;
}

.panel {
  display: grid;
  gap: var(--gap-md);
}

.panel .card {
  min-height: 180px;
}

.progress-list {
  display: grid;
  gap: 14px;
}

.progress-row {
  display: grid;
  gap: 6px;
}

.progress-row .label {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  color: var(--ink);
}

.progress-bar {
  height: 10px;
  border-radius: 999px;
  background: #d6d6d6;
  overflow: hidden;
}

.progress-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.progress-bar .accent {
  background: var(--accent);
}

.progress-bar .primary {
  background: var(--primary);
}

.chart {
  width: 100%;
  height: 220px;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 12px 10px;
  text-align: left;
  font-size: 0.9rem;
  border-bottom: 1px solid #ececec;
}

.table th {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.table tr:hover {
  background: #f5f5f5;
}

.text-block {
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}

.toggle-list {
  display: grid;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.toggle-list label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.footer {
  color: var(--text-muted);
  text-align: right;
  font-size: 0.85rem;
}

@media (max-width: 1024px) {
  .dashboard {
    grid-template-columns: 1fr;
  }

  .sidebar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .nav {
    display: none;
  }

  .grid.content {
    grid-template-columns: 1fr;
  }

  body.page-dashboard .dashboard-top-products-row {
    margin-top: 0;
  }
}

@media (max-width: 1360px) {
  body.page-dashboard .dashboard-top-products-row {
    margin-top: 0;
  }
}

@media (max-width: 680px) {
  .topbar {
    flex-direction: column;
    gap: var(--gap-sm);
    align-items: flex-start;
  }

  .filters {
    flex-wrap: wrap;
  }

  .main {
    padding: 20px;
  }
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(31, 39, 51, 0.65);
  display: grid;
  place-items: center;
  z-index: 20;
}

.overlay.hidden {
  display: none;
}

.login-card {
  background: linear-gradient(160deg, #ffffff 0%, #f6f8fb 100%);
  padding: 30px;
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(23, 31, 45, 0.25);
  border: 1px solid rgba(14, 143, 154, 0.15);
  width: min(420px, 90vw);
  display: grid;
  gap: 10px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.login-icon {
  width: 42px;
  height: 42px;
  object-fit: contain;
}

.login-brand strong {
  display: block;
  font-size: 1rem;
  color: #1f2733;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.login-brand small {
  display: block;
  color: #697281;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.login-card h2 {
  font-size: 1.4rem;
  color: #1f2733;
}

.login-card p {
  color: #5e6673;
}

#login-form {
  display: grid;
  gap: 8px;
}

.login-card label {
  display: block;
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  margin-top: 4px;
}

.login-card input {
  width: 100%;
  border: 1px solid #d7dde7;
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 1rem;
  background: #fff;
}

.login-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 143, 154, 0.15);
}

.primary-btn {
  background: linear-gradient(135deg, var(--primary) 0%, #ff6b63 100%);
  border: none;
  color: #fff;
  padding: 11px 16px;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
  width: 100%;
}

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

.error-text {
  color: var(--primary);
  font-size: 0.9rem;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card,
.topbar {
  animation: fadeUp 0.4s ease both;
}

body.page-accumulated .accumulated-main-charts {
  grid-template-columns: 1fr;
}

body.page-accumulated .accumulated-secondary-charts {
  grid-template-columns: 1fr;
}

body.page-accumulated .accumulated-main-charts .panel-duo {
  grid-template-columns: repeat(2, minmax(320px, 1fr));
}

body.page-accumulated .accumulated-secondary-charts .panel-duo {
  grid-template-columns: repeat(2, minmax(320px, 1fr));
}

body.page-accumulated .accumulated-main-charts .panel-duo .card,
body.page-accumulated .accumulated-secondary-charts .card {
  min-height: 280px;
}

body.page-accumulated .chart {
  height: 280px;
}

body.page-accumulated #daily-sales.chart {
  height: 300px;
}

body.page-accumulated .table {
  table-layout: fixed;
}

body.page-accumulated .table .cell-product-name {
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.page-accumulated .table .cell-value {
  white-space: nowrap;
  text-align: right;
  width: 180px;
}

body.page-accumulated .card-top-products-accum h4 {
  text-align: center;
}

body.page-accumulated #top-products {
  table-layout: fixed;
}

body.page-accumulated #top-products th:nth-child(1),
body.page-accumulated #top-products td:nth-child(1) {
  width: 72%;
}

body.page-accumulated #top-products th:nth-child(2),
body.page-accumulated #top-products td:nth-child(2) {
  width: 28%;
  text-align: right;
  white-space: nowrap;
}

body.page-accumulated .table-scroll {
  max-height: 330px;
  overflow: auto;
  border: 1px solid #eef1f5;
  border-radius: 10px;
}

body.page-accumulated .table-scroll .table {
  margin: 0;
}

body.page-accumulated .table-scroll .table th {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

body.page-services #kpi-grid.grid.cards {
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
}

body.page-services #kpi-grid .card {
  min-height: 150px;
}

body.page-services .grid.content.services-main-charts {
  grid-template-columns: 1fr;
}

body.page-services .services-main-charts .panel-duo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(460px, 1fr));
  gap: var(--gap-md);
}

body.page-services .services-main-charts .panel-duo > .card:first-child {
  grid-column: 1 / -1;
}

body.page-services .chart {
  height: 310px;
}

body.page-services #services-monthly.chart {
  height: 300px;
}

body.page-services #resumo-clientes {
  table-layout: auto;
  min-width: 0;
}

body.page-services #resumo-clientes th:nth-child(1),
body.page-services #resumo-clientes td:nth-child(1) {
  width: 46%;
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.page-services #resumo-clientes th:nth-child(2),
body.page-services #resumo-clientes td:nth-child(2),
body.page-services #resumo-clientes th:nth-child(3),
body.page-services #resumo-clientes td:nth-child(3),
body.page-services #resumo-clientes th:nth-child(4),
body.page-services #resumo-clientes td:nth-child(4),
body.page-services #resumo-clientes th:nth-child(5),
body.page-services #resumo-clientes td:nth-child(5) {
  width: 13.5%;
  text-align: right;
  white-space: nowrap;
}

body.page-services #resumo-clientes th {
  white-space: nowrap;
}

body.page-services .table-scroll {
  max-height: 380px;
  overflow: auto;
  border: 1px solid #eef1f5;
  border-radius: 10px;
}

body.page-services .table-scroll .table {
  margin: 0;
}

body.page-services .table-scroll .table th {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

body.page-services .services-summary-grid {
  grid-template-columns: 1fr;
}

body.page-services .services-summary-grid .panel:first-child {
  grid-template-columns: repeat(2, minmax(360px, 1fr));
}

@media (max-width: 1200px) {
  body.page-services .services-summary-grid .panel:first-child {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  body.page-services #resumo-clientes thead {
    display: none;
  }

  body.page-services #resumo-clientes,
  body.page-services #resumo-clientes tbody,
  body.page-services #resumo-clientes tr,
  body.page-services #resumo-clientes td {
    display: block;
    width: 100%;
  }

  body.page-services #resumo-clientes tr {
    border: 1px solid #e7ebf1;
    border-radius: 10px;
    margin-bottom: 10px;
    overflow: hidden;
  }

  body.page-services #resumo-clientes td {
    border-bottom: 1px solid #eef1f5;
    text-align: left;
    white-space: normal;
    padding: 10px 12px;
    max-width: none;
    overflow: visible;
    text-overflow: clip;
  }

  body.page-services #resumo-clientes td:last-child {
    border-bottom: 0;
  }

  body.page-services #resumo-clientes td::before {
    content: attr(data-label) ": ";
    display: inline-block;
    min-width: 96px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.74rem;
    letter-spacing: 0.4px;
    margin-right: 6px;
  }
}

@media (max-width: 1200px) {
  body.page-services .services-main-charts .panel-duo {
    grid-template-columns: 1fr;
  }

  body.page-services .services-main-charts .panel-duo > .card:first-child {
    grid-column: auto;
  }
}

@media (max-width: 1200px) {
  body.page-accumulated .accumulated-main-charts .panel-duo,
  body.page-accumulated .accumulated-secondary-charts .panel-duo {
    grid-template-columns: 1fr;
  }
}

/* Evita quebra visual de KPI com valores longos na página mensal. */
body.page-monthly #kpi-grid .card {
  min-width: 0;
}

body.page-monthly #kpi-grid {
  grid-template-columns: repeat(5, minmax(220px, 1fr));
}

body.page-monthly #kpi-grid .card:first-child {
  grid-column: span 2;
}

body.page-monthly #kpi-grid .card .value {
  font-size: clamp(1.5rem, 1.9vw, 2.2rem);
  line-height: 1.1;
  overflow-wrap: normal;
  word-break: normal;
  white-space: normal;
  max-width: 100%;
}

body.page-monthly #kpi-grid .card .value.value-currency {
  white-space: nowrap;
}

body.page-monthly #kpi-grid .card .value.value-long {
  font-size: clamp(1.35rem, 1.7vw, 1.95rem);
}

body.page-monthly .monthly-overview {
  grid-template-columns: 2fr 1fr;
}

body.page-monthly .monthly-report {
  grid-template-columns: 1fr;
}

body.page-monthly .monthly-report .panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: var(--gap-md);
}

body.page-monthly .monthly-report > .panel:last-child {
  grid-template-columns: 1fr;
}

body.page-monthly .monthly-report .card-daily-main,
body.page-monthly .monthly-report .card-top-products,
body.page-monthly .monthly-report .card-histogram {
  grid-column: 1 / -1;
}

body.page-monthly .monthly-report .card-histogram .chart {
  height: 280px;
}

body.page-monthly .monthly-report .card .text-block {
  font-size: 0.92rem;
}

body.page-monthly #pareto-chart.chart {
  height: 420px;
  margin-bottom: 0;
}

@media (max-width: 1400px) {
  body.page-monthly #pareto-chart.chart {
    height: 360px;
  }
}

@media (max-width: 1400px) {
  body.page-monthly #kpi-grid {
    grid-template-columns: repeat(4, minmax(210px, 1fr));
  }
}

@media (max-width: 1100px) {
  body.page-monthly #kpi-grid {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }

  body.page-monthly #kpi-grid .card:first-child {
    grid-column: span 2;
  }

  body.page-monthly .monthly-overview {
    grid-template-columns: 1fr;
  }

  body.page-monthly .monthly-report .panel {
    grid-template-columns: 1fr;
  }

  body.page-monthly .monthly-report .card-daily-main,
  body.page-monthly .monthly-report .card-top-products,
  body.page-monthly .monthly-report .card-histogram {
    grid-column: auto;
  }
}

@media (max-width: 760px) {
  body.page-monthly #kpi-grid {
    grid-template-columns: 1fr;
  }

  body.page-monthly #kpi-grid .card:first-child {
    grid-column: auto;
  }
}

body.page-admin .grid.content.admin-management {
  grid-template-columns: minmax(620px, 1.7fr) minmax(360px, 1fr);
}

body.page-admin .grid.content.admin-audit {
  grid-template-columns: repeat(2, minmax(420px, 1fr));
}

body.page-admin .panel .card {
  min-height: 0;
}

body.page-admin .admin-table-scroll {
  max-height: 360px;
  overflow: auto;
  border: 1px solid #eef1f5;
  border-radius: 10px;
  margin-bottom: 10px;
}

body.page-admin .admin-table-scroll .table {
  margin: 0;
}

body.page-admin .admin-table-scroll .table th {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

body.page-admin .table td,
body.page-admin .table th {
  vertical-align: middle;
}

body.page-admin .table .cell-ellipsis {
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.page-admin .table .cell-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  white-space: nowrap;
}

body.page-admin .tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  padding: 4px 9px;
  text-transform: uppercase;
}

body.page-admin .tag-role {
  background: #eef3fa;
  color: #2e4158;
}

body.page-admin .tag-status {
  background: #eef1f5;
  color: #3d4c60;
}

body.page-admin .tag-status-active {
  background: #e5f7ef;
  color: #176c46;
}

body.page-admin .tag-status-pending {
  background: #fff4db;
  color: #825600;
}

body.page-admin .tag-status-disabled {
  background: #fdebec;
  color: #902b30;
}

body.page-admin .form-grid {
  gap: 8px;
}

body.page-admin .form-grid .primary-btn {
  width: 100%;
}

body.page-admin #companies-list {
  max-height: 280px;
  padding-right: 4px;
}

body.page-admin #companies-list label {
  background: #f7f9fc;
  border: 1px solid #e8edf3;
  border-radius: 8px;
  padding: 8px 10px;
}

@media (max-width: 1320px) {
  body.page-admin .grid.content.admin-management,
  body.page-admin .grid.content.admin-audit {
    grid-template-columns: 1fr;
  }
}
