:root {
    color-scheme: light;
    
    /* Cores Globais do Tema Light */
    --bg: #f4f6f8; 
    --surface: #ffffff;
    --surface-secondary: #f9fafb;
    --surface-hover: #f3f4f6;
    --border: #e5e7eb;
    --border-hover: #d1d5db;
    
    --text-primary: #111827;
    --text-secondary: #6b7280;
    
    /* Configurações da Sidebar (Fixo Escuro conforme referência) */
    --sidebar-bg: #1e3a47; /* Azul escuro inspirado no Xtream */
    --sidebar-border: #152c36;
    --sidebar-text: #e2e8f0;
    --sidebar-text-hover: #ffffff;
    --sidebar-hover-bg: rgba(255, 255, 255, 0.1);
    --sidebar-active-bg: rgba(0, 0, 0, 0.2);
    
    --primary: #0087a3; /* Teal / Cyan */
    --primary-hover: #00a4c7;
    
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.1);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.1);
    --info: #3b82f6;
    --info-bg: rgba(59, 130, 246, 0.1);
    
    --radius-sm: 4px;
    --radius: 8px;
    --radius-lg: 12px;
    
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0f172a; 
    --surface: #1e293b;
    --surface-secondary: #334155;
    --surface-hover: #475569;
    --border: #334155;
    --border-hover: #475569;
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    
    /* Em dark mode a sidebar também é escura, podemos manter o mesmo tom ou alinhar ao fundo */
    --sidebar-bg: #0f172a;
    --sidebar-border: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-text-hover: #ffffff;
    --sidebar-hover-bg: #1e293b;
    --sidebar-active-bg: #334155;
}

* { box-sizing: border-box; }

body { 
    margin: 0; 
    min-height: 100vh; 
    background: var(--bg); 
    color: var(--text-primary); 
    font-family: Inter, system-ui, -apple-system, sans-serif; 
    font-size: 14px;
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* Layout */
.app { 
    min-height: 100vh; 
    display: grid; 
    grid-template-columns: 240px minmax(0, 1fr); 
}

/* Sidebar */
.sidebar { 
    background: var(--sidebar-bg); 
    border-right: 1px solid var(--sidebar-border); 
    padding: 24px 16px; 
    position: sticky; 
    top: 0; 
    height: 100vh; 
    overflow-y: auto; 
    display: flex; 
    flex-direction: column; 
    gap: 24px;
    transition: width 0.2s ease;
}

.brand { 
    display: flex; 
    align-items: center; 
    gap: 12px; 
    text-decoration: none; 
    padding: 0 8px;
}
.brand img { 
    width: 32px; 
    height: 32px; 
    object-fit: contain; 
    border-radius: var(--radius-sm); 
}
.brand span { display: grid; gap: 2px; }
.brand b { color: var(--text-primary); font-size: 15px; font-weight: 600; letter-spacing: -0.2px; }
.brand small { color: var(--text-secondary); font-size: 12px; }

.nav-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.nav-group-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--sidebar-text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 8px;
    margin-bottom: 6px;
    margin-top: 12px;
    opacity: 0.6;
}
.nav-group-title:first-child { margin-top: 0; }

nav a { 
    display: flex; 
    align-items: center; 
    gap: 12px; 
    padding: 10px 12px; 
    color: var(--sidebar-text); 
    text-decoration: none; 
    border-radius: var(--radius); 
    font-size: 13.5px;
    transition: all 0.15s ease;
}
nav a:hover { 
    background: var(--sidebar-hover-bg); 
    color: var(--sidebar-text-hover); 
}
nav a.active { 
    background: var(--sidebar-active-bg); 
    color: var(--sidebar-text-hover); 
    font-weight: 500;
}
.icon { 
    width: 16px; 
    height: 16px; 
    display: inline-grid; 
    place-items: center; 
    opacity: 0.8;
}
nav a.active .icon { opacity: 1; }

.icon-grid::before { content: "⊞"; font-size: 14px; } 
.icon-tv::before { content: "💻"; font-size: 13px; }
.icon-list::before { content: "≡"; font-size: 16px; } 
.icon-key::before { content: "🔑"; font-size: 13px; }
.icon-globe::before { content: "🌐"; font-size: 13px; } 
.icon-users::before { content: "👥"; font-size: 13px; }
.icon-shield::before { content: "🛡️"; font-size: 13px; } 
.icon-file::before { content: "📄"; font-size: 13px; }
.icon-gear::before { content: "⚙️"; font-size: 13px; } 
.icon-coin::before { content: "💳"; font-size: 13px; }
.icon-image::before { content: "🎨"; font-size: 13px; }

