:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --sidebar: #0f172a;
  --sidebar-muted: #94a3b8;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---- Login ---- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 340px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
}
.login-card h1 {
  margin: 0 0 4px;
}
.login-card input {
  width: 100%;
  margin: 10px 0;
}
.login-card button {
  width: 100%;
}

/* ---- Layout com sidebar ---- */
.layout {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 188px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: transform 0.2s ease;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 14px 16px;
}
.sidebar .brand {
  font-weight: 700;
  font-size: 16px;
}
.nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--sidebar-muted);
  cursor: pointer;
  font-size: 13.5px;
  user-select: none;
}

/* Botões de ícone (abrir/ocultar menu) */
.icon-btn {
  background: transparent;
  color: var(--sidebar-muted);
  border: 1px solid transparent;
  padding: 4px 9px;
  font-size: 16px;
  line-height: 1;
  border-radius: 8px;
}
.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}
.icon-btn.floating {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 70;
  display: none;
  background: var(--sidebar);
  color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}
body.sidebar-hidden .icon-btn.floating {
  display: block;
}
body.sidebar-hidden .sidebar {
  display: none;
}
#sidebar-backdrop {
  display: none;
}
.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}
.nav-item.active {
  background: var(--primary);
  color: #fff;
}
.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12.5px;
}
.sidebar-footer #current-user {
  color: #fff;
  margin-bottom: 10px;
  line-height: 1.4;
}
.sidebar-footer .muted {
  color: var(--sidebar-muted);
}
.sidebar-footer button {
  width: 100%;
}

.content {
  flex: 1;
  min-width: 0;
  padding: 28px 32px 64px;
  max-width: 1040px;
}
.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.view-head h1 {
  margin: 0;
  font-size: 24px;
}

@media (max-width: 800px) {
  /* Menu vira gaveta (drawer) sobreposta */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 230px;
    z-index: 65;
    transform: translateX(0);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.35);
  }
  body.sidebar-hidden .sidebar {
    display: flex;
    transform: translateX(-100%);
  }
  #sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 60;
  }
  body.sidebar-hidden #sidebar-backdrop {
    display: none;
  }
  .content {
    padding: 20px 16px 48px;
  }
  .view-head {
    flex-wrap: wrap;
    gap: 12px;
  }
}

/* ---- Filtro de período ---- */
.period-filter {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.period-filter button {
  background: var(--card);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 7px 12px;
  font-weight: 500;
}
.period-filter button:hover {
  background: var(--bg);
}
.period-filter button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.custom-range {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -8px 0 20px;
  flex-wrap: wrap;
}
.period-tag {
  display: inline-block;
  background: #eff6ff;
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 20px;
  vertical-align: middle;
  margin-left: 4px;
  text-transform: none;
}

/* ---- Painel / cards ---- */
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}
.panel h2 {
  margin: 0 0 16px;
  font-size: 16px;
}
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.stat-card .value {
  font-size: 26px;
  font-weight: 700;
}
.stat-card .label {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

/* ---- Inputs / botões ---- */
input,
select,
textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
}
button {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
button:hover {
  background: var(--primary-hover);
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
button.ghost:hover {
  background: var(--bg);
}
button.danger {
  background: var(--danger);
}

/* ---- Filtros ---- */
.filters {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filters select,
.filters input {
  flex: 1;
  min-width: 160px;
}

/* ---- Lista de conteúdos ---- */
.links-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.link-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.link-row:hover {
  border-color: var(--primary);
}
.thumb {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  font-size: 22px;
}
.link-info {
  min-width: 0;
  flex: 1;
}
.link-title {
  font-weight: 600;
}
.link-url {
  color: var(--primary);
  font-size: 13px;
  word-break: break-all;
}
.link-dest {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 360px;
}
.cat-badge {
  display: inline-block;
  background: #eef2ff;
  color: #3730a3;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  vertical-align: middle;
}
.tags {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tag {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
}
.link-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.clicks-badge {
  background: var(--bg);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

/* ---- Rankings ---- */
.rank-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.rank-grid h3 {
  margin: 0 0 12px;
  font-size: 14px;
}
@media (max-width: 700px) {
  .rank-grid {
    grid-template-columns: 1fr;
  }
}
.rank-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.rank-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.rank-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Gráficos ---- */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 20px;
}
@media (max-width: 700px) {
  .chart-grid {
    grid-template-columns: 1fr;
  }
}
.chart-box {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.chart-box h3 {
  margin: 0 0 12px;
  font-size: 14px;
}
.chart-box.full {
  grid-column: 1 / -1;
}
.world-map {
  position: relative;
  width: 100%;
  aspect-ratio: 2058 / 1036;
  background-image: url("/assets/vendor/world.jpg");
  background-size: 100% 100%;
  border-radius: 8px;
  overflow: hidden;
}
.map-dot {
  position: absolute;
  transform: translate(-50%, -50%);
  background: rgba(220, 38, 38, 0.7);
  border: 1px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(220, 38, 38, 0.6);
  cursor: pointer;
}

/* ---- Tabelas ---- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th,
td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
th {
  color: var(--muted);
  font-weight: 600;
}
td.nowrap {
  white-space: nowrap;
}
.table-scroll {
  max-height: 360px;
  overflow: auto;
}

/* ---- Modais ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-y: auto;
  padding: 32px 16px;
  z-index: 50;
}
.overlay.hidden {
  display: none;
}
.modal-panel {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  padding: 28px 24px 24px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}
.modal-panel.modal-wide {
  max-width: 880px;
}
.modal-panel.modal-narrow {
  max-width: 360px;
  text-align: center;
}
.modal-panel h2 {
  margin: 0 0 16px;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 6px 10px;
}

/* ---- Formulários em modal ---- */
.form-field {
  display: block;
  margin-bottom: 12px;
}
.form-field > span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}
.form-field input:not([type="checkbox"]),
.form-field select,
.form-field textarea {
  width: 100%;
}
.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.modal-panel button#cm-save,
.modal-panel button#um-save {
  width: 100%;
  margin-top: 8px;
}

/* ---- Misc ---- */
.detail-toolbar {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
.btn-link {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn-link:hover {
  background: var(--bg);
}
.qr-img {
  width: 240px;
  height: 240px;
  display: block;
  margin: 16px auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.muted {
  color: var(--muted);
}
.error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin: 8px 0 0;
}
.hidden {
  display: none !important;
}
