:root {
  --bg: #0b0f19;
  --bg-soft: #111827;
  --panel: #0f172a;
  --panel-2: #111827;
  --panel-3: #1e293b;
  --border: #2a3548;
  --text: #f3f4f6;
  --muted: #94a3b8;

  --primary: #facc15;
  --primary-hover: #eab308;

  --success: #10b981;
  --success-bg: #064e3b;

  --danger: #ef4444;
  --danger-bg: #7f1d1d;

  --warning: #f59e0b;
  --warning-bg: #78350f;

  --shadow: 0 12px 35px rgba(0, 0, 0, 0.32);
  --radius: 18px;
  --radius-sm: 12px;
  --radius-xs: 10px;
  --transition: 0.25s ease;
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: Arial, Helvetica, sans-serif;
  background: radial-gradient(circle at top left, rgba(250, 204, 21, 0.1), transparent 28%),
    radial-gradient(circle at bottom right, rgba(245, 158, 11, 0.08), transparent 24%),
    var(--bg-soft);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
  width: 100%;
}

a {
  text-decoration: none;
  color: inherit;
  transition: var(--transition);
}

img {
  max-width: 100%;
  display: block;
  height: auto;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* ========== SIDEBAR ========== */
.sidebar {
  width: 270px;
  min-width: 270px;
  background: rgba(10, 15, 25, 0.97);
  border-right: 1px solid var(--border);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  z-index: 50;
}

.sidebar .brand {
  padding: 8px 10px 14px;
  border-bottom: 1px solid var(--border);
}

.sidebar .brand h2,
.sidebar .brand h1 {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
  word-break: break-word;
}

.sidebar .brand p {
  color: var(--muted);
  font-size: 13px;
  word-break: break-word;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  border-radius: 14px;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  font-weight: 600;
  transition: var(--transition);
}

.sidebar nav a:hover {
  background: rgba(250, 204, 21, 0.08);
  border-color: rgba(250, 204, 21, 0.2);
  color: #fde68a;
  transform: translateX(2px);
}

.sidebar nav a.active {
  background: linear-gradient(135deg, var(--primary), #f59e0b);
  color: #111827;
  border-color: transparent;
  box-shadow: 0 10px 25px rgba(250, 204, 21, 0.22);
}

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

/* ========== CONTEÚDO PRINCIPAL ========== */
.content {
  flex: 1;
  min-width: 0;
  padding: 28px;
}

.content.full {
  width: 100%;
  max-width: 560px;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-box {
  width: 100%;
}

/* ========== TOPBAR ========== */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.topbar h1 {
  font-size: clamp(24px, 5vw, 30px);
  line-height: 1.2;
  margin-bottom: 6px;
  color: #fff;
}

.muted {
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

/* ========== CARDS E ESTATÍSTICAS ========== */
.card {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(17, 24, 39, 0.96));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.card h2,
.card h3 {
  margin-bottom: 14px;
  color: #fff;
  word-break: break-word;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

.stat {
  padding: 20px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.96), rgba(17, 24, 39, 0.95));
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.stat h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  color: #cbd5e1;
}

.stat strong {
  font-size: clamp(24px, 6vw, 30px);
  line-height: 1.2;
  color: #fff7cc;
  display: block;
  word-break: break-word;
}

/* ========== ALERTAS ========== */
.alert {
  padding: 14px 16px;
  border-radius: 14px;
  margin-bottom: 20px;
  border: 1px solid transparent;
  font-weight: 600;
  word-break: break-word;
}

.alert.success {
  background: rgba(6, 78, 59, 0.3);
  border-color: rgba(16, 185, 129, 0.25);
  color: #d1fae5;
}

.alert.error {
  background: rgba(127, 29, 29, 0.3);
  border-color: rgba(239, 68, 68, 0.25);
  color: #fee2e2;
}

/* ========== BOTÕES ========== */
.btn,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 11px 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: linear-gradient(135deg, var(--primary), #f59e0b);
  color: #111827;
  cursor: pointer;
  font-weight: 700;
  transition: var(--transition);
  text-align: center;
  word-break: keep-all;
}

.btn:hover,
button:hover {
  background: linear-gradient(135deg, var(--primary-hover), #d97706);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(250, 204, 21, 0.2);
}

.btn.secondary {
  background: #334155;
  color: #fff;
}

.btn.secondary:hover {
  background: #475569;
  color: #fff;
  box-shadow: none;
}

.btn.danger {
  background: var(--danger);
  color: #fff;
}

.btn.danger:hover {
  background: #dc2626;
  color: #fff;
  box-shadow: none;
}

.btn.green {
  background: var(--success);
  color: #fff;
}

.btn.green:hover {
  background: #059669;
  color: #fff;
  box-shadow: none;
}

/* ========== FORMULÁRIOS ========== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field label {
  font-size: 14px;
  font-weight: 600;
  color: #e2e8f0;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 46px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #334155;
  background: #0b1220;
  color: #fff;
  outline: none;
  transition: var(--transition);
}

.field textarea {
  min-height: 110px;
  resize: vertical;
}

.field input::placeholder,
.field textarea::placeholder {
  color: #64748b;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(250, 204, 21, 0.12);
}

.field small {
  color: var(--muted);
  font-size: 12px;
}

/* ========== TABELAS ========== */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border-radius: 16px;
  border: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
  background: rgba(2, 6, 23, 0.35);
}

.table th,
.table td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}

.table th {
  background: #0b1220;
  color: #fcd34d;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  position: sticky;
  top: 0;
  z-index: 1;
}

.table tr:hover td {
  background: rgba(250, 204, 21, 0.04);
}

/* ========== BADGES ========== */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  border: 1px solid transparent;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 6px 14px rgba(0, 0, 0, 0.18);
}

.badge.ativo {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.22), rgba(5, 150, 105, 0.16));
  border-color: rgba(16, 185, 129, 0.35);
  color: #d1fae5;
}

