:root {
  --bg: #f3f2ef;
  --card: #ffffff;
  --ink: #1e1e1e;
  --muted: #6f6f6f;
  --accent: #2563eb;
  --accent-2: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 18px 45px rgba(33, 33, 33, 0.12);
  --radius: 16px;
  --radius-sm: 12px;
  --stroke: #e2e2e2;
}

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

body {
  font-family: "Montserrat", sans-serif;
  background: radial-gradient(circle at top, #ffffff 0%, #f1f0ed 45%, #ebebea 100%);
  color: var(--ink);
  padding: 12px;
  min-width: 0;
}

@media (min-width: 600px) {
  body {
    padding: 20px;
  }
}

@media (min-width: 1024px) {
  body {
    padding: 28px;
  }
}

body,
button,
input,
select,
textarea,
table {
  font-family: "Montserrat", sans-serif;
}

.app {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 1024px) {
  .app {
    gap: 24px;
  }
}

/* ==========================================
   TOPBAR
   ========================================== */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  gap: 12px;
  flex-wrap: wrap;
}

@media (min-width: 600px) {
  .topbar {
    padding: 18px 24px;
    flex-wrap: nowrap;
  }
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
  flex: 1;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
}

@media (min-width: 600px) {
  .brand-logo {
    width: 46px;
    height: 46px;
  }
}

.brand-title {
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 600px) {
  .brand-title {
    font-size: 20px;
  }
}

.brand-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.actions {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;
}

@media (min-width: 600px) {
  .actions {
    width: auto;
    flex-shrink: 0;
  }
}

.search input {
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  width: 100%;
  font-size: 13px;
}

@media (min-width: 600px) {
  .search input {
    width: 220px;
  }
}

@media (min-width: 1024px) {
  .search input {
    width: 280px;
  }
}

.btn {
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: #f7f7f7;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #ffffff;
}

.btn.ghost {
  background: transparent;
}

/* ==========================================
   FILTERS
   ========================================== */
