:root {
  --bg: #07080d;
  --bg-2: #0c0e16;
  --panel: #11131d;
  --panel-2: #161927;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f4f5fa;
  --text-dim: #b8bccb;
  --muted: #7d8296;
  --teal: #2ee6c5;
  --violet: #7b5cff;
  --pink: #ff4d8d;
  --amber: #ffc94d;
  --red: #ff4d6a;
  --red-1: #FF6A4D;
  --red-2: #E50914;
  --red-3: #9E0B1F;
  /* Degradê da marca Powerflix (o mesmo do ícone) */
  --brand: linear-gradient(120deg, var(--red-1), var(--red-2) 55%, var(--red-3));
  --radius: 16px;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
code { background: rgba(255,255,255,0.08); padding: 1px 6px; border-radius: 6px; font-size: 12px; }
a { color: var(--teal); }
.hidden { display: none !important; }
.muted { color: var(--muted); margin: 0; }
.tiny { font-size: 12px; }
.mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; letter-spacing: 0.3px; }

/* ---------- Botões e campos ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  transition: transform .12s, background .15s, border-color .15s, box-shadow .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--border-strong); background: #1c2031; }
.btn:active { transform: scale(0.98); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--red-1); outline-offset: 2px; }
.btn-brand { background: var(--brand); border: 0; color: #fff; box-shadow: 0 8px 24px rgba(229, 9, 20, 0.35); }
.btn-brand:hover { background: var(--brand); filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-danger { color: #ff8a9c; }
.btn-danger:hover { background: rgba(255, 77, 106, 0.12); border-color: rgba(255, 77, 106, 0.4); }
.btn-sm { height: 32px; padding: 0 12px; border-radius: 10px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn { width: 34px; height: 34px; padding: 0; border-radius: 10px; display: inline-grid; place-items: center; border: 1px solid var(--border); background: transparent; color: var(--text-dim); cursor: pointer; }
.icon-btn:hover { color: var(--text); background: var(--panel-2); }
.icon-btn.danger:hover { color: var(--red); border-color: rgba(255,77,106,.4); }

label { display: grid; gap: 6px; color: var(--text-dim); font-weight: 600; font-size: 13px; }
input, select, textarea {
  width: 100%; height: 42px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg-2); color: var(--text); font: inherit; font-weight: 500;
}
textarea { height: auto; min-height: 96px; padding: 12px 14px; resize: vertical; }
input[type="color"] { padding: 4px; height: 42px; cursor: pointer; }
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
.hint { font-weight: 500; color: var(--muted); font-size: 12px; }
.form-error { background: rgba(255, 77, 106, 0.12); border: 1px solid rgba(255, 77, 106, 0.35); color: #ffb3c0; padding: 10px 12px; border-radius: 12px; font-weight: 600; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.switch:last-child { border-bottom: 0; }
.switch strong { display: block; color: var(--text); }
.switch input { appearance: none; width: 44px; height: 26px; border-radius: 13px; padding: 0; background: #2a2e40; position: relative; cursor: pointer; border: 0; flex-shrink: 0; transition: background .2s; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked { background: var(--teal); }
.switch input:checked::after { transform: translateX(18px); }

/* ---------- Entrada ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; overflow: hidden; background: #0b1020; }
.login-bg {
  position: absolute; inset: -20px;
  background:
    radial-gradient(1200px 700px at 20% 15%, rgba(229, 9, 20, 0.30), transparent 60%),
    radial-gradient(1000px 800px at 85% 90%, rgba(123, 20, 40, 0.35), transparent 55%),
    linear-gradient(160deg, #14060a, #1a0710 55%, #050507);
  animation: drift 40s ease-in-out infinite alternate;
}
@keyframes drift { from { transform: scale(1.04) translate(0, 0); } to { transform: scale(1.1) translate(-1.5%, -1%); } }
.login-shade { position: absolute; inset: 0; background: radial-gradient(ellipse at 30% 40%, rgba(7,8,13,0.15), rgba(7,8,13,0.75) 70%), linear-gradient(90deg, rgba(7,8,13,0.55), rgba(7,8,13,0.1)); }
.login-wrap { position: relative; width: min(440px, calc(100% - 32px)); display: grid; gap: 22px; }
.login-brand { display: flex; align-items: center; gap: 12px; font-size: 26px; font-weight: 800; letter-spacing: -0.5px; text-shadow: 0 2px 20px rgba(0,0,0,.5); }
.login-brand em, .side-brand em { font-style: normal; font-weight: 500; color: var(--text-dim); }
.login-card {
  display: grid; gap: 16px; padding: 32px; border-radius: 24px;
  background: rgba(12, 14, 22, 0.62); border: 1px solid rgba(255,255,255,0.14);
  backdrop-filter: blur(22px) saturate(1.3); -webkit-backdrop-filter: blur(22px) saturate(1.3);
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0; font-size: 24px; letter-spacing: -0.4px; }
.login-card input { background: rgba(7, 8, 13, 0.55); }
.login-foot { margin: 0; text-align: center; color: rgba(255,255,255,0.45); font-size: 11px; }
.logo-mark { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; box-shadow: 0 8px 24px rgba(229,9,20,.4); }
.logo-mark svg { width: 22px; height: 22px; stroke: none; }
.logo-mark.sm { width: 36px; height: 36px; border-radius: 11px; }
.logo-mark.sm svg { width: 18px; height: 18px; }

/* ---------- Estrutura ---------- */
.app { display: flex; min-height: 100vh; background: radial-gradient(1200px 600px at 80% -10%, rgba(229,9,20,0.12), transparent), radial-gradient(900px 500px at 10% 0%, rgba(255,106,77,0.05), transparent), var(--bg); }
.sidebar { width: 268px; flex-shrink: 0; background: rgba(12, 14, 22, 0.85); border-right: 1px solid var(--border); position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 20px 14px; }
.side-brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 20px; }
.side-brand strong { display: block; font-size: 17px; letter-spacing: -0.3px; }
.side-version { display: inline-block; margin-top: 2px; font-size: 11px; font-weight: 700; letter-spacing: 0.4px; color: #FF8A73; background: rgba(229,9,20,0.12); border: 1px solid rgba(255,106,77,0.3); padding: 1px 8px; border-radius: 999px; }
.nav-section { font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); padding: 16px 12px 6px; }
.nav-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; border-radius: 12px; border: 0; background: none; color: var(--text-dim); font: inherit; font-weight: 600; cursor: pointer; text-align: left; position: relative; }
.nav-item:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.nav-item.active { background: linear-gradient(90deg, rgba(229,9,20,0.24), rgba(229,9,20,0.04)); color: #fff; }
.nav-item.active::before { content: ''; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 4px; border-radius: 0 4px 4px 0; background: var(--brand); }
.nav-item .chev { margin-left: auto; width: 14px; height: 14px; transition: transform .2s; }
.nav-item.open .chev { transform: rotate(180deg); }
.nav-sub { display: grid; gap: 2px; padding: 2px 0 6px 30px; }
.nav-sub .nav-item { padding: 8px 12px; font-size: 13px; }
.nav-sub .nav-item.active::before { display: none; }
.badge-count { margin-left: auto; font-size: 11px; font-weight: 700; color: var(--text-dim); background: rgba(255,255,255,0.07); padding: 1px 8px; border-radius: 999px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 22px 32px 6px; }
.topbar h2 { margin: 0; font-size: 26px; letter-spacing: -0.6px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.greeting { color: var(--text-dim); font-weight: 600; font-size: 14px; margin-right: 6px; white-space: nowrap; }
.greeting::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--teal); margin-right: 8px; vertical-align: middle; }
.menu-btn { display: none; }
.view { padding: 18px 32px 40px; display: grid; gap: 20px; align-content: start; }

