/* ============================================================
   Infra Dashboard — estilos principais
   ============================================================ */
:root {
    --bg: #0f172a;
    --card: #1e293b;
    --card-hover: #273549;
    --card-inner: #111827;
    --text: #f8fafc;
    --muted: #94a3b8;
    --primary: #3b82f6;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: #334155;
}

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

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.container { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
    width: 260px;
    background: #020617;
    border-right: 1px solid var(--border);
    padding: 20px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transition: width 0.3s ease, padding 0.3s ease;
}

.sidebar-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
}

.logo { font-size: 1.4rem; font-weight: 700; color: var(--primary); }

#toggle-sidebar-btn {
    background: rgba(148, 163, 184, 0.1);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: 0.3s;
}

.menu { list-style: none; }
.menu li { margin-bottom: 8px; }
.menu a {
    text-decoration: none;
    color: var(--text);
    display: block;
    padding: 10px 12px;
    border-radius: 10px;
    transition: 0.3s;
    font-size: 14px;
}
.menu a:hover { background: var(--primary); }

.sidebar.collapsed { width: 70px; padding: 20px 10px; }
.sidebar.collapsed .logo,
.sidebar.collapsed .menu { display: none; }
.sidebar.collapsed #toggle-sidebar-btn { margin: 0 auto; transform: rotate(180deg); }

/* ---------- Layout principal ---------- */
.main { flex: 1; padding: 25px; width: 100%; min-width: 0; }

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    flex-wrap: wrap;
    gap: 15px;
}
.header h1 { font-size: 1.8rem; }
.header-actions { display: flex; align-items: center; gap: 12px; }

.user {
    background: var(--card);
    padding: 10px 15px;
    border-radius: 12px;
    font-size: 14px;
    border: 1px solid var(--border);
}
.user a { text-decoration: none; margin-left: 8px; }
.user .link-sair { color: var(--danger); }
.user .link-entrar { color: var(--primary); }
.user .tag-admin { color: var(--primary); }

/* ---------- Cards e secções ---------- */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.card {
    background: var(--card);
    padding: 20px;
    border-radius: 16px;
    border: 1px solid var(--border);
    transition: .3s;
}
.card:hover { background: var(--card-hover); }
.card h3 { margin-bottom: 10px; font-size: 1.1rem; }

.status { font-size: 14px; color: var(--muted); }
.online { color: var(--success); font-weight: 600; }
.offline { color: var(--danger); font-weight: 600; }

.section {
    background: var(--card);
    padding: 20px;
    border-radius: 16px;
    border: 1px solid var(--border);
    margin-bottom: 20px;
    scroll-margin-top: 25px;
}
.section h2 { margin-bottom: 20px; font-size: 1.3rem; }
.section h2.subtitulo { margin-top: 25px; }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}
.section-header h2 { margin-bottom: 0; }

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

/* ---------- Formulários / botões ---------- */
.input, .select {
    width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    outline: none;
    font-family: inherit;
}
.select { width: auto; font-size: 13px; }

.btn {
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card-inner);
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.3s;
}
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn-block { width: 100%; padding: 10px 12px; font-size: 13px; }
.btn-primary { background: rgba(59, 130, 246, 0.2); color: var(--primary); border-color: var(--primary); }
.btn-success { background: rgba(16, 185, 129, 0.15); color: var(--success); border-color: var(--success); }
.btn-danger { background: rgba(239, 68, 68, 0.2); color: var(--danger); border-color: var(--danger); }
.btn-solid { background: var(--primary); color: #fff; border: none; padding: 10px 18px; font-size: 14px; }

/* ---------- Smart Home ---------- */
.smart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 15px;
}

.smart-card {
    background: var(--card-inner);
    padding: 18px;
    border-radius: 12px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 12px;
}
.smart-card-title { font-weight: 600; font-size: 0.95rem; display: block; margin-bottom: 4px; }
.smart-card-platform { font-size: 11px; color: var(--muted); margin-top: 2px; }

