@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap');

:root {
    --bg-main: #f4f6fb;
    --sidebar-bg: #ffffff;
    --card-bg: #ffffff;
    --accent: #1F69F2;
    --accent-hover: #1557d4;
    --brand-dark: #1F2A3F;
    --brand-purple: #805A96;
    --text-main: #1F2A3F;
    --text-muted: #64748b;
    --success: #22c55e;
    --success-bg: #f0fdf4;
    --success-text: #166534;
    --error: #ef4444;
    --warning: #f59e0b;
    --border: #e2e8f0;
    --step-pending: #e2e8f0;
    --step-sent: #dbeafe;
    --step-done: #dcfce7;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
}

/* Login */
.login-container {
    display: none;
    height: 100vh;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #f4f6fb 0%, #eef2ff 100%);
}
.login-container.active { display: flex; animation: fadeIn 0.5s; }
.login-card { width: 100%; max-width: 420px; }
.justify-center { justify-content: center; }
.full-width { width: 100%; margin-top: 1rem; }
.error-msg { color: var(--error); font-size: 0.875rem; text-align: center; }

/* Main Layout */
.app-container { display: none; height: 100vh; }
.app-container.active { display: flex; animation: fadeIn 0.3s; }

.sidebar {
    width: 240px;
    background-color: var(--sidebar-bg);
    padding: 1.75rem 1.25rem;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
}

.logo { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 2.5rem; padding: 0 0.5rem; }
.logo img { width: auto; height: 48px; }
.logo h1, .logo h2 { font-size: 1.1rem; font-weight: 700; color: var(--brand-dark); display: none; }

nav { display: flex; flex-direction: column; gap: 0.25rem; flex: 1; }
.nav-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.75rem 1rem;
    text-align: left;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
    font-size: 0.9rem;
}
.nav-btn:hover { background-color: rgba(31, 105, 242, 0.06); color: var(--accent); }
.nav-btn.active { background-color: rgba(31, 105, 242, 0.1); color: var(--accent); }