.sidebar-footer { 
    margin-top: auto; 
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.me { 
    background: var(--sidebar-active-bg); 
    border: 1px solid var(--sidebar-border); 
    border-radius: var(--radius); 
    padding: 12px; 
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.me b { color: var(--sidebar-text-hover); font-size: 13px; font-weight: 500; }
.me small { color: var(--sidebar-text); font-size: 12px; }

.side-action { 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    height: 36px; 
    border-radius: var(--radius); 
    color: var(--sidebar-text-hover); 
    text-decoration: none; 
    font-weight: 500; 
    background: var(--sidebar-hover-bg); 
    border: 1px solid var(--sidebar-border);
    transition: all 0.15s;
    font-size: 13px;
}
.side-action:hover { background: var(--sidebar-active-bg); border-color: transparent; }

/* Main Content */
main { min-width: 0; }

.topbar { 
    height: 64px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 0 32px; 
    border-bottom: 1px solid var(--border); 
    background: var(--surface); 
    position: sticky; 
    top: 0; 
    z-index: 10; 
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar h1 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -0.2px; }
.topbar p { display: none; } /* hide old description */

.user-menu { display: flex; align-items: center; gap: 16px; color: var(--text-secondary); font-size: 13px; }

.content { padding: 32px; display: flex; flex-direction: column; gap: 24px; }

/* Dashboard Cards */
.cards { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); 
    gap: 16px; 
}
.card, .panel { 
    background: var(--surface); 
    border: 1px solid var(--border); 
    border-radius: var(--radius-lg); 
    box-shadow: var(--shadow-sm);
}
.card { 
    padding: 20px; 
    display: flex; 
    flex-direction: column; 
    gap: 8px; 
}
.card span { 
    color: var(--text-secondary); 
    font-size: 12.5px; 
    font-weight: 500; 
}
.card strong { 
    font-size: 28px; 
    font-weight: 600; 
    line-height: 1; 
    letter-spacing: -0.5px; 
}
.card small { 
    color: var(--text-secondary); 
    font-size: 12px; 
    margin-top: 4px;
}

.panel { padding: 24px; overflow-x: auto; }
.panel-title { 
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    margin-bottom: 20px; 
}
.panel-title h2 { 
    margin: 0; 
    font-size: 16px; 
    font-weight: 600; 
}
.panel-title a { font-size: 13px; font-weight: 500; }

.grid-two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); gap: 24px; }

