* { box-sizing: border-box; }
body { font-family: 'Inter', system-ui, sans-serif; background: #0f172a; color: #f8fafc; margin: 0; padding: 20px; min-height: 100vh; overflow-x: hidden; }
.master-layout { display: flex; gap: 30px; align-items: flex-start; max-width: 1600px; margin: 0 auto; width: 100%; }

.sidebar { 
    width: 350px; 
    flex-shrink: 0;
    background: #1e293b; 
    padding: 20px; 
    border-radius: 12px; 
    border: 1px solid #334155; 
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

/* Custom Scrollbar for Sidebar and Table */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #475569; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #64748b; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; height: calc(100vh - 40px); }

.header-title { color: #8b5cf6; font-size: 24px; margin: 0 0 20px 0; font-weight: 800; letter-spacing: -0.5px; }

.form-group { margin-bottom: 15px; }
.form-group label { display: block; font-size: 12px; color: #94a3b8; margin-bottom: 5px; text-transform: uppercase; letter-spacing: 1px; font-weight: bold; }
.form-group input, .form-group select { width: 100%; background: #0f172a; color: #fff; border: 1px solid #334155; padding: 12px; border-radius: 6px; font-family: sans-serif; }
.form-group input:focus, .form-group select:focus { border-color: #8b5cf6; outline: none; }

.master-btn { background: #8b5cf6; color: white; border: none; padding: 15px; width: 100%; border-radius: 6px; cursor: pointer; font-weight: 800; font-size: 16px; letter-spacing: 1px; transition: all 0.2s; box-shadow: 0 5px 15px rgba(139, 92, 246, 0.3); flex-shrink: 0; }
.master-btn:hover { background: #7c3aed; }
.stop-btn { background: #ef4444; margin-top: 10px; display: none; box-shadow: 0 5px 15px rgba(239, 68, 68, 0.4); }
.stop-btn:hover { background: #dc2626; }

.stat-box { display: flex; justify-content: space-between; background: #0f172a; padding: 10px 15px; border-radius: 6px; margin-top: 15px; font-size: 13px; border: 1px solid #334155; }
.stat-value { font-weight: bold; color: #10b981; }

.table-wrapper { background: #1e293b; border-radius: 8px; border: 1px solid #334155; overflow: auto; flex: 1; min-height: 0; }
table { width: 100%; border-collapse: collapse; margin-top: 0; font-size: 13px; min-width: 600px; }
th, td { padding: 15px 10px; text-align: left; border-bottom: 1px solid #1e293b; }
th { color: #94a3b8; text-transform: uppercase; font-size: 11px; letter-spacing: 1px; position: sticky; top: 0; background: #1e293b; z-index: 10; padding: 15px 10px; }
tr.lead-row { transition: all 0.2s; }
tr.lead-row:hover { background: #0f172a; cursor: pointer; border-left: 3px solid #8b5cf6; }

.score-0 { color: #ef4444; font-weight: bold; }
.score-30 { color: #f59e0b; font-weight: bold; }
.score-60 { color: #eab308; font-weight: bold; }
.score-100 { color: #10b981; font-weight: bold; }

#sys-status { font-family: monospace; color: #10b981; border: 1px solid #10b981; background: rgba(16,185,129,0.1); padding: 10px; border-radius: 6px; margin-bottom: 20px; word-break: break-all; flex-shrink: 0; }

/* Modal do Resumo */
.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); z-index: 9999; padding: 20px; box-sizing: border-box; overflow-y: auto; }
.modal-content { background: #1e293b; max-width: 550px; margin: 20px auto; border-radius: 12px; padding: 30px; position: relative; border: 1px solid #334155; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5); }
.close-btn { position: absolute; top: 15px; right: 20px; background: transparent; color: #cbd5e1; border: none; font-size: 28px; cursor: pointer; transition: color 0.2s; padding: 0; }
.close-btn:hover { color: #fff; }
.ai-box { margin-top: 25px; padding: 20px; background: #0f172a; border-radius: 8px; border-top: 4px solid #8b5cf6; }

.progress-container { width: 100%; background: #334155; height: 6px; border-radius: 3px; overflow: hidden; margin: 15px 0; }
.progress-bar { width: 0%; height: 100%; background: #8b5cf6; border-radius: 3px; transition: width 0.5s ease; box-shadow: 0 0 10px #8b5cf6; }

/* Mobile toggle button - hidden on desktop */
.mobile-toggle {
    display: none;
    width: 100%;
    background: #1e293b;
    color: #cbd5e1;
    border: 1px solid #334155;
    padding: 14px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
    letter-spacing: 0.5px;
    transition: background 0.2s, border-color 0.2s;
    order: -1;
}
.mobile-toggle:hover { background: #334155; }
.mobile-toggle.active { background: #8b5cf6; color: white; border-color: #8b5cf6; }

/* ============================================== */
/* Responsive: Tablet (≤1024px)                   */
/* ============================================== */
@media (max-width: 1024px) {
    .master-layout { flex-direction: column; }
    .sidebar { width: 100%; position: static; max-height: none; height: auto; }
    .content { height: auto; display: block; }
    .table-wrapper { height: 500px; }
}

/* ============================================== */
/* Responsive: Mobile (≤768px)                    */
/* Linear Precision: limpo, funcional, sem neon   */
/* ============================================== */
@media (max-width: 768px) {
    body { padding: 8px; font-size: 14px; }
    .master-layout { gap: 10px; flex-direction: column; }

    /* --- MOBILE TOGGLE --- */
    .mobile-toggle { display: block; }

    /* --- SIDEBAR: collapsível no mobile --- */
    .sidebar {
        width: 100%;
        position: static;
        max-height: none;
        display: none;
        border-radius: 8px;
    }
    .sidebar.sidebar-open { display: block; }

    .header-title { font-size: 18px; margin-bottom: 15px; }

    /* --- FORM: inputs & labels touch-friendly --- */
    .form-group { margin-bottom: 12px; }
    .form-group label { font-size: 11px; margin-bottom: 4px; }
    .form-group input,
    .form-group select {
        padding: 14px 12px;
        font-size: 16px; /* Evita zoom automático no iOS */
        border-radius: 8px;
    }

    /* --- BOTÕES: área mínima 48px para toque --- */
    .master-btn {
        padding: 16px;
        font-size: 15px;
        border-radius: 8px;
        min-height: 48px;
    }

    /* --- CONTENT AREA --- */
    .content { height: auto; display: block; }

    .content-header {
        flex-direction: column !important;
        gap: 8px !important;
        align-items: stretch !important;
    }
    .content-header h2 { font-size: 16px; }
    .content-header-buttons {
        width: 100% !important;
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 6px !important;
    }
    .content-header-buttons button {
        padding: 12px 8px !important;
        font-size: 11px !important;
        border-radius: 6px !important;
        min-height: 44px;
        white-space: nowrap;
    }

    /* --- STATUS BAR --- */
    #sys-status {
        font-size: 12px;
        padding: 10px;
        word-break: break-word;
        line-height: 1.4;
    }

    /* --- TABELA: adaptada para mobile --- */
    .table-wrapper {
        height: auto;
        max-height: 50vh;
        border-radius: 8px;
    }
    table { min-width: 0; font-size: 12px; }
    th, td { padding: 10px 8px; }
    th { font-size: 10px; letter-spacing: 0.5px; }
    tr.lead-row:hover { border-left: 2px solid #8b5cf6; }

    /* Esconde coluna de score no mobile para caber */
    table th:first-child,
    table td:first-child {
        display: none;
    }

    /* --- MODAIS: full-width, scroll seguro --- */
    .modal { padding: 8px; }
    .modal-content {
        max-width: 100%;
        width: 100%;
        margin: 8px auto;
        padding: 16px;
        border-radius: 10px;
        max-height: calc(100vh - 16px);
        overflow-y: auto;
    }
    .close-btn {
        top: 8px;
        right: 12px;
        font-size: 32px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .ai-box { padding: 14px; margin-top: 15px; }
    .ai-box h3 { font-size: 14px; }

    /* --- SELECTS inline (filtros) --- */
    select {
        padding: 12px !important;
        font-size: 14px !important;
        min-height: 44px;
    }

    /* --- SIDEBAR SECTIONS spacing --- */
    .sidebar h2 { font-size: 13px; margin-top: 20px !important; margin-bottom: 10px !important; }
    .sidebar hr { margin: 15px 0; }

    /* --- OBSERVABILITY / LOGS --- */
    #obs-last-run { font-size: 11px; }
    #obs-events { height: 120px !important; font-size: 9px !important; }

    /* --- CRON row --- */
    .sidebar .form-group[style*="display:flex"] {
        flex-direction: row !important;
    }

    /* --- WEBHOOK row --- */
    .sidebar div[style*="display: flex"][style*="gap: 8px"] {
        flex-direction: column;
    }
}

/* ============================================== */
/* Extra small devices (≤390px)                   */
/* ============================================== */
@media (max-width: 390px) {
    body { padding: 4px; }
    .master-layout { gap: 6px; }
    .mobile-toggle { padding: 12px; font-size: 14px; }
    .sidebar { padding: 14px; }
    .header-title { font-size: 16px; }
    .master-btn { padding: 14px; font-size: 14px; }
    .modal-content { padding: 12px; margin: 4px; }
    .content-header-buttons {
        grid-template-columns: 1fr !important;
    }
    .content-header-buttons button {
        font-size: 12px !important;
        padding: 14px 8px !important;
    }
}