.filters {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  background: var(--card);
  padding: 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

@media (min-width: 480px) {
  .filters {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
  }
}

.filter {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.filter select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236f6f6f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-color: #f9f9f9;
  padding: 10px 36px 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
}

.filter select:hover {
  border-color: var(--accent);
  background-color: #fff;
}

.filter select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ==========================================
   KPIs
   ========================================== */
.kpis {
  grid-column: 1 / 2;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

@media (min-width: 600px) {
  .kpis {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
  }
}

@media (min-width: 1024px) {
  .kpis {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

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

@media (min-width: 600px) {
  .kpi {
    padding: 16px;
  }
}

.kpi::after {
  content: "";
  position: absolute;
  right: -40px;
  top: -40px;
  width: 120px;
  height: 120px;
  border-radius: 40px;
  background: rgba(37, 99, 235, 0.08);
}

.kpi-label {
  font-size: 11px;
  color: var(--muted);
}

@media (min-width: 600px) {
  .kpi-label {
    font-size: 12px;
  }
}

.kpi-value {
  font-size: 22px;
  font-weight: 700;
  margin: 6px 0 4px;
}

@media (min-width: 600px) {
  .kpi-value {
    font-size: 26px;
    margin: 8px 0 6px;
  }
}

.kpi-trend {
  font-size: 11px;
  font-weight: 600;
}

.kpi-trend.up {
  color: var(--accent-2);
}

.kpi-trend.down {
  color: var(--danger);
}

.kpi-progress {
  border-top: 4px solid var(--accent);
}

.kpi-ontime {
  border-top: 4px solid var(--accent-2);
}

.kpi-late {
  border-top: 4px solid var(--danger);
}

.kpi-share {
  border-top: 4px solid var(--accent-2);
}

.kpi-share.alt {
  border-top: 4px solid var(--danger);
}

.kpi-meter {
  margin-top: 6px;
  height: 6px;
  background: #f0f0f0;
  border-radius: 999px;
  overflow: hidden;
}

.kpi-share.alt .meter-bar {
  background: var(--danger);
}

.meter-bar {
  height: 100%;
  background: var(--accent-2);
}

/* ==========================================
   CONTENT / PANELS
   ========================================== */
.content {
  grid-column: 1 / 2;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

@media (min-width: 1024px) {
  .content {
    gap: 20px;
  }
}

.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-width: 0;
}

.panel-head {
  padding: 14px 16px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

@media (min-width: 600px) {
  .panel-head {
    padding: 18px 22px 10px;
  }
}

.panel-head h2 {
  font-size: 16px;
  font-weight: 600;
}

@media (min-width: 600px) {
  .panel-head h2 {
    font-size: 18px;
  }
}

.panel-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.panel-body {
  padding: 8px 12px 16px;
}

@media (min-width: 600px) {
  .panel-body {
    padding: 10px 18px 22px;
  }
}

/* ==========================================
   CHART GRID
   ========================================== */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 720px) {
  .chart-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }
}

.chart-card {
  background: var(--card);
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--stroke);
  height: 280px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

@media (min-width: 480px) {
  .chart-card {
    height: 320px;
  }
}

@media (min-width: 720px) {
  .chart-card {
    height: 360px;
    padding: 16px;
  }
}

.chart-title {
  font-size: 12px;
  color: var(--ink);
  margin-bottom: 10px;
  font-weight: 600;
  flex-shrink: 0;
}

@media (min-width: 600px) {
  .chart-title {
    font-size: 13px;
    margin-bottom: 12px;
  }
}

.chart-wrapper {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
}

.chart-wrapper canvas {
  position: relative;
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* ==========================================
   TABLE
   ========================================== */
.table-panel .panel-body {
  padding-top: 0;
}

.table-wrap {
  max-height: 360px;
  overflow: auto;
  border: 1px solid #ededed;
  border-radius: 12px;
  -webkit-overflow-scrolling: touch;
}

.table-wrap table {
  width: 100%;
  min-width: 600px;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid #f0f0f0;
  white-space: nowrap;
}

@media (min-width: 600px) {
  th,
  td {
    padding: 10px 12px;
  }
}

th {
  position: sticky;
  top: 0;
  background: #fafafa;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.03em;
  z-index: 1;
}

tr:hover td {
  background: #f6f8ff;
}

/* ==========================================
   STATUS PILLS
   ========================================== */
.status-pill {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: #ecfdf3;
  color: #118b5a;
  white-space: nowrap;
}

.status-pill.warning {
  background: #fff3d7;
  color: #b45309;
}

.status-pill.danger {
  background: #fee2e2;
  color: #b91c1c;
}

/* ==========================================
   LEGEND
   ========================================== */
.legend {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

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

.dot.green {
  background: var(--accent-2);
}

.dot.yellow {
  background: var(--warning);
}

.dot.red {
  background: var(--danger);
}

/* ==========================================
   RAIL (sidebar cards – legacy, mantido)
   ========================================== */
.rail {
  grid-column: 2 / 3;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.rail-card {
  background: var(--card);
  border-radius: 20px;
  padding: 16px 12px;
  box-shadow: var(--shadow);
  text-align: center;
  display: grid;
  gap: 6px;
}

.rail-title {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.rail-number {
  font-size: 24px;
  font-weight: 700;
}

.rail-sub {
  font-size: 12px;
  color: var(--muted);
}

.rail-progress {
  height: 120px;
  background: #f1f1f1;
  border-radius: 12px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}

.rail-progress span {
  width: 100%;
  background: linear-gradient(180deg, #34d399, #059669);
}

.rail-progress.warning span {
  background: linear-gradient(180deg, #fbbf24, #f59e0b);
}

.rail-progress.danger span {
  background: linear-gradient(180deg, #f87171, #dc2626);
}

/* ==========================================
   FOOTER
   ========================================== */
.footer {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
  padding: 6px 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  background: #fff;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid #ededed;
  white-space: nowrap;
}

/* ==========================================
   TABELA MOBILE COMPACTA
   ========================================== */
@media (max-width: 599px) {
  .table-wrap table {
    font-size: 11px;
    min-width: 0;
    width: 100%;
  }

  th,
  td {
    padding: 7px 8px;
    white-space: normal;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Esconder colunas menos essenciais no mobile */
  th:nth-child(1),
  td:nth-child(1) {
    display: none; /* ID */
  }

  th:nth-child(5),
  td:nth-child(5) {
    display: none; /* Criador */
  }

  th:nth-child(8),
  td:nth-child(8) {
    display: none; /* Situacao */
  }

  .table-wrap {
    max-height: 300px;
    border-radius: 10px;
  }

  .status-pill {
    font-size: 10px;
    padding: 2px 6px;
  }
}

/* Scroll horizontal suave na tabela em mobile */
@media (max-width: 599px) {
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}