/* ---------- Cartões ---------- */
.view > *, .grid-2 > *, .grid-3 > * { min-width: 0; }
.card { background: linear-gradient(180deg, rgba(22,25,39,0.9), rgba(17,19,29,0.9)); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 16px; }
.card-head .muted { font-size: 13px; }
.card-head .spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 6px; }

/* 6 → 3 → 2 colunas, para nunca ficar um cartão sozinho numa linha */
.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 1500px) { .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { position: relative; overflow: hidden; padding: 18px 20px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--border); }
.stat::after { content: ''; position: absolute; right: -30px; top: -30px; width: 110px; height: 110px; border-radius: 50%; background: var(--glow, rgba(123,92,255,.18)); filter: blur(10px); }
.stat-icon { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--chip, rgba(123,92,255,.16)); color: var(--ink, #b9a8ff); margin-bottom: 14px; }
.stat-value { font-size: 30px; font-weight: 800; letter-spacing: -1px; line-height: 1.1; }
.stat-label { color: var(--muted); font-weight: 600; font-size: 13px; }
.stat-trend { position: absolute; right: 18px; top: 20px; font-size: 12px; font-weight: 700; color: var(--teal); }
.chart-box { position: relative; height: 290px; }
.chart-box.sm { height: 230px; }
.legend { display: grid; gap: 10px; margin-top: 14px; }
.legend-row { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--text-dim); }
.legend-row b { margin-left: auto; color: var(--text); }
.dot { width: 10px; height: 10px; border-radius: 50%; }