.mt-auto { margin-top: auto; }
.mt-4 { margin-top: 1rem; }
.status-panel { padding-top: 1.5rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 0.75rem; }
.status-item { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
.status-badge, #gateway-status {
    padding: 0.2rem 0.65rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 700;
}
.badge-success { background: rgba(34, 197, 94, 0.15); color: #166534; }
.badge-danger { background: rgba(239, 68, 68, 0.15); color: #991b1b; }

.content { flex: 1; padding: 2.5rem 3rem; overflow-y: auto; }
header { margin-bottom: 2rem; }
header h2 { font-size: 1.75rem; margin-bottom: 0.25rem; color: var(--brand-dark); font-weight: 700; }
header p { color: var(--text-muted); font-size: 0.9rem; }

.subview { display: none; }
.subview.active { display: block; animation: fadeIn 0.3s ease-out; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Cards & Forms */
.card {
    background-color: var(--card-bg);
    border-radius: 12px;
    padding: 1.75rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.form-group {
    margin-bottom: 1.25rem;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.password-wrapper { position: relative; display: flex; align-items: center; }
.password-wrapper input { width: 100%; padding-right: 45px !important; }
.toggle-password {
    position: absolute; right: 15px; cursor: pointer;
    color: #94a3b8; user-select: none; font-size: 1.1rem; transition: color 0.2s;
}
.toggle-password:hover { color: var(--accent); }

label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
input, select {
    background: #fff; border: 1px solid var(--border); padding: 0.7rem 1rem;
    border-radius: 8px; color: var(--text-main); outline: none; transition: border 0.2s;
    font-size: 0.95rem;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31, 105, 242, 0.1); }

.primary-btn {
    background: var(--accent); color: white; border: none; padding: 0.7rem 1.4rem;
    border-radius: 8px; font-weight: 600; cursor: pointer; transition: all 0.2s;
    font-size: 0.9rem;
}
.primary-btn:hover { background: var(--accent-hover); transform: translateY(-1px); }
.primary-btn:disabled { background: #94a3b8; cursor: not-allowed; transform: none; }
.secondary-btn {
    background: #f8fafc; color: var(--text-main); border: 1px solid var(--border);
    padding: 0.6rem 1.2rem; border-radius: 8px; font-weight: 600; cursor: pointer;
    transition: background 0.2s; font-size: 0.9rem;
}
.secondary-btn:hover { background: #e2e8f0; }
.danger-btn {
    background: rgba(239,68,68,0.08); color: var(--error); border: 1px solid rgba(239,68,68,0.2);
    padding: 0.4rem 0.85rem; border-radius: 6px; font-weight: 600; cursor: pointer; font-size: 0.8rem;
}
.danger-btn:hover { background: var(--error); color: white; }
.logout-btn { width: 100%; color: var(--error); background: transparent; border: 1px solid var(--error); transition: all 0.2s; }
.logout-btn:hover { background: var(--error); color: white; }

/* Grid Layouts */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.form-inline { display: flex; gap: 1rem; align-items: flex-end; }
.form-inline input { flex: 1; }

/* Model List (Gerenciar Modelos) */
.model-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
}
.model-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.model-card-header h4 { font-size: 1.1rem; font-weight: 700; color: var(--brand-dark); }

.command-list-item {
    display: grid;
    grid-template-columns: 28px 1fr auto auto;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.5rem;
    border-radius: 8px;
    transition: background 0.15s;
}
.command-list-item:hover { background: var(--bg-main); }
.command-list-item + .command-list-item { border-top: 1px solid var(--border); }
.cmd-step-number {
    width: 28px; height: 28px; border-radius: 50%; background: rgba(31,105,242,0.1);
    color: var(--accent); font-size: 0.75rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}
.cmd-info .cmd-name { font-weight: 600; font-size: 0.9rem; color: var(--brand-dark); }
.cmd-info .cmd-text { font-family: monospace; font-size: 0.8rem; color: var(--text-muted); background: var(--bg-main); padding: 0.15rem 0.4rem; border-radius: 4px; margin-top: 2px; display: inline-block; }

/* Sessão Ativa - Configuração */
.session-header {
    display: flex; justify-content: space-between; align-items: center;
    background: var(--brand-dark); color: white; padding: 1.25rem 1.75rem;
    border-radius: 12px; margin-bottom: 1.5rem;
}
.session-header h3 { font-size: 1rem; font-weight: 600; opacity: 0.9; }
.session-phone { font-size: 1.4rem; font-weight: 700; }

.cmd-step-row {
    display: grid;
    grid-template-columns: 40px 1fr auto;
    gap: 1rem;
    align-items: start;
    padding: 1.25rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    margin-bottom: 0.75rem;
    transition: all 0.2s;
}
.cmd-step-row.state-sent { border-color: #93c5fd; background: #eff6ff; }
.cmd-step-row.state-done { border-color: #86efac; background: var(--success-bg); }

.step-number {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--step-pending); color: var(--text-muted);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.9rem; flex-shrink: 0;
}
.state-sent .step-number { background: var(--step-sent); color: var(--accent); }
.state-done .step-number { background: var(--step-done); color: var(--success-text); }

.step-content {}
.step-label { font-weight: 700; color: var(--brand-dark); font-size: 0.95rem; margin-bottom: 0.25rem; }
.step-code { font-family: 'Courier New', monospace; font-size: 0.85rem; color: var(--text-muted); background: var(--bg-main); padding: 0.25rem 0.6rem; border-radius: 6px; display: inline-block; margin-bottom: 0.5rem; }
.step-response {
    margin-top: 0.5rem; padding: 0.65rem 1rem; border-radius: 8px;
    font-size: 0.85rem; font-weight: 600; display: none;
}
.step-response.visible { display: block; }
.step-response.waiting { background: #eff6ff; color: var(--accent); }
.step-response.received { background: var(--success-bg); color: var(--success-text); border-left: 3px solid var(--success); }

/* Badge */
.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 6px; font-size: 0.75rem; font-weight: 600; background: rgba(31,105,242,0.1); color: var(--accent); }

/* Misc */
.hidden { display: none !important; }
.modal { position: fixed; inset: 0; background: rgba(31,42,63,0.5); display: flex; justify-content: center; align-items: center; z-index: 100; backdrop-filter: blur(4px); }
.modal-content { background: var(--card-bg); padding: 2rem; border-radius: 16px; width: 420px; box-shadow: 0 20px 40px rgba(0,0,0,0.15); }
.modal-content h3 { margin-bottom: 1.5rem; font-size: 1.1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 1rem; margin-top: 1.5rem; }

/* Mobile Optimizations */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        padding: 1rem;
        border-right: none;
        border-bottom: 1px solid var(--border);
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
    }
    
    .logo {
        margin-bottom: 0;
        padding: 0;
    }
    .logo img {
        height: 36px;
    }
    
    nav {
        flex-direction: row;
        justify-content: flex-end;
    }
    .nav-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }
    
    .status-panel {
        display: none; /* Simplificar no mobile para caber o menu */
    }
    
    .content {
        padding: 1.5rem 1rem;
        padding-bottom: 120px; /* Adiciona o "tab" (margem inferior grande) para scroll livre */
    }
    
    .session-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        padding: 1rem;
    }
    
    .cmd-step-row {
        grid-template-columns: 36px 1fr;
        grid-template-areas: 
            "number content"
            "button button";
        padding: 1rem;
        gap: 0.75rem;
    }
    
    .step-number { grid-area: number; width: 36px; height: 36px; }
    .step-content { grid-area: content; }
    .cmd-step-row > button { 
        grid-area: button; 
        width: 100%; 
        padding: 0.85rem;
        font-size: 0.95rem;
    }
    
    .two-col {
        grid-template-columns: 1fr;
    }
    
    .form-inline {
        flex-direction: column;
        align-items: stretch;
    }
    
    .modal-content {
        width: 90%;
        padding: 1.5rem;
    }
}