.badge.vencido {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.24), rgba(185, 28, 28, 0.16));
  border-color: rgba(239, 68, 68, 0.35);
  color: #fee2e2;
}

.badge.renovado {
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.24), rgba(245, 158, 11, 0.18));
  border-color: rgba(250, 204, 21, 0.35);
  color: #fff4bf;
}

.badge.p2p {
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.26), rgba(217, 119, 6, 0.18));
  border-color: rgba(250, 204, 21, 0.35);
  color: #fff1a6;
}

.badge.iptv {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.26), rgba(126, 34, 206, 0.18));
  border-color: rgba(168, 85, 247, 0.35);
  color: #f3e8ff;
}

.badge.pendente {
  background: linear-gradient(135deg, rgba(148, 163, 184, 0.18), rgba(71, 85, 105, 0.16));
  border-color: rgba(148, 163, 184, 0.25);
  color: #e2e8f0;
}

/* ========== UTILITÁRIOS ========== */
.code {
  background: #020617;
  border: 1px solid var(--border);
  padding: 14px;
  border-radius: 14px;
  overflow-x: auto;
  white-space: pre-wrap;
  font-family: Consolas, monospace;
  font-size: 13px;
  word-break: break-all;
}

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

details {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
}

details summary {
  cursor: pointer;
  font-weight: 700;
  color: #fff;
  word-break: break-word;
}

.mobile-top {
  display: none;
}

/* ========== RESPONSIVIDADE AVANÇADA ========== */
/* Telas grandes (1200px) */
@media (max-width: 1200px) {
  .grid.cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Tablets e telas médias (992px) */
@media (max-width: 992px) {
  .app {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    min-width: 100%;
    height: auto;
    position: relative;
    top: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 18px;
    gap: 16px;
    backdrop-filter: none; /* melhora performance mobile */
  }

  .sidebar nav {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
  }

  .sidebar nav a {
    justify-content: center;
    text-align: center;
  }

  .content {
    padding: 18px;
  }

  .topbar h1 {
    font-size: 26px;
  }

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

  .grid.cols-3,
  .grid.cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Dispositivos médios/pequenos (768px) */
@media (max-width: 768px) {
  .content {
    padding: 14px;
  }

  .card,
  .stat {
    padding: 16px;
    border-radius: 16px;
  }

  .topbar {
    margin-bottom: 18px;
  }

  .topbar h1 {
    font-size: 24px;
  }

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

  .grid.cols-2,
  .grid.cols-3,
  .grid.cols-4,
  .grid.auto {
    grid-template-columns: 1fr;
  }

  .actions {
    width: 100%;
  }

  .actions .btn,
  .actions button,
  .actions input,
  .actions select {
    width: 100%;
    justify-content: center;
  }

  .btn,
  button {
    width: 100%;
  }

  .content.full {
    padding: 14px;
  }

  .table {
    min-width: 760px;
  }

  .table th,
  .table td {
    padding: 10px 8px;
  }
}

/* Smartphones grandes (520px) */
@media (max-width: 520px) {
  body {
    font-size: 14px;
  }

  .sidebar {
    padding: 14px;
  }

  .sidebar .brand h1,
  .sidebar .brand h2 {
    font-size: 20px;
  }

  .sidebar nav {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .sidebar nav a {
    padding: 12px;
    font-size: 14px;
  }

  .card {
    padding: 14px;
  }

  .stat strong {
    font-size: 24px;
  }

  .field input,
  .field select,
  .field textarea {
    min-height: 44px;
    padding: 11px 12px;
  }

  .table {
    min-width: 680px;
  }

  .badge {
    font-size: 10px;
    padding: 6px 9px;
    white-space: nowrap;
  }
}

/* Smartphones muito pequenos (380px) */
@media (max-width: 380px) {
  .sidebar .brand h1,
  .sidebar .brand h2 {
    font-size: 18px;
  }

  .sidebar nav a {
    padding: 10px;
    font-size: 13px;
  }

  .stat {
    padding: 12px;
  }

  .card {
    padding: 12px;
  }

  .btn,
  button {
    min-height: 42px;
    padding: 8px 12px;
  }

  .field input,
  .field select,
  .field textarea {
    min-height: 42px;
    padding: 10px;
  }

  .table th,
  .table td {
    padding: 8px 6px;
    font-size: 12px;
  }
}

/* Melhorias para toque em dispositivos móveis */
@media (hover: none) and (pointer: coarse) {
  .btn,
  button,
  .sidebar nav a {
    min-height: 48px;
  }

  .field input,
  .field select,
  .field textarea {
    font-size: 16px; /* evita zoom automático no iOS */
  }
}