/* Tables */
table { 
    width: 100%; 
    border-collapse: separate; 
    border-spacing: 0; 
    min-width: 720px; 
}
th, td { 
    padding: 12px 16px; 
    text-align: left; 
    border-bottom: 1px solid var(--border); 
    vertical-align: middle; 
    font-size: 13.5px;
}
th { 
    color: var(--text-secondary); 
    font-size: 12px; 
    font-weight: 500; 
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
tr:hover td { background: var(--surface-secondary); }
td small { display: block; color: var(--text-secondary); margin-top: 2px; font-size: 12px; }

code { 
    background: var(--surface-secondary); 
    border: 1px solid var(--border); 
    padding: 2px 6px; 
    border-radius: var(--radius-sm); 
    color: var(--text-primary); 
    font-size: 12.5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

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

/* Badges */
.badge { 
    display: inline-flex; 
    align-items: center; 
    height: 24px; 
    border-radius: 999px; 
    padding: 0 10px; 
    font-size: 11.5px; 
    font-weight: 500;
    border: 1px solid transparent; 
}
.status-active, .status-paid, .status-ok, .status-free, .status-partner, .status-trial, .status-online { 
    color: var(--success); 
    background: var(--success-bg); 
    border-color: rgba(23, 201, 100, 0.2);
}
.status-pending, .status-maintenance, .status-approved, .status-created, .status-atencao { 
    color: var(--warning); 
    background: var(--warning-bg); 
    border-color: rgba(245, 166, 35, 0.2);
}
.status-blocked, .status-error, .status-failed, .status-cancelled, .status-refunded { 
    color: var(--danger); 
    background: var(--danger-bg); 
    border-color: rgba(243, 18, 96, 0.2);
}
.status-expired, .status-inactive { 
    color: var(--text-secondary); 
    background: var(--surface-secondary);
    border-color: var(--border);
}

/* Forms */
form { margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; align-items: end; }
.form-grid .wide { grid-column: 1 / -1; }

label { display: grid; gap: 6px; color: var(--text-primary); font-size: 13px; font-weight: 500; }
label small { color: var(--text-secondary); font-size: 12px; font-weight: 400; margin-top: -2px; }

input, select, textarea { 
    width: 100%; 
    height: 36px; 
    border: 1px solid var(--border); 
    background: var(--bg); 
    color: var(--text-primary); 
    border-radius: var(--radius); 
    padding: 0 12px; 
    font: inherit; 
    font-size: 13.5px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { height: auto; min-height: 80px; padding: 8px 12px; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: var(--border-hover); }
input:focus, select:focus, textarea:focus { 
    outline: 0; 
    border-color: var(--primary); 
    box-shadow: 0 0 0 3px rgba(0, 112, 243, 0.2); 
}
input[type="checkbox"] { 
    width: 16px; 
    height: 16px; 
    accent-color: var(--primary); 
    cursor: pointer; 
}

/* Buttons */
button, .button { 
    height: 36px; 
    border: 1px solid transparent; 
    border-radius: var(--radius); 
    padding: 0 16px; 
    background: var(--primary); 
    color: white; 
    font-weight: 500; 
    font-size: 13.5px;
    cursor: pointer; 
    text-decoration: none; 
    display: inline-flex; 
    align-items: center; 
    justify-content: center; 
    transition: background 0.15s, border-color 0.15s;
}
button:hover, .button:hover { background: var(--primary-hover); }

button.secondary, .button.secondary, .actions-cell button, .actions-cell .button, .inline-form button {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
}
button.secondary:hover, .button.secondary:hover, .actions-cell button:hover, .inline-form button:hover {
    background: var(--surface-hover);
    border-color: var(--border-hover);
}

button.danger, .actions-cell .danger { 
    background: var(--danger-bg); 
    border: 1px solid rgba(243, 18, 96, 0.3);
    color: var(--danger); 
}
button.danger:hover, .actions-cell .danger:hover {
    background: rgba(243, 18, 96, 0.15);
    border-color: rgba(243, 18, 96, 0.5);
}

.bulk-actions { display: flex; justify-content: flex-end; gap: 8px; margin: 0 0 16px; }
.bulk-actions button { height: 32px; padding: 0 12px; font-size: 13px; }

.select-col { width: 40px; text-align: center; }
.select-col input { margin: 0 auto; }
.actions-cell { display: flex; flex-wrap: wrap; gap: 6px; }
.actions-cell button, .actions-cell .button { height: 28px; padding: 0 10px; font-size: 12px; }

/* Modals (Row Editor) */
.row-editor { position: relative; }
.row-editor > summary { 
    height: 28px; 
    display: inline-flex; 
    align-items: center; 
    padding: 0 10px; 
    border: 1px solid var(--border); 
    border-radius: var(--radius); 
    background: var(--surface); 
    color: var(--text-primary); 
    font-weight: 500; 
    font-size: 12px;
    cursor: pointer; 
    list-style: none; 
    transition: all 0.15s;
}
.row-editor > summary::-webkit-details-marker { display: none; }
.row-editor > summary:hover { background: var(--surface-hover); border-color: var(--border-hover); }
.row-editor > summary.danger { color: var(--danger); border-color: rgba(243, 18, 96, 0.3); background: var(--danger-bg); }
.row-editor > summary.danger:hover { background: rgba(243, 18, 96, 0.15); }
.row-editor[open] > summary { background: var(--surface-hover); border-color: var(--border-hover); }

.row-editor .edit-form { 
    position: fixed; 
    z-index: 50; 
    left: 50%; 
    top: 50%; 
    transform: translate(-50%, -50%); 
    width: min(640px, calc(100vw - 32px)); 
    max-height: calc(100vh - 32px); 
    overflow-y: auto; 
    display: grid; 
    grid-template-columns: repeat(2, minmax(0, 1fr)); 
    gap: 16px; 
    padding: 24px; 
    border: 1px solid var(--border); 
    border-radius: var(--radius-lg); 
    background: var(--surface); 
    box-shadow: 0 24px 80px rgba(0,0,0,0.6); 
}

.row-editor .edit-form::before { 
    content: "Editar Registro"; 
    grid-column: 1 / -1; 
    color: var(--text-primary); 
    font-size: 16px; 
    font-weight: 600; 
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
}
.row-editor .bulk-delete-form::before { content: "Apagar registros em massa"; }
.row-editor .edit-form .wide { grid-column: 1 / -1; }
.row-editor .edit-form button { margin-top: 8px; }

/* Inline Forms */
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { width: 100px; height: 28px; }
.inline-form button { height: 28px; padding: 0 10px; font-size: 12px; }

/* Alerts */
.alert { 
    margin: 0 0 24px 0; 
    padding: 12px 16px; 
    border-radius: var(--radius); 
    border: 1px solid; 
    font-size: 13.5px;
}
.alert.success { background: var(--success-bg); border-color: rgba(23, 201, 100, 0.3); color: var(--success); }
.alert.error { background: var(--danger-bg); border-color: rgba(243, 18, 96, 0.3); color: var(--danger); }

/* Tabs */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; border-bottom: 1px solid var(--border); padding-bottom: 16px; margin-bottom: 24px; }
.tabs button { 
    background: transparent; 
    border: 0; 
    border-radius: var(--radius-sm);
    color: var(--text-secondary); 
    font-weight: 500;
}
.tabs button:hover { background: var(--surface-hover); color: var(--text-primary); }
.tabs button.active { 
    background: var(--surface-secondary); 
    color: var(--text-primary); 
}

.filter-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-tabs a { 
    border: 1px solid var(--border); 
    border-radius: 999px; 
    padding: 6px 12px; 
    color: var(--text-secondary); 
    text-decoration: none; 
    background: var(--surface); 
    font-weight: 500; 
    font-size: 12px;
    transition: all 0.15s;
}
.filter-tabs a.active, .filter-tabs a:hover { 
    color: var(--text-primary); 
    border-color: var(--text-secondary); 
    background: var(--surface-secondary); 
}

/* Utils */
.hidden { display: none !important; }

/* Login */
.login-body { 
    min-height: 100vh; 
    display: grid; 
    place-items: center; 
    padding: 32px 16px; 
    background: var(--bg); 
}
.login-shell { width: min(360px, 100%); display: grid; gap: 24px; justify-items: center; }
.login-brand { width: 140px; }
.login-brand img { width: 100%; object-fit: contain; height: auto; display: block; border-radius: var(--radius-sm); }
.login-card { 
    width: 100%; 
    display: grid; 
    gap: 16px; 
    padding: 32px; 
    background: var(--surface); 
    border: 1px solid var(--border); 
    border-radius: var(--radius-lg); 
    box-shadow: var(--shadow); 
}
.login-card h1 { margin: 0; font-size: 18px; font-weight: 600; text-align: center; }
.login-card input { height: 40px; background: var(--bg); }
.login-card button { height: 40px; margin-top: 8px; width: 100%; }
.login-card .alert { margin: 0; padding: 12px; }

/* Media Queries */
@media (max-width: 880px) {
    .app { grid-template-columns: 1fr; }
    
    /* Mobile Menu Button Display */
    #mobile-menu-btn { display: inline-flex !important; }
    
    /* Sidebar as Drawer */
    .sidebar { 
        position: fixed; 
        top: 0; 
        left: -280px; 
        width: 260px; 
        height: 100vh; 
        z-index: 100; 
        border-right: 1px solid var(--sidebar-border); 
        box-shadow: 4px 0 16px rgba(0,0,0,0.5);
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        padding: 24px 16px;
        gap: 24px;
    }
    .sidebar.open { left: 0; }
    .sidebar nav { display: flex; flex-direction: column; gap: 2px; }
    .nav-group-title { display: block; }

    .topbar { flex-direction: row; align-items: center; justify-content: space-between; height: 64px; padding: 0 16px; position: sticky; top: 0; }
    .topbar h1 { font-size: 15px; }
    .user-menu span { display: none; } /* Ocultar nome no celular para espaço */
    
    .content { padding: 16px; }
    .grid-two { grid-template-columns: 1fr; }
    .row-editor .edit-form { grid-template-columns: 1fr; padding: 16px; }
    .row-editor .edit-form .wide { grid-column: auto; }
}