.card-api-app { cursor: pointer; margin-bottom: 15px; }
.card-api-app:hover { transform: translateY(-2px); }
.card-api-app-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.card-api-app-header h3 { margin: 0; }

.smart-grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 15px;
}

.device-card {
    background: var(--card-inner);
    border: 1px solid var(--border);
    border-left: 4px solid var(--muted);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    transition: all 0.2s ease-in-out;
}
.device-card.on { border-left-color: var(--success); }
.device-card.unavailable { border-left-color: var(--danger); opacity: 0.65; }

.device-header { display: flex; align-items: center; gap: 10px; min-width: 0; }
.device-icon { font-size: 1.4rem; }
.device-title {
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.device-body { display: flex; justify-content: space-between; align-items: center; }

.device-status-badge { font-size: 0.8rem; padding: 3px 8px; border-radius: 12px; font-weight: 600; }
.device-status-badge.on { background: rgba(16, 185, 129, .2); color: var(--success); }
.device-status-badge.off { background: rgba(148, 163, 184, .15); color: var(--muted); }
.device-status-badge.unavailable { background: rgba(239, 68, 68, .2); color: var(--danger); }

.smart-state {
    grid-column: 1 / -1;
    padding: 24px;
    text-align: center;
    background: var(--card-inner);
    border-radius: 12px;
    color: var(--muted);
}

/* ---------- Switch (estilo iOS) ---------- */
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: var(--border);
    transition: .3s;
    border-radius: 24px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}
input:checked + .slider { background-color: var(--success); }
input:checked + .slider:before { transform: translateX(20px); }
input:disabled + .slider { cursor: not-allowed; opacity: 0.5; }

/* ---------- Tabelas ---------- */
.table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 600px; }
th, td { padding: 12px; text-align: left; }
th { color: var(--muted); font-size: 13px; text-transform: uppercase; }
tr { border-bottom: 1px solid var(--border); }

.badge { padding: 5px 10px; border-radius: 8px; font-size: 12px; display: inline-block; font-weight: 600; }
.badge-success { background: rgba(16, 185, 129, .2); color: var(--success); }
.badge-danger { background: rgba(239, 68, 68, .2); color: var(--danger); }
.badge-warning { background: rgba(245, 158, 11, .2); color: var(--warning); }

/* ---------- Segurança ---------- */
.security-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}
.security-card { background: var(--card-inner); padding: 15px; border-radius: 12px; }
.security-card p { color: var(--muted); margin-top: 8px; font-size: 13px; }
.security-card .check { font-size: 11px; }

/* ---------- Recursos ---------- */
.resource-label { display: flex; justify-content: space-between; margin-bottom: 5px; font-size: 14px; }
.resource-track { background: var(--card-hover); height: 10px; border-radius: 5px; overflow: hidden; }
.resource-bar { background: var(--primary); height: 100%; width: 0%; transition: 0.5s; }

/* ---------- Logs / terminal ---------- */
.terminal {
    background: #000;
    border-radius: 12px;
    padding: 15px;
    border: 1px solid var(--border);
    position: relative;
    transition: all 0.3s ease;
}
.terminal-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    border-bottom: 1px solid #1e293b;
    padding-bottom: 8px;
}
.terminal pre, .log-pre {
    color: #38f848;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.4;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
}

.log-fullscreen {
    position: fixed !important;
    inset: 0 !important;
    z-index: 99999 !important;
    border-radius: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    padding: 20px !important;
}
.log-fullscreen pre { max-height: none !important; flex: 1 !important; }