/* ---------- Tabelas ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.search { position: relative; flex: 1; min-width: 220px; }
.search svg { position: absolute; left: 12px; top: 12px; color: var(--muted); }
.search input { padding-left: 40px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: transparent; color: var(--text-dim); font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; }
.chip.active { background: #fff; color: #07080d; border-color: #fff; }
.table-wrap { overflow-x: auto; margin: 0 -22px -22px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; letter-spacing: 0.8px; text-transform: uppercase; color: var(--muted); font-weight: 700; padding: 12px 22px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 13px 22px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255,255,255,0.025); }
td .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.cell-main { font-weight: 700; }
.cell-sub { color: var(--muted); font-size: 12px; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty svg { width: 34px; height: 34px; margin-bottom: 8px; opacity: .6; }

.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.active, .pill.ok { color: var(--teal); background: rgba(46,230,197,0.12); }
.pill.demo { color: var(--amber); background: rgba(255,201,77,0.12); }
.pill.expired { color: #ff8a9c; background: rgba(255,77,106,0.12); }
.pill.blocked { color: var(--muted); background: rgba(255,255,255,0.07); }
.pill.used { color: var(--muted); background: rgba(255,255,255,0.07); }
.pill.info { color: #9fb4ff; background: rgba(123,140,255,0.14); }
.pill.warning { color: var(--amber); background: rgba(255,201,77,0.12); }
.pill.success { color: var(--teal); background: rgba(46,230,197,0.12); }

/* ---------- Partes específicas ---------- */
.dns-card { display: flex; align-items: center; gap: 16px; padding: 16px; border-radius: 14px; border: 1px solid var(--border); background: var(--bg-2); }
.dns-card.on { border-color: rgba(46,230,197,.45); background: linear-gradient(90deg, rgba(46,230,197,.08), transparent); }
.dns-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: rgba(123,92,255,.14); color: #b9a8ff; }
.dns-card.on .dns-icon { background: rgba(46,230,197,.14); color: var(--teal); }
.dns-list { display: grid; gap: 10px; }