/* ---------- HTOP ---------- */
.htop-table { background: #000; border-radius: 12px; padding: 10px; border: 1px solid var(--border); }
.htop-table thead tr { border-bottom: 1px solid var(--border); color: #38bdf8; }
.htop-table th.sortable { cursor: pointer; }
.htop-table tbody { font-family: monospace; font-size: 13px; }
.btn-kill {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
}

/* ---------- WhatsApp (whatsapp.php) ---------- */

.qr-box {
    text-align: center;
    padding: 10px;
    background: #020617;
    border-radius: 8px;
    border: 1px solid var(--border);
}
.qr-box img { max-width: 180px; width: 100%; border-radius: 6px; background: white; padding: 5px; }

.config-panel { background: var(--card-inner); padding: 20px; border-radius: 12px; border: 1px solid var(--border); }
.input-group { display: flex; align-items: center; gap: 8px; }
.input-group .unit { color: var(--muted); font-size: 13px; font-weight: 600; }
.input-prefix {
    display: flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    overflow: hidden;
}
.input-prefix span {
    padding: 8px 10px;
    background: #020617;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    border-right: 1px solid var(--border);
}
.input-prefix input { border: none; border-radius: 0; }

/* Página autónoma whatsapp.php */
.page-centered { display: flex; justify-content: center; padding: 30px 16px; }
.wa-box { max-width: 420px; width: 100%; text-align: center; display: flex; flex-direction: column; gap: 12px; }
.wa-box hr { border: none; border-top: 1px solid var(--border); }
.wa-box a { color: var(--primary); text-decoration: none; font-size: 13px; }

/* ---------- Overlay de reboot ---------- */
#overlay-reboot {
    display: none;
    position: fixed;
    inset: 0;
    background: #dc2626;
    color: #fff;
    z-index: 99999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px;
}
#overlay-reboot h1 { font-size: 2.2rem; margin-bottom: 10px; font-weight: 800; }
#overlay-reboot p { font-size: 1.2rem; max-width: 600px; opacity: 0.95; line-height: 1.5; }
.overlay-icon { font-size: 64px; margin-bottom: 20px; }
.overlay-status {
    margin-top: 30px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    background: rgba(0, 0, 0, 0.2);
    padding: 12px 24px;
    border-radius: 30px;
}
.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #fff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Modal de logs ---------- */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.85);
    backdrop-filter: blur(5px);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    padding: 20px;
}
.modal-box {
    background: #090d16;
    width: 100%;
    max-width: 1000px;
    height: 90vh;
    border-radius: 16px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #020617;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 0.95rem; }
.modal-body { flex: 1; padding: 15px; overflow-y: auto; background: #000; }
.modal-body pre { max-height: none; font-size: 11px; }

.footer { text-align: center; padding: 20px; color: var(--muted); font-size: 13px; }

/* ---------- Filmes em destaque (visitantes) ---------- */
.fw-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 20px; }
.fw-chip {
    border: 1px solid var(--border);
    background: var(--card-inner);
    color: var(--text);
    padding: 7px 14px;
    border-radius: 999px;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: 0.2s;
}
.fw-chip:hover { border-color: var(--primary); }
.fw-chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }
.fw-sort { margin-left: auto; }

.fw-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 18px; }
.fw-card {
    background: var(--card-inner);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.fw-card:hover { transform: translateY(-3px); border-color: var(--primary); box-shadow: 0 8px 24px rgba(0, 0, 0, .35); }
.fw-main { display: flex; flex-direction: column; flex: 1; text-decoration: none; color: inherit; }
.fw-play {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.6rem;
    color: #fff;
    background: rgba(2, 6, 23, .45);
    opacity: 0;
    transition: opacity .15s ease;
}
.fw-main:hover .fw-play, .fw-main:focus-visible .fw-play { opacity: 1; }
.fw-links {
    display: flex;
    gap: 12px;
    padding: 0 12px 10px;
    font-size: 11px;
}
.fw-links a { color: var(--muted); text-decoration: none; }
.fw-links a:hover { color: var(--primary); text-decoration: underline; }
.fw-links { align-items: center; flex-wrap: wrap; }
.fw-trailer {
    border: 1px solid var(--primary);
    background: rgba(59, 130, 246, .15);
    color: var(--primary);
    border-radius: 6px;
    padding: 3px 8px;
    font: inherit;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}
.fw-trailer:hover { background: var(--primary); color: #fff; }

/* Trailer em janela flutuante */
.fw-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(2, 6, 23, .85);
    backdrop-filter: blur(4px);
}
.fw-modal.aberto { display: flex; }
.fw-modal-box {
    width: min(960px, 100%);
    background: #000;
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 25px 60px rgba(0, 0, 0, .6);
}
.fw-modal-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    background: #020617;
    border-bottom: 1px solid var(--border);
}
.fw-modal-titulo { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fw-modal-fechar {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--danger);
    background: rgba(239, 68, 68, .2);
    color: var(--danger);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}