.codes { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.code-card { padding: 14px 16px; border-radius: 14px; border: 1px solid var(--border); background: var(--bg-2); display: grid; gap: 8px; }
.code-card .mono { font-size: 19px; font-weight: 700; }
.code-card.used { opacity: .55; }

.period-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.period { padding: 14px; border-radius: 14px; border: 1px solid var(--border); background: var(--bg-2); color: var(--text); font: inherit; cursor: pointer; text-align: left; }
.period strong { display: block; font-size: 18px; }
.period span { color: var(--muted); font-size: 12px; font-weight: 600; }
.period.active { border-color: var(--violet); background: rgba(123,92,255,.14); box-shadow: inset 0 0 0 1px var(--violet); }

.device-pick { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 14px; background: var(--bg-2); border: 1px solid var(--border); }
.device-pick .avatar, .avatar { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: rgba(123,92,255,.16); color: #c8bbff; font-weight: 800; }

.notif { display: flex; gap: 14px; padding: 16px; border-radius: 14px; border: 1px solid var(--border); background: var(--bg-2); }
.notif-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; }
.notif-icon.info { background: rgba(123,140,255,0.14); color: #9fb4ff; }
.notif-icon.warning { background: rgba(255,201,77,0.12); color: var(--amber); }
.notif-icon.success { background: rgba(46,230,197,0.12); color: var(--teal); }
.notif-body { flex: 1; min-width: 0; }
.notif-body p { margin: 4px 0 0; color: var(--text-dim); }

.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.theme-card { border-radius: 14px; border: 2px solid var(--border); padding: 0; overflow: hidden; background: var(--bg-2); cursor: pointer; color: var(--text); font: inherit; text-align: left; }
.theme-card.active { border-color: #fff; }
.theme-swatch { height: 74px; display: flex; align-items: flex-end; gap: 6px; padding: 10px; }
.theme-swatch i { width: 18px; height: 18px; border-radius: 6px; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.theme-card div:last-child { padding: 10px 12px; font-weight: 700; }

/* Pré-visualização da app (ecrã de TV) */
.tv-preview { aspect-ratio: 16 / 9; border-radius: 16px; overflow: hidden; position: relative; border: 6px solid #1a1c25; box-shadow: var(--shadow); background-size: cover; background-position: center; }
.tv-preview .shade { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(0,0,0,.82), rgba(0,0,0,.25)); }
.tv-preview .content { position: absolute; inset: 0; padding: 7% 8%; display: flex; flex-direction: column; justify-content: center; gap: 10px; max-width: 70%; }
.tv-preview h4 { margin: 0; font-size: clamp(16px, 2.3vw, 30px); letter-spacing: -0.5px; }
.tv-preview p { margin: 0; color: rgba(255,255,255,.75); font-size: clamp(11px, 1.1vw, 15px); }
.tv-preview .fake-input { height: 34px; border-radius: 10px; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); max-width: 300px; }
.tv-preview .fake-btn { height: 34px; border-radius: 17px; max-width: 160px; display: grid; place-items: center; font-weight: 800; font-size: 13px; color: #fff; }
.tv-preview .mac { font-family: ui-monospace, monospace; font-size: 12px; color: rgba(255,255,255,.6); }
.tv-preview .home-dock { position: absolute; left: 6%; right: 6%; bottom: 7%; display: flex; gap: 8px; }
.tv-preview .home-dock span { flex: 1; height: 54px; border-radius: 10px; background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,.1); }

.layouts { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 18px; }
.layout-card { padding: 0; border-radius: 18px; overflow: hidden; border: 2px solid var(--border); background: var(--panel); color: var(--text); font: inherit; text-align: left; cursor: pointer; transition: transform .15s, border-color .15s; }
.layout-card:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.layout-card.active { border-color: var(--teal); box-shadow: 0 0 0 1px var(--teal), 0 16px 40px rgba(46,230,197,.15); }
.mock { position: relative; aspect-ratio: 16 / 9; overflow: hidden; background: #0b0d14; border-bottom: 1px solid var(--border); }
.layout-info { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.layout-info > div { flex: 1; min-width: 0; }

.ad-card { display: grid; grid-template-columns: 160px 1fr auto; gap: 16px; align-items: center; padding: 12px; border-radius: 14px; border: 1px solid var(--border); background: var(--bg-2); }
.ad-card img { width: 160px; height: 90px; object-fit: cover; border-radius: 10px; background: #1a1c25; }

.version-hero { display: flex; align-items: center; gap: 20px; padding: 24px; border-radius: var(--radius); background: linear-gradient(120deg, rgba(46,230,197,.14), rgba(123,92,255,.16) 50%, rgba(255,77,141,.12)); border: 1px solid var(--border); }
.version-hero .big { font-size: 40px; font-weight: 800; letter-spacing: -1.5px; }

.callout { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 14px; background: rgba(123,140,255,0.08); border: 1px solid rgba(123,140,255,0.25); color: var(--text-dim); }
.callout svg { color: #9fb4ff; margin-top: 2px; }
.callout.warn { background: rgba(255,201,77,0.08); border-color: rgba(255,201,77,0.3); }
.callout.warn svg { color: var(--amber); }

/* ---------- Janela modal e avisos ---------- */
.modal { position: fixed; inset: 0; background: rgba(4, 5, 9, 0.7); backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--panel); border: 1px solid var(--border-strong); border-radius: 20px; padding: 26px; box-shadow: var(--shadow); display: grid; gap: 16px; }
.modal-card h3 { margin: 0; font-size: 20px; }
.toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 10px; z-index: 60; }
.toast { min-width: 260px; max-width: 380px; padding: 12px 16px; border-radius: 12px; background: #1b1f30; border: 1px solid var(--border-strong); box-shadow: var(--shadow); font-weight: 600; display: flex; gap: 10px; align-items: center; animation: pop .2s ease-out; }
.toast.ok svg { color: var(--teal); }
.toast.err svg { color: var(--red); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Ecrãs pequenos ---------- */
@media (max-width: 1100px) {
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .25s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 16px 16px 4px; }
  .topbar h2 { font-size: 21px; }
  .top-actions .btn span, #logout-btn { font-size: 0; gap: 0; }
  .greeting { display: none; }
  .view { padding: 14px 16px 32px; }
  .form-grid { grid-template-columns: 1fr; }
  .ad-card { grid-template-columns: 1fr; }
  .ad-card img { width: 100%; height: auto; aspect-ratio: 16/9; }
  .table-wrap { margin: 0 -22px -22px; }
}