.fw-modal-video { position: relative; aspect-ratio: 16 / 9; }
.fw-modal-video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.fw-modal-msg {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 20px;
    text-align: center;
    color: var(--muted);
}
.fw-modal-msg a { color: var(--primary); }

/* Janela "onde queres ver?" */
.fw-modo-escolha { width: min(440px, 100%); background: var(--card); }
.fw-modo-escolha .fw-modal-video { aspect-ratio: auto; }
.fw-escolha { display: flex; flex-direction: column; gap: 10px; padding: 16px; }
.fw-op {
    display: flex;
    flex-direction: column;
    gap: 3px;
    width: 100%;
    padding: 14px 16px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card-inner);
    color: var(--text);
    text-align: left;
    text-decoration: none;
    font: inherit;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}
.fw-op span { font-weight: 600; font-size: 15px; }
.fw-op small { color: var(--muted); font-size: 12px; }
.fw-op:hover, .fw-op:focus-visible { border-color: var(--primary); background: rgba(59, 130, 246, .12); }
.fw-op-app { border-color: var(--primary); }
.fw-escolha-aviso {
    margin: 4px 0 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(245, 158, 11, .12);
    border: 1px solid var(--warning);
    color: var(--text);
    font-size: 13px;
    line-height: 1.4;
}
.fw-escolha-aviso a { color: var(--warning); }
.fw-poster { position: relative; aspect-ratio: 2 / 3; background: var(--card-hover); }
.fw-poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fw-rating {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(2, 6, 23, .85);
    color: #fff;
    font-weight: 600;
    font-size: 12px;
    padding: 3px 8px;
    border-radius: 6px;
}
.fw-rating::before { content: "★ "; color: var(--warning); }
.fw-info { padding: 10px 12px 12px; }
.fw-title { font-size: 14px; font-weight: 600; line-height: 1.25; margin: 0 0 4px; }
.fw-meta { font-size: 12px; color: var(--muted); }
.fw-msg { grid-column: 1 / -1; padding: 40px 0; text-align: center; color: var(--muted); }

/* ---------- Mobile ---------- */
@media (max-width: 850px) {
    .container { flex-direction: column; }

    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 15px;
    }
    .sidebar-top { margin-bottom: 15px; }

    .menu { display: flex; overflow-x: auto; gap: 10px; padding-bottom: 5px; }
    .menu li { margin-bottom: 0; white-space: nowrap; }
    .menu a { padding: 8px 14px; background: var(--card); font-size: 13px; }

    .sidebar.collapsed { width: 100%; }

    .main { padding: 15px; }
    .header { flex-direction: column; align-items: flex-start; }
    .header-actions { width: 100%; justify-content: space-between; }
    .cards { grid-template-columns: 1fr; gap: 12px; }
    .section { padding: 15px; }

    .fw-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .fw-sort { margin-left: 0; width: 100%; }

    /* Telemóvel: trailer a toda a largura, colado aos lados */
    .fw-modal { padding: 0; align-items: center; }
    .fw-modal-box { border-radius: 0; border-left: 0; border-right: 0; }
    .fw-modo-escolha { width: calc(100% - 24px); border-radius: 14px; border: 1px solid var(--border); }
    .fw-trailer { padding: 6px 10px; font-size: 12px; }  /* alvo de toque maior */
}